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.ServiceReference;
20  import org.springframework.aop.support.DelegatingIntroductionInterceptor;
21  import org.springframework.osgi.service.importer.ImportedOsgiServiceProxy;
22  import org.springframework.osgi.service.importer.ServiceReferenceProxy;
23  import org.springframework.util.Assert;
24  
25  /**
26   * Mix-in implementation for ImportedOsgiServiceProxy.
27   * 
28   * @author Costin Leau
29   * 
30   */
31  public class ImportedOsgiServiceProxyAdvice extends DelegatingIntroductionInterceptor implements
32  		ImportedOsgiServiceProxy {
33  
34  	private static final long serialVersionUID = 6455437774724678999L;
35  
36  	private static final int hashCode = ImportedOsgiServiceProxyAdvice.class.hashCode() * 13;
37  
38  	private final transient ServiceReferenceProxy reference;
39  
40  
41  	public ImportedOsgiServiceProxyAdvice(ServiceReference reference) {
42  		Assert.notNull(reference);
43  		this.reference = (reference instanceof ServiceReferenceProxy ? (ServiceReferenceProxy) reference
44  				: new StaticServiceReferenceProxy(reference));
45  	}
46  
47  	public ServiceReferenceProxy getServiceReference() {
48  		return reference;
49  	}
50  
51  	public boolean equals(Object other) {
52  		if (this == other)
53  			return true;
54  		if (other instanceof ImportedOsgiServiceProxyAdvice) {
55  			ImportedOsgiServiceProxyAdvice oth = (ImportedOsgiServiceProxyAdvice) other;
56  			return (reference.equals(oth.reference));
57  		}
58  		else
59  			return false;
60  	}
61  
62  	public int hashCode() {
63  		return hashCode;
64  	}
65  }