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 2009/11/03 01:14:54 UTC

svn commit: r832215 [1/2] - in /tuscany/branches/sca-java-2.0-M4: ./ distribution/all/ modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ modules/core/META-INF/ modules/core/src/main/java/org/apache/tuscany/sca/core/assem...

Author: rfeng
Date: Tue Nov  3 00:14:53 2009
New Revision: 832215

URL: http://svn.apache.org/viewvc?rev=832215&view=rev
Log:
Merge changes from trunk so that OSGi remote services can be run with Equinox and Felix over tribes's multicast. This introduces a dependency on tuscany maven-bundle-plugin 1.0.5-SNAPSHOT and we should release it with M4.

Modified:
    tuscany/branches/sca-java-2.0-M4/distribution/all/pom.xml
    tuscany/branches/sca-java-2.0-M4/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java
    tuscany/branches/sca-java-2.0-M4/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
    tuscany/branches/sca-java-2.0-M4/modules/core/META-INF/MANIFEST.MF
    tuscany/branches/sca-java-2.0-M4/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
    tuscany/branches/sca-java-2.0-M4/modules/endpoint-tribes/META-INF/MANIFEST.MF
    tuscany/branches/sca-java-2.0-M4/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
    tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
    tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java
    tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java
    tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
    tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java
    tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java
    tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
    tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java
    tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
    tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
    tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
    tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
    tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java
    tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java
    tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java
    tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
    tuscany/branches/sca-java-2.0-M4/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
    tuscany/branches/sca-java-2.0-M4/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java
    tuscany/branches/sca-java-2.0-M4/pom.xml

Modified: tuscany/branches/sca-java-2.0-M4/distribution/all/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/distribution/all/pom.xml?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/distribution/all/pom.xml (original)
+++ tuscany/branches/sca-java-2.0-M4/distribution/all/pom.xml Tue Nov  3 00:14:53 2009
@@ -64,7 +64,7 @@
             <plugin>
                 <groupId>org.apache.tuscany.maven.plugins</groupId> 
                 <artifactId>maven-bundle-plugin</artifactId> 
-                <version>1.0.4</version>
+                <version>1.0.5-SNAPSHOT</version>
                 <executions>
                     <execution>
                         <id>distribution-modules</id>

Modified: tuscany/branches/sca-java-2.0-M4/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java Tue Nov  3 00:14:53 2009
@@ -39,6 +39,7 @@
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
 import javax.xml.stream.EventFilter;
 import javax.xml.stream.StreamFilter;
 import javax.xml.stream.XMLEventReader;
@@ -49,6 +50,7 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.util.XMLEventAllocator;
 import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
@@ -56,9 +58,11 @@
 import org.apache.tuscany.sca.assembly.xsd.Constants;
 import org.apache.tuscany.sca.common.xml.XMLDocumentHelper;
 import org.apache.tuscany.sca.common.xml.stax.StAXHelper;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
 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.extensibility.ClassLoaderContext;
 import org.apache.tuscany.sca.monitor.Monitor;
 import org.apache.tuscany.sca.monitor.MonitorFactory;
 import org.w3c.dom.DOMImplementation;
@@ -75,7 +79,7 @@
  * @version $Rev$ $Date$
  */
 public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory implements LSResourceResolver {
-
+    private ExtensionPointRegistry registry;
     private XMLInputFactory inputFactory;
     private DocumentBuilderFactory documentBuilderFactory;
     private DOMImplementationLS ls;
@@ -87,6 +91,7 @@
     private StAXHelper helper;
 
     public DefaultValidatingXMLInputFactory(ExtensionPointRegistry registry) {
+        this.registry = registry;
         FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class);
         this.inputFactory = factoryExtensionPoint.getFactory(XMLInputFactory.class);
         this.documentBuilderFactory = factoryExtensionPoint.getFactory(DocumentBuilderFactory.class);
@@ -102,9 +107,11 @@
      * @param inputFactory
      * @param schemas
      */
+    // FOR Test only
     public DefaultValidatingXMLInputFactory(XMLInputFactory inputFactory, ValidationSchemaExtensionPoint schemas) {
         this.inputFactory = inputFactory;
         this.schemas = schemas;
+        this.registry = new DefaultExtensionPointRegistry();
     }
     
 
@@ -188,8 +195,7 @@
             }
             final Collection<? extends Source> sources = aggregate(urls);            
 
-            // Create an aggregated validation schemas from all the XSDs
-            final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+            final SchemaFactory schemaFactory = newSchemaFactory();
             DOMImplementation impl = null;
             try {
                 impl = documentBuilderFactory.newDocumentBuilder().getDOMImplementation();
@@ -225,6 +231,30 @@
         }
     }
 
+    /**
+     * For OSGi:
+     * Create a SchemaFactory in the context of service provider classloaders
+     * @return
+     */
+    private SchemaFactory newSchemaFactory() {
+        ClassLoader cl =
+            ClassLoaderContext.setContextClassLoader(getClass().getClassLoader(),
+                                                     registry.getServiceDiscovery(),
+                                                     SchemaFactory.class,
+                                                     TransformerFactory.class,
+                                                     SAXParserFactory.class,
+                                                     DocumentBuilderFactory.class
+                                                     );
+        try {
+            // Create an aggregated validation schemas from all the XSDs
+            return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+        } finally {
+            if (cl != null) {
+                Thread.currentThread().setContextClassLoader(cl);
+            }
+        }
+    }
+
     @Override
     public XMLEventReader createFilteredReader(XMLEventReader arg0, EventFilter arg1) throws XMLStreamException {
         return inputFactory.createFilteredReader(arg0, arg1);

Modified: tuscany/branches/sca-java-2.0-M4/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java Tue Nov  3 00:14:53 2009
@@ -33,6 +33,7 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.tuscany.sca.assembly.Extension;
 import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
@@ -56,7 +57,6 @@
     private XMLInputFactory inputFactory;
     private XMLOutputFactory outputFactory;
     private StAXArtifactProcessorExtensionPoint processors;
-    
 
     /**
      * Constructs a new ExtensibleStAXArtifactProcessor.
@@ -172,7 +172,6 @@
 
     @SuppressWarnings("unchecked")
     public void write(Object model, XMLStreamWriter outputSource, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
-        Monitor monitor = context.getMonitor();
         // Delegate to the processor associated with the model type
         if (model != null) {
             StAXArtifactProcessor processor = processors.getProcessor(model.getClass());
@@ -182,11 +181,8 @@
                 if (logger.isLoggable(Level.WARNING)) {
                     logger.warning("No StAX processor is configured to handle " + model.getClass());
                 }
-                if (!XMLStreamReader.class.isInstance(model)) {
-                    warning(monitor, "NoStaxProcessor", processors, model.getClass());
-                }
                 StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT);
-                if (anyElementProcessor != null) {
+                if ((model instanceof Extension) && anyElementProcessor != null) {
                     anyElementProcessor.write(model, outputSource, context);
                 }
             }

Modified: tuscany/branches/sca-java-2.0-M4/modules/core/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/core/META-INF/MANIFEST.MF?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/core/META-INF/MANIFEST.MF (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/core/META-INF/MANIFEST.MF Tue Nov  3 00:14:53 2009
@@ -1,5 +1,7 @@
 Manifest-Version: 1.0
-Export-Package: org.apache.tuscany.sca.core.assembly;version="2.0.0";uses:="org.apache.tuscany.sca.assembly,org.apache.tuscany.sca.core",
+Export-Package: org.apache.tuscany.sca.core.assembly;version="2.0.0";
+ uses:="org.apache.tuscany.sca.assembly,org.apache.tuscany.sca.core",
+ org.apache.tuscany.sca.core.assembly.impl;version="2.0.0";scope=internal;mandatory:=scope,
  org.apache.tuscany.sca.core.context;version="2.0.0";
   uses:="javax.xml.stream,
    org.apache.tuscany.sca.runtime,

Modified: tuscany/branches/sca-java-2.0-M4/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java Tue Nov  3 00:14:53 2009
@@ -497,7 +497,26 @@
         }
 
         compositeContext.bindComponent(runtimeComponent);
+        Implementation implementation = component.getImplementation();
+        
+        if (implementation instanceof Composite) {
+            start(compositeContext, (Composite)implementation);
+        } else {
+            for (PolicyProvider policyProvider : runtimeComponent.getPolicyProviders()) {
+                policyProvider.start();
+            }
+            ImplementationProvider implementationProvider = runtimeComponent.getImplementationProvider();
+            if (implementationProvider != null) {
+                implementationProvider.start();
+            }
+        }
 
+        if (component instanceof ScopedRuntimeComponent) {
+            ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component;
+            if (scopedRuntimeComponent.getScopeContainer() != null) {
+                scopedRuntimeComponent.getScopeContainer().start();
+            }
+        }
         // Reference bindings aren't started until the wire is first used
 
         for (ComponentService service : component.getServices()) {
@@ -526,26 +545,6 @@
             }
         }
 
-        Implementation implementation = component.getImplementation();
-        if (implementation instanceof Composite) {
-            start(compositeContext, (Composite)implementation);
-        } else {
-            for (PolicyProvider policyProvider : runtimeComponent.getPolicyProviders()) {
-                policyProvider.start();
-            }
-            ImplementationProvider implementationProvider = runtimeComponent.getImplementationProvider();
-            if (implementationProvider != null) {
-                implementationProvider.start();
-            }
-        }
-
-        if (component instanceof ScopedRuntimeComponent) {
-            ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component;
-            if (scopedRuntimeComponent.getScopeContainer() != null) {
-                scopedRuntimeComponent.getScopeContainer().start();
-            }
-        }
-
         runtimeComponent.setStarted(true);
     }
 

Modified: tuscany/branches/sca-java-2.0-M4/modules/endpoint-tribes/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/endpoint-tribes/META-INF/MANIFEST.MF?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/endpoint-tribes/META-INF/MANIFEST.MF (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/endpoint-tribes/META-INF/MANIFEST.MF Tue Nov  3 00:14:53 2009
@@ -21,6 +21,7 @@
  org.apache.catalina.tribes.util,
  org.apache.juli.logging;resolution:=optional,
  org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.core.assembly.impl;version="2.0.0";scope=internal;resolution:=optional,
  org.apache.tuscany.sca.core;version="2.0.0",
  org.apache.tuscany.sca.management;version="2.0.0",
  org.apache.tuscany.sca.policy;version="2.0.0",

Modified: tuscany/branches/sca-java-2.0-M4/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java Tue Nov  3 00:14:53 2009
@@ -354,10 +354,12 @@
 
     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/branches/sca-java-2.0-M4/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java Tue Nov  3 00:14:53 2009
@@ -37,6 +37,7 @@
 import org.apache.tuscany.sca.core.invocation.ProxyFactory;
 import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
 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.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.Operation;
@@ -63,14 +64,18 @@
     private RuntimeComponent component;
     private ProxyFactoryExtensionPoint proxyFactoryExtensionPoint;
     private Bundle osgiBundle;
+    private boolean startedByMe;
     private OSGiImplementation implementation;
     private List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
+    private OSGiImplementationFactory implementationFactory;
 
     public OSGiImplementationProvider(RuntimeComponent component,
                                       OSGiImplementation impl,
-                                      ProxyFactoryExtensionPoint proxyFactoryExtensionPoint) throws BundleException {
+                                      ProxyFactoryExtensionPoint proxyFactoryExtensionPoint,
+                                      OSGiImplementationFactory implementationFactory) throws BundleException {
         this.component = component;
         this.proxyFactoryExtensionPoint = proxyFactoryExtensionPoint;
+        this.implementationFactory = implementationFactory;
         this.implementation = impl;
         this.osgiBundle = impl.getBundle();
     }
@@ -85,6 +90,7 @@
             int state = osgiBundle.getState();
             if ((state & Bundle.STARTING) == 0 && (state & Bundle.ACTIVE) == 0) {
                 osgiBundle.start();
+                startedByMe = true;
             }
         } catch (BundleException e) {
             throw new ServiceRuntimeException(e);
@@ -93,8 +99,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, "");
@@ -109,20 +115,39 @@
             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;
                         }
                     });
                 registrations.add(registration);
             }
         }
+        
+        // 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));
+            }
+        }
     }
 
     public void stop() {
@@ -134,13 +159,18 @@
             }
         }
         registrations.clear();
-        try {
-            int state = osgiBundle.getState();
-            if ((state & Bundle.STOPPING) == 0 && (state & Bundle.ACTIVE) != 0) {
-                osgiBundle.stop();
+        // [REVIEW] Shoud it take care of stopping the bundle?
+        if (startedByMe) {
+            try {
+                int state = osgiBundle.getState();
+                if ((state & Bundle.STOPPING) == 0 && (state & Bundle.ACTIVE) != 0) {
+                    osgiBundle.stop();
+                }
+            } catch (BundleException e) {
+                throw new ServiceRuntimeException(e);
+            } finally {
+                startedByMe = false;
             }
-        } catch (BundleException e) {
-            throw new ServiceRuntimeException(e);
         }
     }
 
@@ -165,24 +195,29 @@
     }
 
     protected Object getOSGiService(ComponentService service) {
+        BundleContext bundleContext = osgiBundle.getBundleContext();
+        ServiceReference ref = getServiceReference(bundleContext, service);
+        if (ref != null) {
+            Object instance = bundleContext.getService(ref);
+            return instance;
+        } else {
+            return null;
+        }
+    }
+
+    private ServiceReference getServiceReference(BundleContext bundleContext, ComponentService service) {
         JavaInterface javaInterface = (JavaInterface)service.getInterfaceContract().getInterface();
         // String filter = getOSGiFilter(provider.getOSGiProperties(service));
         // FIXME: What is the filter?
         String filter = "(!(" + SERVICE_IMPORTED + "=*))";
         // "(sca.service=" + component.getURI() + "#service-name\\(" + service.getName() + "\\))";
-        BundleContext bundleContext = osgiBundle.getBundleContext();
         ServiceReference ref;
         try {
             ref = bundleContext.getServiceReferences(javaInterface.getName(), filter)[0];
         } catch (InvalidSyntaxException e) {
             throw new ServiceRuntimeException(e);
         }
-        if (ref != null) {
-            Object instance = bundleContext.getService(ref);
-            return instance;
-        } else {
-            return null;
-        }
+        return ref;
     }
 
     RuntimeComponent getComponent() {

Modified: tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java Tue Nov  3 00:14:53 2009
@@ -19,8 +19,10 @@
 package org.apache.tuscany.sca.implementation.osgi.runtime;
 
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
 import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
 import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
 import org.apache.tuscany.sca.provider.ImplementationProvider;
 import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -32,20 +34,20 @@
  * @version $Rev$ $Date$
  */
 public class OSGiImplementationProviderFactory implements ImplementationProviderFactory<OSGiImplementation> {
-
+    private OSGiImplementationFactory implementationFactory;
     private ProxyFactoryExtensionPoint proxyFactoryExtensionPoint;
 
-    public OSGiImplementationProviderFactory(ExtensionPointRegistry extensionPoints) {
-        proxyFactoryExtensionPoint = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class);
+    public OSGiImplementationProviderFactory(ExtensionPointRegistry registry) {
+        proxyFactoryExtensionPoint = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class);
+        FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class);
+        this.implementationFactory = factoryExtensionPoint.getFactory(OSGiImplementationFactory.class);
     }
 
     public ImplementationProvider createImplementationProvider(RuntimeComponent component,
                                                                OSGiImplementation implementation) {
-
         try {
-
-            return new OSGiImplementationProvider(component, implementation, proxyFactoryExtensionPoint);
-
+            return new OSGiImplementationProvider(component, implementation, proxyFactoryExtensionPoint,
+                                                  implementationFactory);
         } catch (BundleException e) {
             throw new RuntimeException(e);
         }

Modified: tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java Tue Nov  3 00:14:53 2009
@@ -19,6 +19,10 @@
 
 package org.apache.tuscany.sca.implementation.osgi;
 
+import java.util.Collection;
+
+import org.osgi.framework.ServiceReference;
+
 /**
  * The factory interface to create OSGiImplementation instances
  */
@@ -34,4 +38,7 @@
      * @return
      */
     OSGiProperty createOSGiProperty();
+    OSGiProperty createOSGiProperty(String name, String stringValue, String type);
+    OSGiProperty createOSGiProperty(String name, Object value);
+    Collection<OSGiProperty> createOSGiProperties(ServiceReference reference); 
 }

Modified: tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java Tue Nov  3 00:14:53 2009
@@ -26,6 +26,8 @@
  */
 public interface OSGiProperty {
     String NAME = "name";
+    String TYPE = "type";
+    String VALUE = "value";
     QName PROPERTY_QNAME = new QName(OSGiImplementation.SCA11_TUSCANY_NS, "osgi.property");
 
     String REMOTE_CONFIG_SCA = "org.osgi.sca";
@@ -169,11 +171,16 @@
     public final String SERVICE_IMPORTED_CONFIGS = "service.imported.configs";
     
 
-    String getValue();
-
-    void setValue(String value);
+    Object getValue();
+    void setValue(Object value);
 
     String getName();
 
     void setName(String name);
+    
+    String getType();
+    void setType(String type);
+    
+    String getStringValue();
+    void setStringValue(String value);
 }

Modified: tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java Tue Nov  3 00:14:53 2009
@@ -19,10 +19,15 @@
 
 package org.apache.tuscany.sca.implementation.osgi.impl;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 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.osgi.framework.ServiceReference;
 
 /**
  * 
@@ -40,4 +45,72 @@
         return new OSGiPropertyImpl();
     }
 
+    public OSGiProperty createOSGiProperty(String propName, String propValue, String propType) {
+        OSGiProperty prop = new OSGiPropertyImpl();
+        if (propType == null) {
+            propType = "String";
+        }
+        prop.setName(propName);
+        prop.setStringValue(propValue);
+        prop.setType(propType);
+
+        Object value = propValue;
+        if ("Integer".equals(propType)) {
+            value = Integer.valueOf(propValue);
+        } else if ("Long".equals(propType)) {
+            value = Long.valueOf(propValue);
+        } else if ("Float".equals(propType)) {
+            value = Float.valueOf(propValue);
+        } else if ("Double".equals(propType)) {
+            value = Double.valueOf(propValue);
+        } else if ("Short".equals(propType)) {
+            value = Short.valueOf(propValue);
+        } else if ("Character".equals(propType)) {
+            value = propValue.charAt(0);
+        } else if ("Byte".equals(propType)) {
+            value = Byte.valueOf(propValue);
+        } else if ("Boolean".equals(propType)) {
+            value = Boolean.valueOf(propValue);
+        } else if ("String+".equals(propType)) {
+            value = propValue.split(" ");
+        } else {
+            // String
+            value = propValue;
+        }
+        prop.setValue(value);
+        return prop;
+    }
+
+    public OSGiProperty createOSGiProperty(String propName, Object value) {
+        OSGiProperty prop = new OSGiPropertyImpl();
+        prop.setName(propName);
+        prop.setValue(value);
+
+        if (value instanceof String[]) {
+            StringBuffer sb = new StringBuffer();
+            for (String s : (String[])value) {
+                sb.append(s).append(' ');
+            }
+            if (sb.length() > 0) {
+                sb.deleteCharAt(sb.length() - 1);
+            }
+            prop.setStringValue(sb.toString());
+            prop.setType("String+");
+        } else if (value != null) {
+            prop.setStringValue(String.valueOf(value));
+            prop.setType(value.getClass().getSimpleName());
+        }
+        return prop;
+    }
+    
+    public Collection<OSGiProperty> createOSGiProperties(ServiceReference reference) {
+        List<OSGiProperty> props = new ArrayList<OSGiProperty>();
+        for(String key: reference.getPropertyKeys()) {
+            Object value = reference.getProperty(key);
+            OSGiProperty prop = createOSGiProperty(key, value);
+            props.add(prop);
+        }
+        return props;
+    }        
+    
 }

Modified: tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java Tue Nov  3 00:14:53 2009
@@ -25,13 +25,15 @@
  * Implementation of OSGiProperty
  */
 public class OSGiPropertyImpl implements OSGiProperty {
+    private String name;
+    private String type;
+    private Object value;
+    private String stringValue;
+
     public OSGiPropertyImpl() {
         super();
     }
 
-    private String name;
-    private String value;
-
     public String getName() {
         return name;
     }
@@ -40,12 +42,28 @@
         this.name = name;
     }
 
-    public String getValue() {
+    public Object getValue() {
         return value;
     }
 
-    public void setValue(String value) {
+    public void setValue(Object value) {
         this.value = value;
     }
 
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getStringValue() {
+        return stringValue;
+    }
+
+    public void setStringValue(String stringValue) {
+        this.stringValue = stringValue;
+    }
+
 }

Modified: tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java Tue Nov  3 00:14:53 2009
@@ -23,6 +23,8 @@
 import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
 import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.NAME;
 import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.PROPERTY_QNAME;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.TYPE;
+import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.VALUE;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
@@ -57,14 +59,18 @@
                 case START_ELEMENT:
                     QName name = reader.getName();
                     if (PROPERTY_QNAME.equals(name)) {
-                        prop = factory.createOSGiProperty();
-                        prop.setName(reader.getAttributeValue(null, NAME));
-                        // After the following call, the reader will be positioned at END_ELEMENT
-                        String text = reader.getElementText();
-                        if (text != null) {
-                            text = text.trim();
+                        String propName = reader.getAttributeValue(null, NAME);
+                        String propValue = reader.getAttributeValue(null, VALUE);
+                        String propType = reader.getAttributeValue(null, TYPE);
+
+                        if (propValue == null) {
+                            propValue = reader.getElementText();
+                        }
+                        if (propValue != null) {
+                            propValue = propValue.trim();
                         }
-                        prop.setValue(text);
+
+                        prop = factory.createOSGiProperty(propName, propValue, propType);
                         return prop;
                     }
                     break;
@@ -90,7 +96,8 @@
     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.writeCharacters(model.getValue());
+        writer.writeAttribute(TYPE, model.getType());
+        writer.writeCharacters(model.getStringValue());
         writer.writeEndElement();
     }
 

Modified: tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java Tue Nov  3 00:14:53 2009
@@ -37,6 +37,7 @@
     protected EndpointIntrospector introspector;
     protected ServiceTracker discoveryTracker;
     protected String domainRegistry;
+    protected String domainURI;
 
     /**
      * @param context
@@ -45,6 +46,8 @@
      */
     protected AbstractOSGiServiceHandler(BundleContext context) {
         this.context = context;
+        this.domainRegistry = context.getProperty("org.osgi.sca.domain.registry");
+        this.domainURI = context.getProperty("org.osgi.sca.domain.uri");
     }
 
     protected ExtensionPointRegistry getExtensionPointRegistry() {
@@ -87,4 +90,8 @@
         this.domainRegistry = domainRegistry;
     }
 
+    public void setDomainURI(String domainURI) {
+        this.domainURI = domainURI;
+    }
+
 }

Modified: tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java Tue Nov  3 00:14:53 2009
@@ -23,9 +23,9 @@
 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;
 import org.apache.tuscany.sca.interfacedef.Interface;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
@@ -37,7 +37,6 @@
  * Implementation of {@link EndpointDescription}
  */
 public class EndpointHelper {
-    private final static String FRAMEWORK_UUID = "org.osgi.framework.uuid";
     private EndpointHelper() {
     }
 
@@ -54,11 +53,21 @@
     private static Map<String, Object> getProperties(BundleContext bundleContext, Endpoint endpoint) {
         Map<String, Object> props = new HashMap<String, Object>();
         
-        String uuid = getFrameworkUUID(bundleContext);
+        if (!endpoint.isRemote()) {
+            String uuid = OSGiHelper.getFrameworkUUID(bundleContext);
+            props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, uuid);
+        }
+        
+        for (Object ext : endpoint.getService().getExtensions()) {
+            if (ext instanceof OSGiProperty) {
+                OSGiProperty prop = (OSGiProperty)ext;
+                props.put(prop.getName(), prop.getStringValue());
+            }
+        }
         
-        props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, uuid);
+        props.put(RemoteConstants.SERVICE_REMOTE_ID, props.get(Constants.SERVICE_ID));
         props.put(RemoteConstants.SERVICE_REMOTE_URI, endpoint.getURI());
-        props.put(RemoteConstants.SERVICE_REMOTE_ID, String.valueOf(System.currentTimeMillis()));
+        // FIXME: [rfeng] How to pass in the remote service id from the endpoint XML
         props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, new String[] {"org.osgi.sca"});
         props.put(Endpoint.class.getName(), endpoint);
         List<String> interfaces = getInterfaces(endpoint);
@@ -66,15 +75,6 @@
         return props;
     }
 
-    public synchronized static String getFrameworkUUID(BundleContext bundleContext) {
-        String 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/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java Tue Nov  3 00:14:53 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/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java Tue Nov  3 00:14:53 2009
@@ -19,13 +19,20 @@
 
 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;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
+import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Filter;
@@ -36,6 +43,8 @@
  * 
  */
 public class OSGiHelper {
+    public final static String FRAMEWORK_UUID = "org.osgi.framework.uuid";
+
     private OSGiHelper() {
     }
 
@@ -131,5 +140,65 @@
         }
         return files;
     }
+    
+    public static Collection<OSGiProperty> getOSGiProperties(ExtensionPointRegistry registry, ServiceReference reference) {
+        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/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java Tue Nov  3 00:14:53 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;
@@ -70,14 +76,25 @@
                 if (domainRegistry != null) {
                     configuration.setDomainRegistryURI(domainRegistry);
                 }
+                if (domainURI != null) {
+                    configuration.setDomainURI(domainURI);
+                }
                 configuration.setURI(contribution.getURI());
                 configuration.getExtensions().add(reference.getBundle());
+                Component component = contribution.getDeployables().get(0).getComponents().get(0);
+                ComponentService service = component.getServices().get(0);
+                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));
                 node.start();
                 List<ExportRegistration> exportedServices = new ArrayList<ExportRegistration>();
-                Component component = contribution.getDeployables().get(0).getComponents().get(0);
-                ComponentService service = component.getServices().get(0);
                 for (Endpoint endpoint : service.getEndpoints()) {
                     EndpointDescription endpointDescription = createEndpointDescription(context, endpoint);
                     ExportRegistration exportRegistration =

Modified: tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java Tue Nov  3 00:14:53 2009
@@ -61,6 +61,9 @@
                 if (domainRegistry != null) {
                     configuration.setDomainRegistryURI(domainRegistry);
                 }
+                if (domainURI != null) {
+                    configuration.setDomainURI(domainURI);
+                }
                 configuration.setURI(contribution.getURI());
                 configuration.getExtensions().add(bundle);
                 // FIXME: Configure the domain and node URI

Modified: tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java Tue Nov  3 00:14:53 2009
@@ -276,9 +276,14 @@
             return;
         }
         String domainRegistry = (String)props.get("org.osgi.sca.domain.registry");
+        String domainURI = (String)props.get("org.osgi.sca.domain.uri");
         if (domainRegistry != null) {
             exporter.setDomainRegistry(domainRegistry);
             importer.setDomainRegistry(domainRegistry);
         }
+        if (domainURI != null) {
+            exporter.setDomainURI(domainURI);
+            importer.setDomainURI(domainURI);
+        }
     }
 }

Modified: tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java Tue Nov  3 00:14:53 2009
@@ -30,6 +30,7 @@
 import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
 import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
 import org.apache.tuscany.sca.runtime.EndpointListener;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -56,8 +57,13 @@
             return;
         }
 
-        OSGiImplementation osgiImpl = (OSGiImplementation)impl;
-        BundleContext bundleContext = osgiImpl.getBundle().getBundleContext();
+        BundleContext bundleContext = null;
+        // Remote endpoint doesn't have a bundle
+        if (!endpoint.isRemote()) {
+            OSGiImplementation osgiImpl = (OSGiImplementation)impl;
+            Bundle bundle = osgiImpl.getBundle();
+            bundleContext = bundle != null ? bundle.getBundleContext() : null;
+        }
 
         /*
         if (!endpoint.isRemote()) {
@@ -114,4 +120,5 @@
         props.put(SUPPORTED_PROTOCOLS, new String[] {"org.osgi.sca"});
         return props;
     }
+
 }

Modified: tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java Tue Nov  3 00:14:53 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());

Modified: tuscany/branches/sca-java-2.0-M4/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-2.0-M4/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java?rev=832215&r1=832214&r2=832215&view=diff
==============================================================================
--- tuscany/branches/sca-java-2.0-M4/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java (original)
+++ tuscany/branches/sca-java-2.0-M4/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java Tue Nov  3 00:14:53 2009
@@ -186,71 +186,7 @@
         try {
             if (injectedBundleContext == null) {
 
-                String version = getSystemProperty("java.specification.version");
-                
-                /**
-                 * [rfeng] I have to remove javax.transaction.* packages from the system bundle
-                 * See: http://www.mail-archive.com/dev@geronimo.apache.org/msg70761.html
-                 */
-                String profile = "J2SE-1.5.profile";
-                if (version.startsWith("1.6")) {
-                    profile = "JavaSE-1.6.profile";
-                }
-                Properties props = new Properties();
-                InputStream is = getClass().getResourceAsStream(profile);
-                if (is != null) {
-                    props.load(is);
-                    is.close();
-                }
-
-                props.putAll(getSystemProperties());
-
-                // Configure Eclipse properties
-
-                // Use the boot classloader as the parent classloader
-                put(props, PROP_OSGI_CONTEXT_CLASS_LOADER_PARENT, "app");
-
-                // Set startup properties
-                put(props, PROP_OSGI_CLEAN, "true");
-
-                // Set location properties
-                // FIXME Use proper locations
-                String tmpDir = getSystemProperty("java.io.tmpdir");
-                File root = new File(tmpDir);
-                // Add user name as the prefix. For multiple users on the same Lunix,
-                // there will be permission issue if one user creates the .tuscany folder
-                // first under /tmp with no write permission for others.
-                String userName = getSystemProperty(PROP_USER_NAME);
-                if (userName != null) {
-                    root = new File(root, userName);
-                }
-                root = new File(root, ".tuscany/equinox/" + UUID.randomUUID().toString());
-                if (logger.isLoggable(Level.FINE)) {
-                    logger.fine("Equinox location: " + root);
-                }
-
-                put(props, PROP_INSTANCE_AREA_DEFAULT, new File(root, "workspace").toURI().toString());
-                put(props, PROP_INSTALL_AREA, new File(root, "install").toURI().toString());
-                put(props, PROP_CONFIG_AREA_DEFAULT, new File(root, "config").toURI().toString());
-                put(props, PROP_USER_AREA_DEFAULT, new File(root, "user").toURI().toString());
-
-                // Test if the configuration/config.ini or osgi.bundles has been set
-                // If yes, try to avoid discovery of bundles
-                if (bundleLocations == null) {
-                    if (props.getProperty("osgi.bundles") != null) {
-                        bundleLocations = Collections.emptySet();
-                    } else {
-                        String config = props.getProperty(PROP_CONFIG_AREA);
-                        File ini = new File(config, "config.ini");
-                        if (ini.isFile()) {
-                            Properties iniProps = new Properties();
-                            iniProps.load(new FileInputStream(ini));
-                            if (iniProps.getProperty("osgi.bundles") != null) {
-                                bundleLocations = Collections.emptySet();
-                            }
-                        }
-                    }
-                }
+                Properties props = configureProperties();
                 startFramework(props);
 
             } else {
@@ -396,6 +332,75 @@
         }
     }
 
+    protected Properties configureProperties() throws IOException, FileNotFoundException {
+        String version = getSystemProperty("java.specification.version");
+        
+        /**
+         * [rfeng] I have to remove javax.transaction.* packages from the system bundle
+         * See: http://www.mail-archive.com/dev@geronimo.apache.org/msg70761.html
+         */
+        String profile = "J2SE-1.5.profile";
+        if (version.startsWith("1.6")) {
+            profile = "JavaSE-1.6.profile";
+        }
+        Properties props = new Properties();
+        InputStream is = getClass().getResourceAsStream(profile);
+        if (is != null) {
+            props.load(is);
+            is.close();
+        }
+
+        props.putAll(getSystemProperties());
+
+        // Configure Eclipse properties
+
+        // Use the boot classloader as the parent classloader
+        put(props, PROP_OSGI_CONTEXT_CLASS_LOADER_PARENT, "app");
+
+        // Set startup properties
+        put(props, PROP_OSGI_CLEAN, "true");
+
+        // Set location properties
+        // FIXME Use proper locations
+        String tmpDir = getSystemProperty("java.io.tmpdir");
+        File root = new File(tmpDir);
+        // Add user name as the prefix. For multiple users on the same Lunix,
+        // there will be permission issue if one user creates the .tuscany folder
+        // first under /tmp with no write permission for others.
+        String userName = getSystemProperty(PROP_USER_NAME);
+        if (userName != null) {
+            root = new File(root, userName);
+        }
+        root = new File(root, ".tuscany/equinox/" + UUID.randomUUID().toString());
+        if (logger.isLoggable(Level.FINE)) {
+            logger.fine("Equinox location: " + root);
+        }
+
+        put(props, PROP_INSTANCE_AREA_DEFAULT, new File(root, "workspace").toURI().toString());
+        put(props, PROP_INSTALL_AREA, new File(root, "install").toURI().toString());
+        put(props, PROP_CONFIG_AREA_DEFAULT, new File(root, "config").toURI().toString());
+        put(props, PROP_USER_AREA_DEFAULT, new File(root, "user").toURI().toString());
+
+        // Test if the configuration/config.ini or osgi.bundles has been set
+        // If yes, try to avoid discovery of bundles
+        if (bundleLocations == null) {
+            if (props.getProperty("osgi.bundles") != null) {
+                bundleLocations = Collections.emptySet();
+            } else {
+                String config = props.getProperty(PROP_CONFIG_AREA);
+                File ini = new File(config, "config.ini");
+                if (ini.isFile()) {
+                    Properties iniProps = new Properties();
+                    iniProps.load(new FileInputStream(ini));
+                    if (iniProps.getProperty("osgi.bundles") != null) {
+                        bundleLocations = Collections.emptySet();
+                    }
+                }
+            }
+        }
+        return props;
+    }
+
     private boolean isServiceProvider(Bundle bundle, Set<String> serviceProviders) {
         if (bundle != null) {
             String export = (String)bundle.getHeaders().get(Constants.EXPORT_PACKAGE);