Index: core/src/main/java/org/springframework/osgi/config/OsgiServiceLifecycleListenerAdapter.java =================================================================== --- core/src/main/java/org/springframework/osgi/config/OsgiServiceLifecycleListenerAdapter.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/config/OsgiServiceLifecycleListenerAdapter.java (working copy) @@ -146,7 +146,7 @@ if (trace) log.trace("invoking listener custom method " + method); - ServiceReference ref = (service != null ? ((ImportedOsgiServiceProxy) service).getServiceReference() : null); + ServiceReference ref = (service != null ? ((ImportedOsgiServiceProxy) service).getServiceReference().getTargetServiceReference() : null); try { ReflectionUtils.invokeMethod(method, target, new Object[] { ref }); Index: core/src/main/java/org/springframework/osgi/service/importer/ServiceReferenceProxy.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/ServiceReferenceProxy.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/ServiceReferenceProxy.java (working copy) @@ -38,7 +38,7 @@ * @author Costin Leau * */ -public interface ServiceReferenceProxy extends ServiceReference { +public interface ServiceReferenceProxy { /** * Returns the target, native service reference used, at the moment of the Index: core/src/main/java/org/springframework/osgi/service/importer/support/ServiceReferenceDelegate.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/ServiceReferenceDelegate.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/ServiceReferenceDelegate.java (working copy) @@ -1,61 +0,0 @@ -/* - * Copyright 2006-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.osgi.service.importer.support; - -import org.osgi.framework.Bundle; -import org.osgi.framework.ServiceReference; -import org.springframework.osgi.service.importer.ImportedOsgiServiceProxy; -import org.springframework.util.Assert; - -/** - * {@link ServiceReference} adapter using a {@link ImportedOsgiServiceProxy} - * internally for delegation. - * - * @author Costin Leau - * - */ -class ServiceReferenceDelegate implements ServiceReference { - private final ImportedOsgiServiceProxy delegate; - - public ServiceReferenceDelegate(ImportedOsgiServiceProxy delegate) { - Assert.notNull(delegate, "delegate object should not be null"); - this.delegate = delegate; - } - - public Bundle getBundle() { - return delegate.getServiceReference().getBundle(); - } - - public Object getProperty(String key) { - return delegate.getServiceReference().getProperty(key); - } - - public String[] getPropertyKeys() { - return delegate.getServiceReference().getPropertyKeys(); - } - - public Bundle[] getUsingBundles() { - return delegate.getServiceReference().getUsingBundles(); - } - - public boolean isAssignableTo(Bundle bundle, String className) { - return delegate.getServiceReference().isAssignableTo(bundle, className); - } - - public String toString() { - return "ServiceReference wrapper for " + delegate.getServiceReference(); - } -} Index: core/src/main/java/org/springframework/osgi/service/importer/support/ServiceReferenceEditor.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/ServiceReferenceEditor.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/ServiceReferenceEditor.java (working copy) @@ -16,10 +16,8 @@ package org.springframework.osgi.service.importer.support; -import java.beans.PropertyEditor; import java.beans.PropertyEditorSupport; -import org.osgi.framework.ServiceReference; import org.springframework.osgi.service.importer.ImportedOsgiServiceProxy; /** @@ -59,7 +57,7 @@ } if (value instanceof ImportedOsgiServiceProxy) { - super.setValue(new ServiceReferenceDelegate((ImportedOsgiServiceProxy) value)); + super.setValue(((ImportedOsgiServiceProxy) value).getServiceReference().getTargetServiceReference()); return; } throw new IllegalArgumentException("expected a service of type " + ImportedOsgiServiceProxy.class.getName()); Index: core/src/main/java/org/springframework/osgi/service/importer/support/AbstractServiceProxyCreator.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/AbstractServiceProxyCreator.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/AbstractServiceProxyCreator.java (working copy) @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; +import org.springframework.osgi.service.importer.ServiceReferenceProxy; import org.springframework.osgi.service.importer.support.internal.aop.ImportedOsgiServiceProxyAdvice; import org.springframework.osgi.service.importer.support.internal.aop.InfrastructureOsgiProxyAdvice; import org.springframework.osgi.service.importer.support.internal.aop.ProxyPlusCallback; @@ -79,7 +80,7 @@ invokerBundleContextAdvice = new LocalBundleContextAdvice(bundleContext); } - public ProxyPlusCallback createServiceProxy(ServiceReference reference) { + public ProxyPlusCallback createServiceProxy(ServiceReferenceProxy reference) { List advices = new ArrayList(4); // 1. the ServiceReference-like mixin @@ -108,7 +109,7 @@ advices), dispatcherInterceptor); } - private Advice determineTCCLAdvice(ServiceReference reference) { + private Advice determineTCCLAdvice(ServiceReferenceProxy reference) { try { if (ImportContextClassLoader.CLIENT == iccl) { return clientTCCLAdvice; @@ -125,12 +126,12 @@ } finally { if (log.isTraceEnabled()) { - log.trace(iccl + " TCCL used for invoking " + OsgiStringUtils.nullSafeToString(reference)); + log.trace(iccl + " TCCL used for invoking " + OsgiStringUtils.nullSafeToString(reference.getTargetServiceReference())); } } } - Class[] getInterfaces(ServiceReference reference) { + Class[] getInterfaces(ServiceReferenceProxy reference) { return classes; } @@ -141,7 +142,7 @@ * @param reference service reference * @return AOP advice */ - abstract Advice createServiceProviderTCCLAdvice(ServiceReference reference); + abstract Advice createServiceProviderTCCLAdvice(ServiceReferenceProxy reference); /** * Create a dispatcher interceptor that actually execute the call on the @@ -150,5 +151,5 @@ * @param reference service reference * @return AOP advice */ - abstract ServiceInvoker createDispatcherInterceptor(ServiceReference reference); + abstract ServiceInvoker createDispatcherInterceptor(ServiceReferenceProxy reference); } Index: core/src/main/java/org/springframework/osgi/service/importer/support/OsgiServiceProxyFactoryBean.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/OsgiServiceProxyFactoryBean.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/OsgiServiceProxyFactoryBean.java (working copy) @@ -31,6 +31,7 @@ import org.springframework.osgi.context.internal.classloader.AopClassLoaderFactory; import org.springframework.osgi.service.importer.ImportedOsgiServiceProxy; import org.springframework.osgi.service.importer.OsgiServiceLifecycleListener; +import org.springframework.osgi.service.importer.ServiceReferenceProxy; import org.springframework.osgi.service.importer.support.internal.aop.ProxyPlusCallback; import org.springframework.osgi.service.importer.support.internal.aop.ServiceDynamicInterceptor; import org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker; @@ -82,7 +83,7 @@ if (!mandatory) return true; else - return (proxy == null ? true : proxy.getServiceReference().getBundle() != null); + return (proxy == null ? true : proxy.getServiceReference().getTargetServiceReference().getBundle() != null); } }; @@ -169,11 +170,11 @@ ServiceProxyCreator creator = new AbstractServiceProxyCreator(getInterfaces(), getAopClassLoader(), getBundleContext(), getContextClassLoader()) { - ServiceInvoker createDispatcherInterceptor(ServiceReference reference) { + ServiceInvoker createDispatcherInterceptor(ServiceReferenceProxy reference) { return lookupAdvice; } - Advice createServiceProviderTCCLAdvice(ServiceReference reference) { + Advice createServiceProviderTCCLAdvice(ServiceReferenceProxy reference) { return tcclAdvice; } }; Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/collection/comparator/ServiceReferenceComparator.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/collection/comparator/ServiceReferenceComparator.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/collection/comparator/ServiceReferenceComparator.java (working copy) @@ -63,8 +63,8 @@ ImportedOsgiServiceProxy obj1 = (ImportedOsgiServiceProxy) o1; ImportedOsgiServiceProxy obj2 = (ImportedOsgiServiceProxy) o2; - ref1 = obj1.getServiceReference(); - ref2 = obj2.getServiceReference(); + ref1 = obj1.getServiceReference().getTargetServiceReference(); + ref2 = obj2.getServiceReference().getTargetServiceReference(); } return compare(ref1, ref2); Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/collection/OsgiServiceCollection.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/collection/OsgiServiceCollection.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/collection/OsgiServiceCollection.java (working copy) @@ -40,6 +40,7 @@ import org.springframework.osgi.service.importer.OsgiServiceLifecycleListener; import org.springframework.osgi.service.importer.support.internal.aop.ProxyPlusCallback; import org.springframework.osgi.service.importer.support.internal.aop.ServiceProxyCreator; +import org.springframework.osgi.service.importer.support.internal.aop.StaticServiceReferenceProxy; import org.springframework.osgi.service.importer.support.internal.dependency.ImporterStateListener; import org.springframework.osgi.service.importer.support.internal.util.OsgiServiceBindingUtils; import org.springframework.osgi.util.OsgiListenerUtils; @@ -88,7 +89,7 @@ // same as ServiceEvent.REGISTERED synchronized (serviceProxies) { if (!servicesIdMap.containsKey(serviceId)) { - ppc = proxyCreator.createServiceProxy(ref); + ppc = proxyCreator.createServiceProxy(new StaticServiceReferenceProxy(ref)); proxy = ppc.proxy; // let the dynamic collection decide if the service // is added or not (think set, sorted set) @@ -297,7 +298,7 @@ synchronized (serviceProxies) { for (Iterator iterator = serviceProxies.iterator(); iterator.hasNext();) { ImportedOsgiServiceProxy serviceProxy = (ImportedOsgiServiceProxy) iterator.next(); - ServiceReference ref = serviceProxy.getServiceReference(); + ServiceReference ref = serviceProxy.getServiceReference().getTargetServiceReference(); // get first the destruction callback ProxyPlusCallback ppc = (ProxyPlusCallback) servicesIdMap.get((Long) ref.getProperty(Constants.SERVICE_ID)); Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceInvoker.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceInvoker.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceInvoker.java (working copy) @@ -26,6 +26,7 @@ import org.osgi.framework.ServiceReference; import org.springframework.aop.TargetSource; import org.springframework.beans.factory.DisposableBean; +import org.springframework.osgi.service.importer.ServiceReferenceProxy; import org.springframework.util.Assert; /** @@ -92,7 +93,7 @@ * * @return */ - public ServiceReference getServiceReference() { + public ServiceReferenceProxy getServiceReference() { return null; } Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceDynamicInterceptor.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceDynamicInterceptor.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceDynamicInterceptor.java (working copy) @@ -35,6 +35,7 @@ import org.springframework.osgi.service.importer.OsgiServiceDependency; import org.springframework.osgi.service.importer.OsgiServiceLifecycleListener; import org.springframework.osgi.service.importer.ServiceProxyDestroyedException; +import org.springframework.osgi.service.importer.ServiceReferenceProxy; import org.springframework.osgi.service.importer.event.OsgiServiceDependencyWaitEndedEvent; import org.springframework.osgi.service.importer.event.OsgiServiceDependencyWaitTimedOutEvent; import org.springframework.osgi.service.importer.event.OsgiServiceDependencyWaitStartingEvent; @@ -483,7 +484,7 @@ * callers can keep the reference even if the underlying target service * reference changes in time. */ - public ServiceReference getServiceReference() { + public ServiceReferenceProxy getServiceReference() { return referenceDelegate; } Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceReferenceProvider.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceReferenceProvider.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceReferenceProvider.java (working copy) @@ -15,7 +15,7 @@ */ package org.springframework.osgi.service.importer.support.internal.aop; -import org.osgi.framework.ServiceReference; +import org.springframework.osgi.service.importer.ServiceReferenceProxy; /** * Simple interface providing access to a ServiceReference. @@ -27,5 +27,5 @@ */ public interface ServiceReferenceProvider { - ServiceReference getServiceReference(); + ServiceReferenceProxy getServiceReference(); } Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ImportedOsgiServiceProxyAdvice.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ImportedOsgiServiceProxyAdvice.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ImportedOsgiServiceProxyAdvice.java (working copy) @@ -38,10 +38,9 @@ private final transient ServiceReferenceProxy reference; - public ImportedOsgiServiceProxyAdvice(ServiceReference reference) { + public ImportedOsgiServiceProxyAdvice(ServiceReferenceProxy reference) { Assert.notNull(reference); - this.reference = (reference instanceof ServiceReferenceProxy ? (ServiceReferenceProxy) reference - : new StaticServiceReferenceProxy(reference)); + this.reference = reference; } public ServiceReferenceProxy getServiceReference() { Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceProxyCreator.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceProxyCreator.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceProxyCreator.java (working copy) @@ -17,6 +17,7 @@ package org.springframework.osgi.service.importer.support.internal.aop; import org.osgi.framework.ServiceReference; +import org.springframework.osgi.service.importer.ServiceReferenceProxy; /** * Simple interface passed around to decouple proxy creation (which is highly @@ -42,5 +43,5 @@ * @param reference service reference * @return the proxy plus a destruction callback to it */ - ProxyPlusCallback createServiceProxy(ServiceReference reference); + ProxyPlusCallback createServiceProxy(ServiceReferenceProxy reference); } Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceStaticInterceptor.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceStaticInterceptor.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceStaticInterceptor.java (working copy) @@ -20,6 +20,7 @@ import org.osgi.framework.ServiceReference; import org.springframework.osgi.service.ServiceUnavailableException; import org.springframework.osgi.service.importer.ServiceProxyDestroyedException; +import org.springframework.osgi.service.importer.ServiceReferenceProxy; import org.springframework.util.Assert; /** @@ -39,12 +40,12 @@ /** private lock */ private final Object lock = new Object(); - private final ServiceReference reference; + private final ServiceReferenceProxy reference; private final BundleContext bundleContext; - public ServiceStaticInterceptor(BundleContext context, ServiceReference reference) { + public ServiceStaticInterceptor(BundleContext context, ServiceReferenceProxy reference) { Assert.notNull(context); Assert.notNull(reference, "a not null service reference is required"); this.bundleContext = context; @@ -58,18 +59,18 @@ } // check if the service is alive first - if (reference.getBundle() != null) { + if (reference.getTargetServiceReference().getBundle() != null) { // since requesting for a service requires additional work // from the OSGi platform - Object target = bundleContext.getService(reference); + Object target = bundleContext.getService(reference.getTargetServiceReference()); if (target != null) return target; } // throw exception - throw new ServiceUnavailableException(reference); + throw new ServiceUnavailableException(reference.getTargetServiceReference()); } - public ServiceReference getServiceReference() { + public ServiceReferenceProxy getServiceReference() { return reference; } Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceProviderTCCLInterceptor.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceProviderTCCLInterceptor.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/ServiceProviderTCCLInterceptor.java (working copy) @@ -47,7 +47,7 @@ // example) if (service instanceof ImportedOsgiServiceProxy) { // get the service reference from object - setServiceProvidedClassLoader(((ImportedOsgiServiceProxy) service).getServiceReference().getBundle()); + setServiceProvidedClassLoader(((ImportedOsgiServiceProxy) service).getServiceReference().getTargetServiceReference().getBundle()); } } Index: core/src/main/java/org/springframework/osgi/service/importer/support/StaticServiceProxyCreator.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/StaticServiceProxyCreator.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/StaticServiceProxyCreator.java (working copy) @@ -27,6 +27,7 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.springframework.osgi.context.internal.classloader.AopClassLoaderFactory; +import org.springframework.osgi.service.importer.ServiceReferenceProxy; import org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker; import org.springframework.osgi.service.importer.support.internal.aop.ServiceStaticInterceptor; import org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor; @@ -78,12 +79,12 @@ log.debug("Greedy proxying will " + msg + " consider exposed classes"); } - ServiceInvoker createDispatcherInterceptor(ServiceReference reference) { + ServiceInvoker createDispatcherInterceptor(ServiceReferenceProxy reference) { return new ServiceStaticInterceptor(bundleContext, reference); } - Advice createServiceProviderTCCLAdvice(ServiceReference reference) { - Bundle bundle = reference.getBundle(); + Advice createServiceProviderTCCLAdvice(ServiceReferenceProxy reference) { + Bundle bundle = reference.getTargetServiceReference().getBundle(); // if reference is dead already, it's impossible to provide the service // class loader if (bundle == null)