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  
17  package org.springframework.osgi.service.importer.support.internal.aop;
18  
19  import org.osgi.framework.Bundle;
20  import org.osgi.framework.ServiceReference;
21  import org.springframework.osgi.service.importer.ServiceReferenceProxy;
22  import org.springframework.util.Assert;
23  
24  /**
25   * Simple {@link ServiceReference} proxy which simply does delegation, without
26   * any extra features. It's main purpose is to allow the consistent behaviour
27   * between dynamic and static proxies.
28   * 
29   * @author Costin Leau
30   * 
31   */
32  public class StaticServiceReferenceProxy implements ServiceReferenceProxy {
33  
34  	private static final int HASH_CODE = StaticServiceReferenceProxy.class.hashCode() * 13;
35  
36  	private final ServiceReference target;
37  
38  
39  	/**
40  	 * Constructs a new <code>StaticServiceReferenceProxy</code> instance.
41  	 * 
42  	 * @param target service reference
43  	 */
44  	public StaticServiceReferenceProxy(ServiceReference target) {
45  		Assert.notNull(target);
46  		this.target = target;
47  	}
48  
49  	public Bundle getBundle() {
50  		return target.getBundle();
51  	}
52  
53  	public Object getProperty(String key) {
54  		return target.getProperty(key);
55  	}
56  
57  	public String[] getPropertyKeys() {
58  		return target.getPropertyKeys();
59  	}
60  
61  	public Bundle[] getUsingBundles() {
62  		return target.getUsingBundles();
63  	}
64  
65  	public boolean isAssignableTo(Bundle bundle, String className) {
66  		return target.isAssignableTo(bundle, className);
67  	}
68  
69  	public ServiceReference getTargetServiceReference() {
70  		return target;
71  	}
72  
73  	public boolean equals(Object obj) {
74  		if (obj instanceof StaticServiceReferenceProxy) {
75  			StaticServiceReferenceProxy other = (StaticServiceReferenceProxy) obj;
76  			return (target.equals(other.target));
77  		}
78  		return false;
79  	}
80  
81  	public int hashCode() {
82  		return HASH_CODE + target.hashCode();
83  	}
84  }