tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r831516 - in /tuscany/java/sca/modules: endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/ implementation-osgi/src/main/java/or...
Date Sat, 31 Oct 2009 06:03:33 GMT
Author: rfeng
Date: Sat Oct 31 06:03:33 2009
New Revision: 831516

URL: http://svn.apache.org/viewvc?rev=831516&view=rev
Log:
Resolve interfaces from the remote endpoints (tribes based discovery is now working)

Modified:
    tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
    tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
    tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
    tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
    tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
    tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
    tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java

Modified: tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java?rev=831516&r1=831515&r2=831516&view=diff
==============================================================================
--- tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
(original)
+++ tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
Sat Oct 31 06:03:33 2009
@@ -354,10 +354,11 @@
 
     public void entryAdded(Object key, Object value) {
         MapEntry entry = (MapEntry)value;
+        Endpoint newEp = (Endpoint)entry.getValue();
         if (!isLocal(entry)) {
             logger.info(id + " Remote endpoint added: " + entry.getValue());
+            newEp.setRemote(true);
         }
-        Endpoint newEp = (Endpoint)entry.getValue();
         newEp.setExtensionPointRegistry(registry);
         for (EndpointListener listener : listeners) {
             listener.endpointAdded(newEp);

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java?rev=831516&r1=831515&r2=831516&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
(original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
Sat Oct 31 06:03:33 2009
@@ -97,8 +97,8 @@
         for (ComponentReference ref : component.getReferences()) {
             RuntimeComponentReference reference = (RuntimeComponentReference)ref;
             InterfaceContract interfaceContract = reference.getInterfaceContract();
-            JavaInterface javaInterface = (JavaInterface)interfaceContract.getInterface();
-            final Class<?> interfaceClass = javaInterface.getJavaClass();
+            final JavaInterface javaInterface = (JavaInterface)interfaceContract.getInterface();
+            // final Class<?> interfaceClass = javaInterface.getJavaClass();
 
             //            final Hashtable<String, Object> props = new Hashtable<String,
Object>();
             //            props.put(FILTER_MATCH_CRITERIA, "");
@@ -113,14 +113,14 @@
             osgiProps.put(SERVICE_IMPORTED_CONFIGS, new String[] {REMOTE_CONFIG_SCA});
 
             for (RuntimeWire wire : reference.getRuntimeWires()) {
-                final OSGiServiceFactory serviceFactory = new OSGiServiceFactory(interfaceClass.getName(),
wire);
+                final OSGiServiceFactory serviceFactory = new OSGiServiceFactory(javaInterface.getName(),
wire);
                 ServiceRegistration registration =
                     AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>()
{
                         public ServiceRegistration run() {
                             // Register the proxy as OSGi service
                             BundleContext context = osgiBundle.getBundleContext();
                             ServiceRegistration registration =
-                                context.registerService(interfaceClass.getName(), serviceFactory,
osgiProps);
+                                context.registerService(javaInterface.getName(), serviceFactory,
osgiProps);
                             return registration;
                         }
                     });
@@ -130,6 +130,17 @@
         
         // Set the OSGi service reference properties into the SCA service
         for (ComponentService service : component.getServices()) {
+            // The properties might have been set by the export service
+            boolean found = false;
+            for (Object ext : service.getExtensions()) {
+                if (ext instanceof OSGiProperty) {
+                    found = true;
+                    break;
+                }
+            }
+            if (found) {
+                continue;
+            }
             ServiceReference serviceReference = getServiceReference(osgiBundle.getBundleContext(),
service);
             if (serviceReference != null) {
                 service.getExtensions().addAll(implementationFactory.createOSGiProperties(serviceReference));

Modified: tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java?rev=831516&r1=831515&r2=831516&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
(original)
+++ tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
Sat Oct 31 06:03:33 2009
@@ -96,7 +96,7 @@
     public void write(OSGiProperty model, XMLStreamWriter writer, ProcessorContext context)
throws ContributionWriteException, XMLStreamException {
         writer.writeStartElement(PROPERTY_QNAME.getNamespaceURI(), PROPERTY_QNAME.getLocalPart());
         writer.writeAttribute(NAME, model.getName());
-        writer.writeAttribute(TYPE, model.getName());
+        writer.writeAttribute(TYPE, model.getType());
         writer.writeCharacters(model.getStringValue());
         writer.writeEndElement();
     }

Modified: tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java?rev=831516&r1=831515&r2=831516&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
(original)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
Sat Oct 31 06:03:33 2009
@@ -23,7 +23,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.UUID;
 
 import org.apache.tuscany.sca.assembly.Endpoint;
 import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
@@ -38,7 +37,6 @@
  * Implementation of {@link EndpointDescription}
  */
 public class EndpointHelper {
-    private final static String FRAMEWORK_UUID = "org.osgi.framework.uuid";
     private EndpointHelper() {
     }
 
@@ -56,7 +54,7 @@
         Map<String, Object> props = new HashMap<String, Object>();
         
         if (!endpoint.isRemote()) {
-            String uuid = getFrameworkUUID(bundleContext);
+            String uuid = OSGiHelper.getFrameworkUUID(bundleContext);
             props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, uuid);
         }
         
@@ -77,20 +75,6 @@
         return props;
     }
 
-    public synchronized static String getFrameworkUUID(BundleContext bundleContext) {
-        String uuid = null;
-        if (bundleContext != null) {
-            uuid = bundleContext.getProperty(FRAMEWORK_UUID);
-        } else {
-            uuid = System.getProperty(FRAMEWORK_UUID);
-        }
-        if (uuid == null) {
-            uuid = UUID.randomUUID().toString();
-        }
-        System.setProperty(FRAMEWORK_UUID, uuid);
-        return uuid;
-    }
-
     public static Endpoint getEndpoint(EndpointDescription endpointDescription) {
         return (Endpoint)endpointDescription.getProperties().get(Endpoint.class.getName());
     }

Modified: tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java?rev=831516&r1=831515&r2=831516&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
(original)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
Sat Oct 31 06:03:33 2009
@@ -24,6 +24,7 @@
 import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS;
 import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS_EXTRA;
 import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTERFACES;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.getStringArray;
 import static org.osgi.framework.Constants.OBJECTCLASS;
 import static org.osgi.framework.Constants.SERVICE_ID;
 
@@ -55,17 +56,17 @@
 import org.apache.tuscany.sca.contribution.Contribution;
 import org.apache.tuscany.sca.contribution.ContributionFactory;
 import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
 import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
 import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
 import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.deployment.Deployer;
 import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
 import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
 import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
 import org.apache.tuscany.sca.implementation.osgi.SCAConfig;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
@@ -86,16 +87,17 @@
  * implementation.osgi
  */
 public class EndpointIntrospector {
-    private BundleContext context;
+    // private BundleContext context;
     private AssemblyFactory assemblyFactory;
     private ContributionFactory contributionFactory;
     private OSGiImplementationFactory implementationFactory;
     private PolicyFactory policyFactory;
-    private ExtensionPointRegistry registry;
+    // private ExtensionPointRegistry registry;
     private FactoryExtensionPoint factories;
     private ModelResolverExtensionPoint modelResolvers;
+    // private StAXArtifactProcessor<Composite> compositeProcessor;
     private JavaInterfaceFactory javaInterfaceFactory;
-    private Deployer deployer;
+    // private Deployer deployer;
     private ServiceTracker discoveryTracker;
 
     /**
@@ -124,17 +126,19 @@
      */
     public EndpointIntrospector(BundleContext context, ExtensionPointRegistry registry, ServiceTracker
discoveryTracker) {
         super();
-        this.context = context;
+        // this.context = context;
         this.discoveryTracker = discoveryTracker;
-        this.registry = registry;
+        // this.registry = registry;
         this.factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
         this.modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class);
+//        this.compositeProcessor =
+//            registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class).getProcessor(Composite.class);
         this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
         this.contributionFactory = factories.getFactory(ContributionFactory.class);
         this.policyFactory = factories.getFactory(PolicyFactory.class);
         this.implementationFactory = factories.getFactory(OSGiImplementationFactory.class);
         this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
-        this.deployer = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Deployer.class);
+        // this.deployer = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Deployer.class);
     }
 
     private Intent getIntent(String intent) {
@@ -232,54 +236,79 @@
      * @throws Exception
      */
     public Contribution introspect(ServiceReference reference, Map<String, Object>
props) throws Exception {
+        Bundle bundle = reference.getBundle();
         Map<String, Object> properties = getProperties(reference, props);
+        Long sid = (Long)reference.getProperty(SERVICE_ID);
 
-        OSGiProperty serviceID = implementationFactory.createOSGiProperty();
-        serviceID.setName(SERVICE_ID);
-        // The service.id is Long
-        serviceID.setValue(String.valueOf(reference.getProperty(SERVICE_ID)));
+        String[] requiredIntents = getStringArray(properties.get(SERVICE_EXPORTED_INTENTS));
+        List<Intent> intents = getIntents(requiredIntents);
+        String[] requiredIntentsExtra = getStringArray(properties.get(SERVICE_EXPORTED_INTENTS_EXTRA));
+        List<Intent> extraIntents = getIntents(requiredIntentsExtra);
+        Set<Intent> allIntents = new HashSet<Intent>(intents);
+        allIntents.addAll(extraIntents);
+
+        String[] bindingNames = getStringArray(properties.get(SCA_BINDINGS));
+        Collection<Binding> bindings = loadBindings(bindingNames);
 
+        String[] remoteInterfaces = getStringArray(reference.getProperty(SERVICE_EXPORTED_INTERFACES));
+        if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0]))
{
+            remoteInterfaces = getStringArray(reference.getProperty(OBJECTCLASS));
+        } else {
+            remoteInterfaces = parse(remoteInterfaces);
+            String[] objectClasses = getStringArray(reference.getProperty(OBJECTCLASS));
+            Set<String> objectClassSet = new HashSet<String>(Arrays.asList(objectClasses));
+            if (!objectClassSet.containsAll(Arrays.asList(remoteInterfaces))) {
+                throw new IllegalArgumentException(
+                                                   "The exported interfaces are not a subset
of the types" + " listed in the objectClass service property from the Service Reference");
+            }
+        }
+
+        Contribution contribution = generateContribution(bundle, sid, remoteInterfaces, bindings,
allIntents);
+        return contribution;
+    }
+
+    /**
+     * Generate a contribution that contains the composite for the exported service
+     * @param bundle The OSGi bundle
+     * @param sid The service id
+     * @param remoteInterfaces 
+     * @param bindings
+     * @param allIntents
+     * @return
+     * @throws ClassNotFoundException
+     * @throws InvalidInterfaceException
+     */
+    private Contribution generateContribution(Bundle bundle,
+                                              Long sid,
+                                              String[] remoteInterfaces,
+                                              Collection<Binding> bindings,
+                                              Set<Intent> allIntents) throws ClassNotFoundException,
+        InvalidInterfaceException {
         String id = "osgi.service." + UUID.randomUUID();
         Composite composite = assemblyFactory.createComposite();
         composite.setName(new QName(SCA11_TUSCANY_NS, id));
 
         Component component = assemblyFactory.createComponent();
         component.setName(id);
-        component.setAutowire(Boolean.TRUE);
 
         composite.getComponents().add(component);
 
-        Bundle bundle = reference.getBundle();
         OSGiImplementation implementation = implementationFactory.createOSGiImplementation();
 
         implementation.setBundle(bundle);
         component.setImplementation(implementation);
         implementation.setUnresolved(false);
 
-        String[] remoteInterfaces = getStrings(reference.getProperty(SERVICE_EXPORTED_INTERFACES));
-        if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0]))
{
-            remoteInterfaces = getStrings(reference.getProperty(OBJECTCLASS));
-        } else {
-            remoteInterfaces = parse(remoteInterfaces);
-            String[] objectClasses = getStrings(reference.getProperty(OBJECTCLASS));
-            Set<String> objectClassSet = new HashSet<String>(Arrays.asList(objectClasses));
-            if (!objectClassSet.containsAll(Arrays.asList(remoteInterfaces))) {
-                throw new IllegalArgumentException(
-                                                   "The exported interfaces are not a subset
of the types" + " listed in the objectClass service property from the Service Reference");
-            }
-        }
+        OSGiProperty serviceID = implementationFactory.createOSGiProperty();
+        serviceID.setName(SERVICE_ID);
+        // The service.id is Long
+        serviceID.setValue(String.valueOf(sid));
+
         for (String intf : remoteInterfaces) {
             Service service = assemblyFactory.createService();
-            JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
-            Class<?> interfaceClass = bundle.loadClass(intf);
-            JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
-            interfaceContract.setInterface(javaInterface);
-            if (javaInterface.getCallbackClass() != null) {
-                interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
-                    .getCallbackClass()));
-            }
-
-            service.setName(interfaceClass.getSimpleName());
+            JavaInterfaceContract interfaceContract = createJavaInterfaceContract(bundle,
intf);
+            String name = intf.substring(intf.lastIndexOf('.') + 1);
+            service.setName(name);
             service.setInterfaceContract(interfaceContract);
 
             service.getExtensions().add(serviceID);
@@ -292,39 +321,63 @@
             componentService.setService(service);
         }
 
-        String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
-        List<Intent> intents = getIntents(requiredIntents);
-        String[] requiredIntentsExtra = getStrings(properties.get(SERVICE_EXPORTED_INTENTS_EXTRA));
-        List<Intent> extraIntents = getIntents(requiredIntentsExtra);
-
-        String[] bindingNames = getStrings(properties.get(SCA_BINDINGS));
-        Collection<Binding> bindings = loadBindings(bindingNames);
-
         for (ComponentService componentService : component.getServices()) {
-            componentService.getRequiredIntents().addAll(intents);
-            componentService.getRequiredIntents().addAll(extraIntents);
+            componentService.getRequiredIntents().addAll(allIntents);
             componentService.getBindings().addAll(bindings);
         }
 
         // FIXME: Should we scan the owning bundle to create the SCA contribution?
+        Contribution contribution = createContribution(bundle, id, composite);
+        return contribution;
+    }
+
+    private Contribution createContribution(Bundle bundle, String id, Composite composite)
{
         Contribution contribution = contributionFactory.createContribution();
+        contribution.setClassLoader(OSGiHelper.createBundleClassLoader(bundle));
         contribution.setURI("urn:" + id);
         contribution.setLocation(bundle.getEntry("/").toString());
         contribution.getDeployables().add(composite);
         ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers,
factories);
         contribution.setModelResolver(modelResolver);
+        // compositeProcessor.resolve(composite, modelResolver, new ProcessorContext(registry));
         contribution.setUnresolved(true);
         return contribution;
     }
 
+    /**
+     * @param bundle
+     * @param endpoint
+     * @return
+     * @throws Exception
+     */
     public Contribution introspect(Bundle bundle, EndpointDescription endpoint) throws Exception
{
+        Collection<Binding> bindings = Collections.emptyList();
+        Collection<String> interfaces = Collections.emptyList();
+        Collection<Intent> intents = Collections.emptyList();
         Endpoint ep = (Endpoint)endpoint.getProperties().get(Endpoint.class.getName());
         if (ep != null) {
-            return introspect(bundle, ep);
+            bindings = Collections.singletonList(ep.getBinding());
+            interfaces = Collections.singletonList(((JavaInterface)ep.getInterfaceContract().getInterface()).getName());
+            intents = ep.getRequiredIntents();
+        } else {
+            Map<String, Object> properties = endpoint.getProperties();
+            interfaces = endpoint.getInterfaces();
+            String[] requiredIntents = getStringArray(properties.get(SERVICE_EXPORTED_INTENTS));
+            intents = getIntents(requiredIntents);
+
+            String[] bindingNames = getStringArray(properties.get(SCA_BINDINGS));
+            bindings = loadBindings(bindingNames);
         }
-        Map<String, Object> properties = endpoint.getProperties();
-        List<String> remoteInterfaces = endpoint.getInterfaces();
 
+        Contribution contribution = generateContribution(bundle, interfaces, bindings, intents);
+        return contribution;
+    }
+
+    private Contribution generateContribution(Bundle bundle,
+                                              Collection<String> remoteInterfaces,
+                                              Collection<Binding> bindings,
+                                              Collection<Intent> intents) throws ClassNotFoundException,
+        InvalidInterfaceException, ContributionResolveException {
         String id = "osgi.reference." + UUID.randomUUID();
         Composite composite = assemblyFactory.createComposite();
         composite.setName(new QName(Base.SCA11_TUSCANY_NS, id));
@@ -344,14 +397,7 @@
         int count = 0;
         for (String intf : remoteInterfaces) {
             Reference reference = assemblyFactory.createReference();
-            JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
-            Class<?> interfaceClass = bundle.loadClass(intf);
-            JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
-            interfaceContract.setInterface(javaInterface);
-            if (javaInterface.getCallbackClass() != null) {
-                interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
-                    .getCallbackClass()));
-            }
+            JavaInterfaceContract interfaceContract = createJavaInterfaceContract(bundle,
intf);
 
             reference.setName("ref" + (count++));
             reference.setInterfaceContract(interfaceContract);
@@ -365,77 +411,30 @@
             componentReference.setWiredByImpl(true);
         }
 
-        String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
-        List<Intent> intents = getIntents(requiredIntents);
-
-        String[] bindingNames = getStrings(properties.get(SCA_BINDINGS));
-        Collection<Binding> bindings = loadBindings(bindingNames);
-
         for (ComponentReference componentReference : component.getReferences()) {
             componentReference.getRequiredIntents().addAll(intents);
             componentReference.getBindings().addAll(bindings);
         }
-        // FIXME: Should we scan the owning bundle to create the SCA contribution?
-        Contribution contribution = contributionFactory.createContribution();
-        contribution.setURI("urn:" + id);
-        contribution.setLocation(bundle.getEntry("/").toString());
-        contribution.getDeployables().add(composite);
-        ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers,
factories);
-        contribution.setModelResolver(modelResolver);
-        contribution.setUnresolved(true);
+
+        Contribution contribution = createContribution(bundle, id, composite);
         return contribution;
     }
 
-    public Contribution introspect(Bundle bundle, Endpoint endpoint) throws Exception {
-        String id = "osgi.reference." + UUID.randomUUID();
-        Composite composite = assemblyFactory.createComposite();
-        composite.setName(new QName(Base.SCA11_TUSCANY_NS, id));
-
-        Component component = assemblyFactory.createComponent();
-        component.setName(id);
-        // component.setAutowire(Boolean.TRUE);
-
-        composite.getComponents().add(component);
-
-        OSGiImplementation implementation = implementationFactory.createOSGiImplementation();
-
-        implementation.setBundle(bundle);
-        component.setImplementation(implementation);
-        implementation.setUnresolved(false);
-
-        Reference reference = assemblyFactory.createReference();
-        Service service = endpoint.getService().getService();
-        reference.setInterfaceContract(service.getInterfaceContract());
-        reference.setName("ref");
-
-        reference.getBindings().add(endpoint.getBinding());
-
-        /*
-        reference.getRequiredIntents().addAll(service.getRequiredIntents());
-        reference.getPolicySets().addAll(service.getPolicySets());
-        */
-
-        implementation.getReferences().add(reference);
-
-        ComponentReference componentReference = assemblyFactory.createComponentReference();
-        component.getReferences().add(componentReference);
-        componentReference.setReference(reference);
-        componentReference.setName(reference.getName());
-        componentReference.setWiredByImpl(true);
-
-        // FIXME: Should we scan the owning bundle to create the SCA contribution?
-        Contribution contribution = contributionFactory.createContribution();
-        contribution.setURI("urn:" + id);
-        contribution.setLocation(bundle.getEntry("/").toString());
-        contribution.getDeployables().add(composite);
-        ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers,
factories);
-        contribution.setModelResolver(modelResolver);
-        contribution.setUnresolved(true);
-        return contribution;
+    private JavaInterfaceContract createJavaInterfaceContract(Bundle bundle, String intf)
+        throws ClassNotFoundException, InvalidInterfaceException {
+        JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+        Class<?> interfaceClass = bundle.loadClass(intf);
+        JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
+        interfaceContract.setInterface(javaInterface);
+        if (javaInterface.getCallbackClass() != null) {
+            interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
+                .getCallbackClass()));
+        }
+        return interfaceContract;
     }
 
-    private Collection<Binding> loadBindings(String[] qnames) throws IOException,
-        ContributionReadException, XMLStreamException {
+    private Collection<Binding> loadBindings(String[] qnames) throws IOException, ContributionReadException,
+        XMLStreamException {
         if (qnames == null || qnames.length == 0) {
             return Collections.emptyList();
         }
@@ -472,23 +471,4 @@
         return bindingMap.values();
     }
 
-    /**
-     * In OSGi, the value of String+ can be a single String, String[] or Collection<String>
-     * @param value
-     * @return
-     */
-    private String[] getStrings(Object value) {
-        if (value == null) {
-            return null;
-        }
-        if (value instanceof String) {
-            return new String[] {(String)value};
-        } else if (value instanceof Collection) {
-            Collection<String> collection = (Collection)value;
-            return collection.toArray(new String[collection.size()]);
-        }
-        return (String[])value;
-
-    }
-
 }

Modified: tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java?rev=831516&r1=831515&r2=831516&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
(original)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
Sat Oct 31 06:03:33 2009
@@ -19,12 +19,15 @@
 
 package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
 
+import java.io.IOException;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashSet;
+import java.util.List;
+import java.util.UUID;
 
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
@@ -40,6 +43,8 @@
  * 
  */
 public class OSGiHelper {
+    public final static String FRAMEWORK_UUID = "org.osgi.framework.uuid";
+
     private OSGiHelper() {
     }
 
@@ -140,6 +145,60 @@
         FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class);
         OSGiImplementationFactory implementationFactory= factoryExtensionPoint.getFactory(OSGiImplementationFactory.class);
         return implementationFactory.createOSGiProperties(reference);
+    }
+    
+    public static OSGiProperty createOSGiProperty(ExtensionPointRegistry registry, String
name, Object value) {
+        FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class);
+        OSGiImplementationFactory implementationFactory= factoryExtensionPoint.getFactory(OSGiImplementationFactory.class);
+        return implementationFactory.createOSGiProperty(name, value);
+    }
+
+
+    public synchronized static String getFrameworkUUID(BundleContext bundleContext) {
+        String uuid = null;
+        if (bundleContext != null) {
+            uuid = bundleContext.getProperty(FRAMEWORK_UUID);
+        } else {
+            uuid = System.getProperty(FRAMEWORK_UUID);
+        }
+        if (uuid == null) {
+            uuid = UUID.randomUUID().toString();
+        }
+        System.setProperty(FRAMEWORK_UUID, uuid);
+        return uuid;
+    }  
+    
+    public static ClassLoader createBundleClassLoader(Bundle bundle) {
+        return new BundleClassLoader(bundle);
+    }
+    
+    private static class BundleClassLoader extends ClassLoader {
+        private Bundle bundle;
+        public BundleClassLoader(Bundle bundle) {
+            super(null);
+            this.bundle = bundle;
+        }
+
+        @Override
+        protected Class<?> findClass(String name) throws ClassNotFoundException {
+            return bundle.loadClass(name);
+        }
+
+        @Override
+        protected URL findResource(String name) {
+            return bundle.getResource(name);
+        }
+
+        @Override
+        protected Enumeration<URL> findResources(String name) throws IOException {
+            Enumeration<URL> urls = bundle.getResources(name);
+            if (urls == null) {
+                List<URL> list = Collections.emptyList();
+                return Collections.enumeration(list);
+            } else {
+                return urls;
+            }
+        }
     }    
 
 }

Modified: tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java?rev=831516&r1=831515&r2=831516&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
(original)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
Sat Oct 31 06:03:33 2009
@@ -19,7 +19,13 @@
 
 package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
 
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants.SERVICE_REMOTE_ID;
 import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.EndpointHelper.createEndpointDescription;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.createOSGiProperty;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.getFrameworkUUID;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.getOSGiProperties;
+import static org.osgi.framework.Constants.SERVICE_ID;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -77,7 +83,13 @@
                 configuration.getExtensions().add(reference.getBundle());
                 Component component = contribution.getDeployables().get(0).getComponents().get(0);
                 ComponentService service = component.getServices().get(0);
-                service.getExtensions().addAll(OSGiHelper.getOSGiProperties(registry, reference));
+                service.getExtensions().addAll(getOSGiProperties(registry, reference));
+                service.getExtensions().add(createOSGiProperty(registry,
+                                                               SERVICE_REMOTE_FRAMEWORK_UUID,
+                                                               getFrameworkUUID(reference.getBundle()
+                                                                   .getBundleContext())));
+                service.getExtensions().add(createOSGiProperty(registry, SERVICE_REMOTE_ID,
reference
+                    .getProperty(SERVICE_ID)));
 
                 // FIXME: Configure the domain and node URI
                 NodeImpl node = new NodeImpl(nodeFactory, configuration, Collections.singletonList(contribution));

Modified: tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java?rev=831516&r1=831515&r2=831516&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
(original)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
Sat Oct 31 06:03:33 2009
@@ -38,7 +38,7 @@
 import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
 import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
 import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants;
-import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.EndpointHelper;
+import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper;
 import org.oasisopen.sca.ServiceRuntimeException;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -92,7 +92,7 @@
             props.put(RemoteConstants.SERVICE_REMOTE_ID, String.valueOf(System.currentTimeMillis()));
         }
         if (!props.containsKey(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID)) {
-            props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, EndpointHelper.getFrameworkUUID(context));
+            props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, OSGiHelper.getFrameworkUUID(context));
         }
         if (!props.containsKey(RemoteConstants.SERVICE_REMOTE_URI)) {
             props.put(RemoteConstants.SERVICE_REMOTE_URI, UUID.randomUUID().toString());



Mime
View raw message