tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r831468 - in /tuscany/java/sca: ./ distribution/all/ modules/core/META-INF/ modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ modules/endpoint-tribes/META-INF/ modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca...
Date Fri, 30 Oct 2009 22:10:13 GMT
Author: rfeng
Date: Fri Oct 30 22:10:11 2009
New Revision: 831468

URL: http://svn.apache.org/viewvc?rev=831468&view=rev
Log:
Propagate osgi properties for OSGi remote services 

Modified:
    tuscany/java/sca/distribution/all/pom.xml
    tuscany/java/sca/modules/core/META-INF/MANIFEST.MF
    tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
    tuscany/java/sca/modules/endpoint-tribes/META-INF/MANIFEST.MF
    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-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java
    tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java
    tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
    tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java
    tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.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/AbstractOSGiServiceHandler.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/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/remoteserviceadmin/impl/OSGiServiceImporter.java
    tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java
    tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java
    tuscany/java/sca/pom.xml

Modified: tuscany/java/sca/distribution/all/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/distribution/all/pom.xml?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/distribution/all/pom.xml (original)
+++ tuscany/java/sca/distribution/all/pom.xml Fri Oct 30 22:10:11 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/java/sca/modules/core/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/META-INF/MANIFEST.MF?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/META-INF/MANIFEST.MF (original)
+++ tuscany/java/sca/modules/core/META-INF/MANIFEST.MF Fri Oct 30 22:10:11 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/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java (original)
+++ tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java Fri Oct 30 22:10:11 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/java/sca/modules/endpoint-tribes/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/endpoint-tribes/META-INF/MANIFEST.MF?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/endpoint-tribes/META-INF/MANIFEST.MF (original)
+++ tuscany/java/sca/modules/endpoint-tribes/META-INF/MANIFEST.MF Fri Oct 30 22:10:11 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/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=831468&r1=831467&r2=831468&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 Fri Oct 30 22:10:11 2009
@@ -358,6 +358,7 @@
             logger.info(id + " Remote endpoint added: " + entry.getValue());
         }
         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=831468&r1=831467&r2=831468&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 Fri Oct 30 22:10:11 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;
@@ -65,12 +66,15 @@
     private Bundle osgiBundle;
     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();
     }
@@ -123,6 +127,14 @@
                 registrations.add(registration);
             }
         }
+        
+        // Set the OSGi service reference properties into the SCA service
+        for (ComponentService service : component.getServices()) {
+            ServiceReference serviceReference = getServiceReference(osgiBundle.getBundleContext(), service);
+            if (serviceReference != null) {
+                service.getExtensions().addAll(implementationFactory.createOSGiProperties(serviceReference));
+            }
+        }
     }
 
     public void stop() {
@@ -165,24 +177,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/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProviderFactory.java Fri Oct 30 22:10:11 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/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java (original)
+++ tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationFactory.java Fri Oct 30 22:10:11 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/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java (original)
+++ tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiProperty.java Fri Oct 30 22:10:11 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/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java (original)
+++ tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiImplementationFactoryImpl.java Fri Oct 30 22:10:11 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/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java (original)
+++ tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/impl/OSGiPropertyImpl.java Fri Oct 30 22:10:11 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/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=831468&r1=831467&r2=831468&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 Fri Oct 30 22:10:11 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.getName());
+        writer.writeCharacters(model.getStringValue());
         writer.writeEndElement();
     }
 

Modified: tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java (original)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java Fri Oct 30 22:10:11 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/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=831468&r1=831467&r2=831468&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 Fri Oct 30 22:10:11 2009
@@ -26,6 +26,7 @@
 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;
@@ -54,11 +55,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 = 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);
@@ -67,7 +78,12 @@
     }
 
     public synchronized static String getFrameworkUUID(BundleContext bundleContext) {
-        String uuid = System.getProperty(FRAMEWORK_UUID);
+        String uuid = null;
+        if (bundleContext != null) {
+            uuid = bundleContext.getProperty(FRAMEWORK_UUID);
+        } else {
+            uuid = System.getProperty(FRAMEWORK_UUID);
+        }
         if (uuid == null) {
             uuid = UUID.randomUUID().toString();
         }

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=831468&r1=831467&r2=831468&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 Fri Oct 30 22:10:11 2009
@@ -26,6 +26,10 @@
 import java.util.Enumeration;
 import java.util.HashSet;
 
+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;
@@ -131,5 +135,11 @@
         }
         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);
+    }    
 
 }

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=831468&r1=831467&r2=831468&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 Fri Oct 30 22:10:11 2009
@@ -70,14 +70,19 @@
                 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(OSGiHelper.getOSGiProperties(registry, reference));
+
                 // 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/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java (original)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceImporter.java Fri Oct 30 22:10:11 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/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java (original)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/RemoteServiceAdminImpl.java Fri Oct 30 22:10:11 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/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.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/DomainDiscoveryService.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java (original)
+++ tuscany/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java Fri Oct 30 22:10:11 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/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java Fri Oct 30 22:10:11 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);

Modified: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java Fri Oct 30 22:10:11 2009
@@ -23,8 +23,10 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
+import java.util.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -101,7 +103,28 @@
         if (factory == null) {
             return null;
         }
-        return factory.newFramework(properties);
+        String propertyFile = null;
+        String factoryName = factory.getClass().getName();
+        if (factoryName.startsWith("org.eclipse.osgi.")) {
+            propertyFile = "equinox.properties";
+        } else if (factoryName.startsWith("org.apache.felix.")) {
+            propertyFile = "felix.properties";
+        }
+        Map propMap = new HashMap();
+        if (propertyFile != null) {
+            InputStream is = getClass().getResourceAsStream(propertyFile);
+            if (is != null) {
+                Properties props = new Properties();
+                try {
+                    props.load(is);
+                } catch (IOException e) {
+                    logger.log(Level.WARNING, e.getMessage(), e);
+                }
+                propMap.putAll(props);
+            }
+        }
+        propMap.putAll(properties);
+        return factory.newFramework(propMap);
     }
 
     public boolean isEquinox() {
@@ -123,4 +146,109 @@
     public void stop(BundleContext context) throws Exception {
         EquinoxHost.injectedBundleContext = null;
     }
+
+    private static final String DELIM_START = "${";
+    private static final String DELIM_STOP = "}";
+
+    /**
+     * <p>
+     * This method performs property variable substitution on the
+     * specified value. If the specified value contains the syntax
+     * <tt>${&lt;prop-name&gt;}</tt>, where <tt>&lt;prop-name&gt;</tt>
+     * refers to either a configuration property or a system property,
+     * then the corresponding property value is substituted for the variable
+     * placeholder. Multiple variable placeholders may exist in the
+     * specified value as well as nested variable placeholders, which
+     * are substituted from inner most to outer most. Configuration
+     * properties override system properties.
+     * </p>
+     * @param val The string on which to perform property substitution.
+     * @param currentKey The key of the property being evaluated used to
+     *        detect cycles.
+     * @param cycleMap Map of variable references used to detect nested cycles.
+     * @param configProps Set of configuration properties.
+     * @return The value of the specified string after system property substitution.
+     * @throws IllegalArgumentException If there was a syntax error in the
+     *         property placeholder syntax or a recursive variable reference.
+    **/
+    public static String substVars(String val, String currentKey, Map cycleMap, Properties configProps)
+        throws IllegalArgumentException {
+        // If there is currently no cycle map, then create
+        // one for detecting cycles for this invocation.
+        if (cycleMap == null) {
+            cycleMap = new HashMap();
+        }
+
+        // Put the current key in the cycle map.
+        cycleMap.put(currentKey, currentKey);
+
+        // Assume we have a value that is something like:
+        // "leading ${foo.${bar}} middle ${baz} trailing"
+
+        // Find the first ending '}' variable delimiter, which
+        // will correspond to the first deepest nested variable
+        // placeholder.
+        int stopDelim = val.indexOf(DELIM_STOP);
+
+        // Find the matching starting "${" variable delimiter
+        // by looping until we find a start delimiter that is
+        // greater than the stop delimiter we have found.
+        int startDelim = val.indexOf(DELIM_START);
+        while (stopDelim >= 0) {
+            int idx = val.indexOf(DELIM_START, startDelim + DELIM_START.length());
+            if ((idx < 0) || (idx > stopDelim)) {
+                break;
+            } else if (idx < stopDelim) {
+                startDelim = idx;
+            }
+        }
+
+        // If we do not have a start or stop delimiter, then just
+        // return the existing value.
+        if ((startDelim < 0) && (stopDelim < 0)) {
+            return val;
+        }
+        // At this point, we found a stop delimiter without a start,
+        // so throw an exception.
+        else if (((startDelim < 0) || (startDelim > stopDelim)) && (stopDelim >= 0)) {
+            throw new IllegalArgumentException("stop delimiter with no start delimiter: " + val);
+        }
+
+        // At this point, we have found a variable placeholder so
+        // we must perform a variable substitution on it.
+        // Using the start and stop delimiter indices, extract
+        // the first, deepest nested variable placeholder.
+        String variable = val.substring(startDelim + DELIM_START.length(), stopDelim);
+
+        // Verify that this is not a recursive variable reference.
+        if (cycleMap.get(variable) != null) {
+            throw new IllegalArgumentException("recursive variable reference: " + variable);
+        }
+
+        // Get the value of the deepest nested variable placeholder.
+        // Try to configuration properties first.
+        String substValue = (configProps != null) ? configProps.getProperty(variable, null) : null;
+        if (substValue == null) {
+            // Ignore unknown property values.
+            substValue = System.getProperty(variable, "");
+        }
+
+        // Remove the found variable from the cycle map, since
+        // it may appear more than once in the value and we don't
+        // want such situations to appear as a recursive reference.
+        cycleMap.remove(variable);
+
+        // Append the leading characters, the substituted value of
+        // the variable, and the trailing characters to get the new
+        // value.
+        val = val.substring(0, startDelim) + substValue + val.substring(stopDelim + DELIM_STOP.length(), val.length());
+
+        // Now perform substitution again, since there could still
+        // be substitutions to make.
+        val = substVars(val, currentKey, cycleMap, configProps);
+
+        // Return the value.
+        return val;
+    }
+
 }

Modified: tuscany/java/sca/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/pom.xml?rev=831468&r1=831467&r2=831468&view=diff
==============================================================================
--- tuscany/java/sca/pom.xml (original)
+++ tuscany/java/sca/pom.xml Fri Oct 30 22:10:11 2009
@@ -340,7 +340,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> 
                        <extensions>true</extensions> 
                     </plugin>
                     <plugin>



Mime
View raw message