View Javadoc

1   /*
2    * Copyright 2006-2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.osgi.service.importer.support;
17  
18  import org.osgi.framework.Bundle;
19  import org.osgi.framework.ServiceReference;
20  import org.springframework.osgi.service.importer.ImportedOsgiServiceProxy;
21  import org.springframework.util.Assert;
22  
23  /**
24   * {@link ServiceReference} adapter using a {@link ImportedOsgiServiceProxy}
25   * internally for delegation.
26   * 
27   * @author Costin Leau
28   * 
29   */
30  class ServiceReferenceDelegate implements ServiceReference {
31  	private final ImportedOsgiServiceProxy delegate;
32  
33  	public ServiceReferenceDelegate(ImportedOsgiServiceProxy delegate) {
34  		Assert.notNull(delegate, "delegate object should not be null");
35  		this.delegate = delegate;
36  	}
37  
38  	public Bundle getBundle() {
39  		return delegate.getServiceReference().getBundle();
40  	}
41  
42  	public Object getProperty(String key) {
43  		return delegate.getServiceReference().getProperty(key);
44  	}
45  
46  	public String[] getPropertyKeys() {
47  		return delegate.getServiceReference().getPropertyKeys();
48  	}
49  
50  	public Bundle[] getUsingBundles() {
51  		return delegate.getServiceReference().getUsingBundles();
52  	}
53  
54  	public boolean isAssignableTo(Bundle bundle, String className) {
55  		return delegate.getServiceReference().isAssignableTo(bundle, className);
56  	}
57  
58  	public String toString() {
59  		return "ServiceReference wrapper for " + delegate.getServiceReference();
60  	}
61  }