You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/07/06 19:09:51 UTC

svn commit: r553957 - in /incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi: ./ invocation/ runtime/ xml/

Author: rfeng
Date: Fri Jul  6 10:09:50 2007
New Revision: 553957

URL: http://svn.apache.org/viewvc?view=rev&rev=553957
Log:
Apply the patch from Rajini Sivaram for TUSCANY-1414. Thanks!

Modified:
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationInterface.java
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTargetInvoker.java
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/FelixRuntime.java
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java

Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationInterface.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationInterface.java?view=diff&rev=553957&r1=553956&r2=553957
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationInterface.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationInterface.java Fri Jul  6 10:09:50 2007
@@ -34,10 +34,8 @@
     public String getBundleName();
     
     public String getBundleLocation();
-
     
     public String[] getImports();
-    
     
     public Scope getScope();
     

Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java?view=diff&rev=553957&r1=553956&r2=553957
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java Fri Jul  6 10:09:50 2007
@@ -46,6 +46,7 @@
 import org.apache.tuscany.sca.assembly.Service;
 import org.apache.tuscany.sca.core.invocation.JDKProxyService;
 import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.runtime.EndpointReference;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
 import org.apache.tuscany.sca.runtime.RuntimeComponentService;
@@ -217,11 +218,9 @@
         }
     }
     
-    private String getOSGiFilter(ComponentService service) {
+    private String getOSGiFilter(Hashtable<String, Object> props) {
         
         String filter = "";
-        Hashtable<String, Object> props = new Hashtable<String, Object>();
-        processProperties(implementation.getServiceProperties(service.getName()), props);
         
         if (props != null && props.size() > 0) {
             int propCount = 0;
@@ -269,7 +268,7 @@
                     Object compName = ref.getProperty(COMPONENT_SERVICE_NAME);
                     if (compName == null && reference == null)
                         reference = ref;
-                    if (compServiceName.equals(compName)) {
+                    if (scaServiceName == null || compServiceName.equals(compName)) {
                         reference = ref;
                         break;
                     }
@@ -280,7 +279,8 @@
            
         }
         
-        filter = "(" + COMPONENT_SERVICE_NAME + "="+ compServiceName + ")";
+        filter = scaServiceName == null? null : 
+                                         "(" + COMPONENT_SERVICE_NAME + "="+ compServiceName + ")";
         
         org.osgi.framework.ServiceReference[] references = 
             bundleContext.getServiceReferences(osgiServiceName, filter);
@@ -363,17 +363,49 @@
     }
     
     
+    protected org.osgi.framework.ServiceReference getOSGiServiceReference(ComponentService service) 
+            throws ObjectCreationException {
+         
+        Hashtable<String, Object> props = new Hashtable<String, Object>();
+        processProperties(implementation.getServiceProperties(service.getName()), props);
+        
+        String filter = getOSGiFilter(props);
+        Interface serviceInterface = service.getInterfaceContract().getInterface();
+        String scaServiceName = service.getName();
+            
+        return getOSGiServiceReference(serviceInterface, filter, scaServiceName);
+           
+    }
     
-    protected org.osgi.framework.ServiceReference getOSGiServiceReference( 
-            ComponentService service) 
+    protected org.osgi.framework.ServiceReference getOSGiServiceReference(
+            EndpointReference from, Interface callbackInterface) 
+            throws ObjectCreationException {
+        
+        RuntimeWire refWire = null;
+        String filter = null;
+        for (RuntimeWire wire : referenceWires.keySet()) {
+            if (wire.getSource() == from) {
+                refWire = wire;
+                break;
+            }
+        }
+        if (refWire != null) {
+            Hashtable<String, Object> props = new Hashtable<String, Object>();
+            ComponentReference scaRef = componentReferenceWires.get(refWire);
+            processProperties(implementation.getReferenceCallbackProperties(scaRef.getName()), props);
+            filter = getOSGiFilter(props);
+        }
+        
+        return getOSGiServiceReference(callbackInterface, filter, null);
+    }
+    
+    private org.osgi.framework.ServiceReference getOSGiServiceReference(Interface serviceInterface,
+            String filter, String scaServiceName)
             throws ObjectCreationException {
         
         try {
             
-            String filter = getOSGiFilter(service);
-            Interface serviceInterface = service.getInterfaceContract().getInterface();
             String serviceInterfaceName = null;
-            String scaServiceName = service.getName();
 
             org.osgi.framework.ServiceReference osgiServiceReference = null;
             
@@ -401,13 +433,9 @@
                         }
                     }   
                     
-                        
                 }
             }
                 
-            
-            
-            
             return osgiServiceReference;
             
         } catch (Exception e) {
@@ -620,7 +648,7 @@
     
    
     
-    private  void resolveWireCreateDummyBundles(Class interfaceClass, RuntimeWire wire) throws Exception {
+    private  void resolveWireCreateDummyBundles(Class interfaceClass) throws Exception {
         
         
         try {
@@ -753,6 +781,27 @@
         
     }
     
+    private void registerCallbackProxyService(Bundle bundle, Class interfaceClass,
+            RuntimeComponentService service) throws Exception {
+        
+        List<RuntimeWire> wires = service.getCallbackWires();
+        Hashtable<String, Object> targetProperties = new Hashtable<String, Object>();
+        processProperties(implementation.getServiceCallbackProperties(service.getName()), targetProperties);
+        targetProperties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
+          
+        JDKProxyService proxyService = new JDKProxyService();
+              
+        Class<?> proxyInterface = bundle.loadClass(interfaceClass.getName());
+                
+
+        Object proxy = proxyService.createCallbackProxy(proxyInterface, wires);
+       
+            
+        bundleContext.registerService(proxyInterface.getName(), proxy, targetProperties);
+            
+        
+    }
+    
     
     private void resolveBundle() throws ObjectCreationException {
         
@@ -762,10 +811,11 @@
             if (!wiresResolved) {
                 wiresResolved = true;
                     
-                boolean[] createProxyService = new boolean[referenceWires.size()];
-                Class<?>[] interfaceClasses = new Class<?>[referenceWires.size()] ;
-                boolean[] isOSGiToOSGiWire = new boolean[referenceWires.size()];
-                boolean[] wireResolved = new boolean[referenceWires.size()];
+                int refPlusServices = referenceWires.size() + runtimeComponent.getServices().size();
+                boolean[] createProxyService = new boolean[refPlusServices];
+                Class<?>[] interfaceClasses = new Class<?>[refPlusServices] ;
+                boolean[] isOSGiToOSGiWire = new boolean[refPlusServices];
+                boolean[] wireResolved = new boolean[refPlusServices];
                 int index = 0;
                 for (RuntimeWire wire : referenceWires.keySet()) {
                 
@@ -780,7 +830,7 @@
                         interfaceClasses[index] = ((JavaInterface)refInterface).getJavaClass();
                     
                         if (!isOSGiToOSGiWire[index])
-                            resolveWireCreateDummyBundles(interfaceClasses[index], wire);
+                            resolveWireCreateDummyBundles(interfaceClasses[index]);
 
                     }
                     
@@ -792,6 +842,16 @@
                     
                     index++;
                 }
+                for (ComponentService service : runtimeComponent.getServices()) {
+                    Interface callbackInterface = service.getInterfaceContract().getCallbackInterface();
+                    if (callbackInterface instanceof JavaInterface) {
+                        interfaceClasses[index] = ((JavaInterface)callbackInterface).getJavaClass();
+                        
+                        resolveWireCreateDummyBundles(interfaceClasses[index]);
+                    }
+                    
+                    index++;
+                }
                 
                 index = 0;
                 for (RuntimeWire wire : referenceWires.keySet()) {
@@ -805,6 +865,7 @@
                     index++;
                 }
                 
+                
                 index = 0;
                 for (RuntimeWire wire : referenceWires.keySet()) {
                     
@@ -812,6 +873,13 @@
                         resolveWireRegisterProxyService(osgiBundle, interfaceClasses[index], wire);
                     index++;
                 }
+                for (ComponentService service : runtimeComponent.getServices()) {
+                    if (interfaceClasses[index] != null) {
+                        registerCallbackProxyService(osgiBundle, interfaceClasses[index],
+                                ((RuntimeComponentService)service));
+                    }
+                    index++;
+                }
             }
             else if (osgiBundle.getState() == Bundle.INSTALLED && packageAdmin != null) {
                 packageAdmin.resolveBundles(new Bundle[] {osgiBundle});
@@ -890,7 +958,7 @@
 
     }
     
-    protected void injectPropertiesUsingAnnotations(Object instance)  {
+    protected void injectProperties(Object instance)  {
         
         if (!implementation.needsPropertyInjection())
             return;
@@ -959,7 +1027,7 @@
         
     }
     
-    protected void injectProperties(Object instance)  {
+    protected void injectPropertiesWithoutAnnotations(Object instance)  {
         
         if (!implementation.needsPropertyInjection())
             return;
@@ -1053,7 +1121,9 @@
         
     }
     
+    
     public Invoker createCallbackInvoker(Operation operation) {
+        
         return createTargetInvoker(null, operation);
     }
 
@@ -1062,8 +1132,7 @@
     }
 
     public void start() {
-        
-        
+                
         for (Reference ref: implementation.getReferences()) {
             List<RuntimeWire> wireList = null;
             ComponentReference compRef = null;

Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java?view=diff&rev=553957&r1=553956&r2=553957
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java Fri Jul  6 10:09:50 2007
@@ -25,8 +25,9 @@
 import java.util.Random;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
-
 import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.runtime.EndpointReference;
 import org.apache.tuscany.sca.scope.InstanceWrapper;
 import org.apache.tuscany.sca.scope.Scope;
 import org.apache.tuscany.sca.scope.TargetDestructionException;
@@ -50,8 +51,9 @@
     
     private OSGiImplementationProvider provider;
     private BundleContext bundleContext;
-    private Hashtable<ComponentService,InstanceInfo<T>> instanceInfoList = 
-        new Hashtable<ComponentService,InstanceInfo<T>>();
+    private Hashtable<Object,InstanceInfo<T>> instanceInfoList = 
+        new Hashtable<Object,InstanceInfo<T>>();
+
 
     public OSGiInstanceWrapper(OSGiImplementationProvider provider, 
             BundleContext bundleContext) {
@@ -80,6 +82,30 @@
         instanceInfo.osgiInstance = (T)instanceInfo.refBundleContext.getService(instanceInfo.osgiServiceReference);
         
         provider.injectProperties(instanceInfo.osgiInstance);
+        
+        return instanceInfo.osgiInstance;
+    }
+    
+    public synchronized T getCallbackInstance(EndpointReference from, Interface callbackInterface) 
+            throws TargetInitializationException {
+        
+        if (instanceInfoList.get(callbackInterface) != null)
+            return instanceInfoList.get(callbackInterface).osgiInstance;
+
+        Bundle refBundle = provider.startBundle();
+        
+        if (!provider.getImplementation().getScope().equals(Scope.COMPOSITE)) {
+            refBundle = getDummyReferenceBundle();
+        }
+        
+        InstanceInfo<T> instanceInfo = new InstanceInfo<T>();
+        instanceInfoList.put(callbackInterface, instanceInfo);
+        
+
+        instanceInfo.osgiServiceReference = provider.getOSGiServiceReference(from, callbackInterface);
+        
+        instanceInfo.refBundleContext = refBundle.getBundleContext();
+        instanceInfo.osgiInstance = (T)instanceInfo.refBundleContext.getService(instanceInfo.osgiServiceReference);
         
         return instanceInfo.osgiInstance;
     }

Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTargetInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTargetInvoker.java?view=diff&rev=553957&r1=553956&r2=553957
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTargetInvoker.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTargetInvoker.java Fri Jul  6 10:09:50 2007
@@ -30,8 +30,10 @@
 import org.apache.tuscany.sca.invocation.InvocationChain;
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.EndpointReference;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
 import org.apache.tuscany.sca.scope.Scope;
 import org.apache.tuscany.sca.scope.InstanceWrapper;
 import org.apache.tuscany.sca.scope.ScopeContainer;
@@ -71,7 +73,7 @@
         this.scopeContainer = ((ScopedRuntimeComponent) component).getScopeContainer();
         this.cacheable = true;
         stateless = Scope.STATELESS == scopeContainer.getScope();
-
+        
     }
 
     /**
@@ -110,9 +112,15 @@
     
         ConversationSequence sequence = msg.getConversationSequence();
         Object contextId = ThreadMessageContext.getMessageContext().getConversationID();
+        EndpointReference from = ThreadMessageContext.getMessageContext().getFrom();
         try {
             OSGiInstanceWrapper wrapper = (OSGiInstanceWrapper)getInstance(sequence, contextId);
-            Object instance = wrapper.getInstance(service);
+            Object instance;
+            
+            if (service != null)
+                instance = wrapper.getInstance(service);
+            else
+                instance = wrapper.getCallbackInstance(from, operation.getInterface());
         
             Method m = JavaInterfaceUtil.findMethod(instance.getClass(), operation);
         

Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/FelixRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/FelixRuntime.java?view=diff&rev=553957&r1=553956&r2=553957
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/FelixRuntime.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/FelixRuntime.java Fri Jul  6 10:09:50 2007
@@ -26,6 +26,7 @@
 import java.util.Map;
 import java.util.Properties;
 
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 
@@ -98,17 +99,28 @@
         Constructor implConstructor = propertyResolverImplClass.getConstructor(Map.class);
         Object mutableProps = implConstructor.newInstance(props);
         
-        felix = felixClass.newInstance();
-        Method startMethod = felixClass.getMethod("start", propertyResolverClass, List.class);
-        List<BundleActivator> activators = new ArrayList<BundleActivator>();
-        BundleActivator activator = new FelixRuntime();
-        activators.add(activator);
-        startMethod.invoke(felix, mutableProps, activators);
-        
-        synchronized (activator) {
-            int retries = 0;
-            while (bundleContext == null && retries++ < 10) {
-                activator.wait(1000);
+        try {
+            Constructor felixConstructor = felixClass.getConstructor(propertyResolverClass, List.class);
+            List<BundleActivator> activators = new ArrayList<BundleActivator>();
+            felix = felixConstructor.newInstance(mutableProps, activators);
+            ((Bundle)felix).start();
+            bundleContext = ((Bundle)felix).getBundleContext();
+            
+        } catch (Exception e) {
+            
+        
+            felix = felixClass.newInstance();
+            Method startMethod = felixClass.getMethod("start", propertyResolverClass, List.class);
+            List<BundleActivator> activators = new ArrayList<BundleActivator>();
+            BundleActivator activator = new FelixRuntime();
+            activators.add(activator);
+            startMethod.invoke(felix, mutableProps, activators);
+        
+            synchronized (activator) {
+                int retries = 0;
+                while (bundleContext == null && retries++ < 10) {
+                    activator.wait(1000);
+                }
             }
         }
         
@@ -143,7 +155,11 @@
             return;
         bundleContext = null;
         instance = null;
-        if (felix != null) {
+        
+        if (felix instanceof Bundle) {
+            ((Bundle)felix).stop();
+        }
+        else if (felix != null) {
             Method shutdownMethod = felixClass.getMethod("shutdown");
             try {
                 shutdownMethod.invoke(felix);

Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java?view=diff&rev=553957&r1=553956&r2=553957
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java Fri Jul  6 10:09:50 2007
@@ -27,6 +27,7 @@
 import org.apache.tuscany.sca.assembly.impl.ComponentTypeImpl;
 import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationInterface;
 import org.apache.tuscany.sca.scope.Scope;
+import org.osoa.sca.annotations.AllowsPassByReference;
 
 
 /**
@@ -45,6 +46,9 @@
     private boolean needsPropertyInjection;
     private Hashtable<String, List<ComponentProperty>> referenceProperties;
     private Hashtable<String, List<ComponentProperty>> serviceProperties;
+
+    private Hashtable<String, List<ComponentProperty>> referenceCallbackProperties;
+    private Hashtable<String, List<ComponentProperty>> serviceCallbackProperties;
     
 
     public OSGiImplementation(String bundleName, 
@@ -97,6 +101,14 @@
         return serviceProperties.get(serviceName);
     }
     
+    public List<ComponentProperty> getReferenceCallbackProperties(String referenceName) {
+        return referenceCallbackProperties.get(referenceName);
+    }
+    
+    public List<ComponentProperty> getServiceCallbackProperties(String serviceName) {
+        return serviceCallbackProperties.get(serviceName);
+    }
+    
 
     public boolean isAllowsPassByReference(Method method) {
         
@@ -112,6 +124,18 @@
         }
         return false;
     }
+    
+    public boolean isAllowsPassByReferenceAnnotation(Method method) {
+        
+        if (method.getAnnotation(AllowsPassByReference.class) != null) {
+            return true;
+        }
+        else if (method.getClass().getAnnotation(AllowsPassByReference.class) != null) {
+            return true;
+        }
+        else            
+            return false;
+    }
 
     
     public boolean needsPropertyInjection() {
@@ -131,4 +155,13 @@
         return Long.MAX_VALUE;
     }
     
+    
+    protected void setCallbackProperties(Hashtable<String, List<ComponentProperty>> refCallbackProperties, 
+            Hashtable<String, List<ComponentProperty>> serviceCallbackProperties) {
+        
+        this.referenceCallbackProperties = refCallbackProperties;
+        this.serviceCallbackProperties = serviceCallbackProperties;
+        
+    }
+
 }

Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java?view=diff&rev=553957&r1=553956&r2=553957
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java Fri Jul  6 10:09:50 2007
@@ -154,6 +154,10 @@
                 new Hashtable<String, List<ComponentProperty>>();
             Hashtable<String, List<ComponentProperty>> serviceProperties = 
                 new Hashtable<String, List<ComponentProperty>>();
+            Hashtable<String, List<ComponentProperty>> refCallbackProperties = 
+                new Hashtable<String, List<ComponentProperty>>();
+            Hashtable<String, List<ComponentProperty>> serviceCallbackProperties = 
+                new Hashtable<String, List<ComponentProperty>>();
             
             while (reader.hasNext()) {
                 
@@ -170,11 +174,17 @@
                     //        instance of an implementation.
                     String refName = reader.getAttributeValue(null, "reference");
                     String serviceName = reader.getAttributeValue(null, "service");
+                    String refCallbackName = reader.getAttributeValue(null, "referenceCallback");
+                    String serviceCallbackName = reader.getAttributeValue(null, "serviceCallback");
                     List<ComponentProperty> props = readProperties(reader);
                     if (refName != null)
                         refProperties.put(refName, props);
                     else if (serviceName != null)
                         serviceProperties.put(serviceName, props);
+                    else if (refCallbackName != null)
+                        refCallbackProperties.put(refCallbackName, props);
+                    else if (serviceCallbackName != null)
+                        serviceCallbackProperties.put(serviceCallbackName, props);
                     else
                         throw new ContributionReadException("Properties in implementation.osgi should specify service or reference");                }
             }
@@ -189,6 +199,7 @@
                     refProperties,
                     serviceProperties,
                     injectProperties);
+            implementation.setCallbackProperties(refCallbackProperties, serviceCallbackProperties);
             
             
             implementation.setUnresolved(true);
@@ -225,7 +236,17 @@
                         Class<?> javaClass = Class.forName(javaInterface.getName());
                         javaInterface.setJavaClass(javaClass);
                     }
-                    Service serv = createService(service, javaInterface.getJavaClass());
+                    Class<?> callback = null;
+                    if (service.getInterfaceContract().getCallbackInterface() instanceof JavaInterface) {
+                        JavaInterface callbackInterface = (JavaInterface)service.getInterfaceContract().getCallbackInterface();
+                        if (callbackInterface.getJavaClass() == null) {
+                            Class<?> javaClass = Class.forName(javaInterface.getName());
+                            callbackInterface.setJavaClass(javaClass);
+                        }
+                        callback = callbackInterface.getJavaClass();
+                    }
+                    
+                    Service serv = createService(service, javaInterface.getJavaClass(), callback);
                     impl.getServices().add(serv);
                 }
             }
@@ -259,17 +280,23 @@
         
     }
     
-    private Service createService(Service serv, Class<?> interfaze) throws InvalidInterfaceException {
+    private Service createService(Service serv, Class<?> interfaze, Class<?> callbackInterfaze) throws InvalidInterfaceException {
         Service service = assemblyFactory.createService();
         JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
         service.setInterfaceContract(interfaceContract);
-
+        
+        
         // create a relative URI
         service.setName(serv.getName());
 
         JavaInterface callInterface = interfaceIntrospector.introspect(interfaze);
         service.getInterfaceContract().setInterface(callInterface);
-        if (callInterface.getCallbackClass() != null) {
+        
+        if (callbackInterfaze != null) {
+            JavaInterface callbackInterface = interfaceIntrospector.introspect(callbackInterfaze);
+            service.getInterfaceContract().setCallbackInterface(callbackInterface);
+        }
+        else if (callInterface.getCallbackClass() != null) {
             JavaInterface callbackInterface = interfaceIntrospector.introspect(callInterface.getCallbackClass());
             service.getInterfaceContract().setCallbackInterface(callbackInterface);
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org