tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r549122 [1/2] - in /incubator/tuscany/java/sca/modules/implementation-osgi: ./ src/main/java/org/apache/tuscany/implementation/ src/main/java/org/apache/tuscany/implementation/osgi/ src/main/java/org/apache/tuscany/implementation/osgi/conte...
Date Wed, 20 Jun 2007 14:58:26 GMT
Author: antelder
Date: Wed Jun 20 07:58:18 2007
New Revision: 549122

URL: http://svn.apache.org/viewvc?view=rev&rev=549122
Log:
TUSCANY-1363, implementation-osgi contributed by Rajini Sivaram

Added:
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/OSGiImplementationInterface.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/context/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/context/OSGiPropertyValueObjectFactory.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProvider.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProviderFactory.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiInstanceWrapper.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiPassByValueInvoker.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiTargetInvoker.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/module/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/module/OSGiModuleActivator.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/EquinoxRuntime.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/FelixRuntime.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/KnopflerfishRuntime.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/OSGiRuntime.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/xml/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/xml/OSGiImplementation.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/xml/OSGiImplementationProcessor.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/invocation/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/invocation/OSGiTestCase.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/runtime/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/runtime/OSGiRuntimeTestCase.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/test/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/test/OSGiTestBundles.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/test/OSGiTestImpl.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/test/OSGiTestInterface.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/xml/
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/xml/OSGiReadImplTestCase.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/implementation/osgi/xml/TestModelResolver.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType   (with props)
    incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite
Modified:
    incubator/tuscany/java/sca/modules/implementation-osgi/pom.xml
    incubator/tuscany/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator

Modified: incubator/tuscany/java/sca/modules/implementation-osgi/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/pom.xml?view=diff&rev=549122&r1=549121&r2=549122
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/pom.xml Wed Jun 20 07:58:18 2007
@@ -30,11 +30,71 @@
     <artifactId>tuscany-implementation-osgi</artifactId>
     <name>Apache Tuscany Implementation OSGi</name>
 
+    <repositories>
+       <!-- for felix snapshots -->
+       <repository>
+          <id>apache.snapshots</id>
+          <url>http://people.apache.org/repo/m2-snapshot-repository</url>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+       </repository>
+    </repositories>
+
     <dependencies>
 
         <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.main</artifactId>
+            <version>0.9.0-incubator-SNAPSHOT</version>
+        </dependency>
+
+
+        <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-host-embedded</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>sca-api</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>        
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-core</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-interface</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>       
+         
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-interface-java</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>     
+           
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-interface-java-xml</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>       
+         
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-assembly-xml</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>        
+        
+	    <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-databinding</artifactId>
             <version>1.0-incubating-SNAPSHOT</version>
         </dependency>
 

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/OSGiImplementationInterface.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/OSGiImplementationInterface.java?view=auto&rev=549122
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/OSGiImplementationInterface.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/OSGiImplementationInterface.java Wed Jun 20 07:58:18 2007
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.implementation.osgi;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.scope.Scope;
+
+/**
+ * 
+ * The model representing an OSGi implementation in an SCA assembly model.
+ *
+ */
+public interface OSGiImplementationInterface extends Implementation {
+    
+    public String getBundleName();
+    
+    public String getBundleLocation();
+
+    
+    public String[] getImports();
+    
+    
+    public Scope getScope();
+    
+    public List<ComponentProperty> getReferenceProperties(String referenceName);
+    
+    public List<ComponentProperty> getServiceProperties(String serviceName);
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/OSGiImplementationInterface.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/OSGiImplementationInterface.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/context/OSGiPropertyValueObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/context/OSGiPropertyValueObjectFactory.java?view=auto&rev=549122
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/context/OSGiPropertyValueObjectFactory.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/context/OSGiPropertyValueObjectFactory.java Wed Jun 20 07:58:18 2007
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.implementation.osgi.context;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.SimpleTypeMapper;
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sca.factory.ObjectCreationException;
+import org.apache.tuscany.sca.factory.ObjectFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * 
+ * Process properties and create property values.
+ * 
+ * This code has been copied from the Java implementation to avoid dependencies on the Java implementation.
+ *
+ */
+public class OSGiPropertyValueObjectFactory {
+    protected SimpleTypeMapper simpleTypeMapper = new SimpleTypeMapperImpl();
+    boolean isSimpleType;
+    
+    
+    public OSGiPropertyValueObjectFactory() {
+    }
+    
+    public OSGiPropertyValueObjectFactory(Mediator mediator) {
+    }
+    
+    public ObjectFactory createValueFactory(Property property, Object propertyValue) {
+        
+        Class javaType = SimpleTypeMapperImpl.getJavaType(property.getXSDType());
+        isSimpleType = isSimpleType(property);
+        Document doc = (Document)propertyValue;
+        Element rootElement = doc.getDocumentElement();
+        if (property.isMany()) {
+            if (isSimpleType) {
+                String value = "";
+                if (rootElement.getChildNodes().getLength() > 0) {
+                    value = rootElement.getChildNodes().item(0).getTextContent();
+                }
+                List<String> values = 
+                    getSimplePropertyValues(value, javaType);
+                return new ListObjectFactoryImpl(property, 
+                                                 values,
+                                                 isSimpleType,
+                                                 javaType);
+            } else {
+                return new ListObjectFactoryImpl(property,
+                                                 getComplexPropertyValues(doc),
+                                                 isSimpleType,
+                                                 javaType);
+            }
+        } else {
+            if (isSimpleType) {
+                String value = "";
+                if (rootElement.getChildNodes().getLength() > 0) {
+                    value = rootElement.getChildNodes().item(0).getTextContent();
+                }
+                return new ObjectFactoryImpl(property,
+                                             value,
+                                             isSimpleType,
+                                             javaType);
+            } else {
+                Object value = getComplexPropertyValues(doc).get(0);
+                return new ObjectFactoryImpl(property,
+                                             value,
+                                             isSimpleType,
+                                             javaType);
+            }
+            
+        }
+    }
+    
+    private boolean isSimpleType(Property property) {
+        if (property.getXSDType() != null) {
+            return SimpleTypeMapperImpl.isSimpleXSDType(property.getXSDType());
+        } else {
+            if (property instanceof Document) {
+                Document doc = (Document)property;
+                Element element = doc.getDocumentElement(); 
+                if (element.getChildNodes().getLength() == 1 && 
+                    element.getChildNodes().item(0).getNodeType() == Element.TEXT_NODE) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+    
+    private List<String> getSimplePropertyValues(String concatenatedValue, Class javaType) {
+        List<String> propValues = new ArrayList<String>();
+        StringTokenizer st = null;
+        if ( javaType.getName().equals("java.lang.String")) {
+            st = new StringTokenizer(concatenatedValue, "\"");
+        } else {
+            st = new StringTokenizer(concatenatedValue);
+        }
+        String aToken = null;
+        while (st.hasMoreTokens()) {
+            aToken = st.nextToken();
+            if (aToken.trim().length() > 0) {
+                propValues.add(aToken);
+            }
+        }
+        return propValues;
+    }
+    
+    private List<Node> getComplexPropertyValues(Document document) {
+        Element rootElement = document.getDocumentElement();
+        List<Node> propValues = new ArrayList<Node>();
+        for (int count = 0 ; count < rootElement.getChildNodes().getLength() ; ++count) {
+            if (rootElement.getChildNodes().item(count).getNodeType() == Document.ELEMENT_NODE) {
+                propValues.add(rootElement.getChildNodes().item(count));
+            }
+        }
+        return propValues;
+    }
+    
+    public abstract class ObjectFactoryImplBase  implements ObjectFactory {
+        protected SimpleTypeMapper simpleTypeMapper = new SimpleTypeMapperImpl();
+        protected Property property;
+        protected Object propertyValue;
+        protected Class javaType;
+        protected DataType<XMLType> sourceDataType;
+        protected DataType<?> targetDataType;
+        boolean isSimpleType;
+
+        public ObjectFactoryImplBase(Property property, Object propertyValue, boolean isSimpleType, Class javaType)  {
+            this.isSimpleType = isSimpleType;
+            this.property = property;
+            this.propertyValue = propertyValue;
+            this.javaType = javaType;
+            sourceDataType =
+                new DataTypeImpl<XMLType>(DOMDataBinding.NAME, Node.class, 
+                    new XMLType(null, this.property.getXSDType()));
+            TypeInfo typeInfo = null;
+            if (this.property.getXSDType() != null) {
+                if (SimpleTypeMapperImpl.isSimpleXSDType(this.property.getXSDType())) {
+                    typeInfo = new TypeInfo(property.getXSDType(), true, null);
+                } else {
+                    typeInfo = new TypeInfo(property.getXSDType(), false, null);
+                }
+            } else {
+                typeInfo = new TypeInfo(property.getXSDType(), false, null);
+            }
+
+            XMLType xmlType = new XMLType(typeInfo);
+            String dataBinding = null; //(String)property.getExtensions().get(DataBinding.class.getName());
+            if (dataBinding != null) {
+                targetDataType = new DataTypeImpl<XMLType>(dataBinding, javaType, xmlType);
+            } else {
+                targetDataType = new DataTypeImpl<XMLType>(dataBinding, javaType, xmlType);
+            }
+        }
+    }
+    
+    public class ObjectFactoryImpl extends ObjectFactoryImplBase {
+        public ObjectFactoryImpl(Property property, Object propertyValue, boolean isSimpleType, Class javaType) {
+            super(property, propertyValue, isSimpleType, javaType);
+        }
+
+        @SuppressWarnings("unchecked")
+        public Object getInstance() throws ObjectCreationException {
+            if (isSimpleType) {
+                return simpleTypeMapper.toJavaObject(property.getXSDType(), (String)propertyValue, null);
+            } else {
+                return null;
+            }
+        }
+    }
+
+    public class ListObjectFactoryImpl extends ObjectFactoryImplBase  {
+        public ListObjectFactoryImpl(Property property, List<?>propertyValues, boolean isSimpleType, Class javaType) {
+            super(property, propertyValues, isSimpleType, javaType);
+        }
+
+        @SuppressWarnings("unchecked")
+        public List<?> getInstance() throws ObjectCreationException {
+            if (isSimpleType) {
+                List<Object> values = new ArrayList<Object>();
+                for (String aValue : (List<String>)propertyValue) {
+                    values.add(simpleTypeMapper.toJavaObject(property.getXSDType(), aValue, null));
+                }
+                return values;
+            } else {
+                List instances = new ArrayList();
+                for (Node aValue : (List<Node>)propertyValue) {
+                    instances.add(aValue);
+                }
+                return instances;
+            }
+        }
+    }
+}
+      

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/context/OSGiPropertyValueObjectFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/context/OSGiPropertyValueObjectFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProvider.java?view=auto&rev=549122
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProvider.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProvider.java Wed Jun 20 07:58:18 2007
@@ -0,0 +1,856 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.implementation.osgi.invocation;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+
+import org.apache.tuscany.implementation.osgi.OSGiImplementationInterface;
+import org.apache.tuscany.implementation.osgi.context.OSGiPropertyValueObjectFactory;
+import org.apache.tuscany.implementation.osgi.runtime.OSGiRuntime;
+import org.apache.tuscany.implementation.osgi.xml.OSGiImplementation;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.core.invocation.JDKProxyService;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.factory.ObjectCreationException;
+import org.apache.tuscany.sca.factory.ObjectFactory;
+import org.apache.tuscany.sca.scope.Scope;
+import org.apache.tuscany.sca.scope.InstanceWrapper;
+import org.apache.tuscany.sca.scope.ScopedImplementationProvider;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osoa.sca.annotations.AllowsPassByReference;
+
+/**
+ * The runtime instantiation of OSGi component implementations
+ * 
+ */
+public class OSGiImplementationProvider  implements ScopedImplementationProvider {
+	
+	private static final String COMPONENT_NAME = "component.name";
+	private static final String REFERENCE_NAME = "reference.name";
+  
+	private OSGiImplementation implementation;
+    private BundleContext bundleContext;
+    
+    private Hashtable<RuntimeWire, Reference> referenceWires = new Hashtable<RuntimeWire,Reference>();
+    private Hashtable<RuntimeWire, ComponentReference> componentReferenceWires 
+                       = new Hashtable<RuntimeWire,ComponentReference>();
+    private HashSet<RuntimeWire> resolvedWires = new HashSet<RuntimeWire>();   
+    private boolean wiresResolved;
+    
+
+    private Hashtable<String, Object> componentProperties = new Hashtable<String, Object>();
+    private RuntimeComponent runtimeComponent;
+    
+    private Bundle osgiBundle;
+    private OSGiServiceListener osgiServiceListener;
+    private PackageAdmin packageAdmin;
+    
+    
+    private DataBindingExtensionPoint dataBindingRegistry;
+    
+
+    public OSGiImplementationProvider(RuntimeComponent definition,
+            OSGiImplementationInterface impl,
+            DataBindingExtensionPoint dataBindingRegistry) throws BundleException {
+    	
+    	
+        this.implementation = (OSGiImplementation)impl;
+        this.runtimeComponent = definition;
+        this.dataBindingRegistry = dataBindingRegistry;
+
+        bundleContext = getBundleContext();
+        osgiBundle = installBundle();
+        
+        // Install and start all dependent  bundles
+        String[] imports = implementation.getImports();
+        ArrayList<Bundle>bundles = new ArrayList<Bundle>();
+        for (int i = 0; i < imports.length; i++) {
+        	String location = imports[i].trim();
+        	if (location.length() > 0) {
+        		Bundle bundle = bundleContext.installBundle(location);
+        		bundles.add(bundle);
+        	}        		
+        }
+        for (int i = 0; i < bundles.size(); i++) {
+        	bundles.get(i).start();
+        }
+        
+        // PackageAdmin is used to resolve bundles 
+        org.osgi.framework.ServiceReference packageAdminReference = 
+            bundleContext.getServiceReference("org.osgi.service.packageadmin.PackageAdmin");
+        if (packageAdminReference != null) {
+            packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminReference);
+        }
+        
+    }
+    
+    protected RuntimeComponent getRuntimeComponent() {
+    	return runtimeComponent;
+    }
+    
+    protected OSGiImplementation getImplementation() {
+    	return implementation;
+    }
+    
+    // Create a property table from the list of properties 
+    // The source properties are properties read from <property/> elements
+    // Create property values in the table of the appropriate class based 
+    // on the property type specified.
+    private void processProperties(List<?> props, Hashtable<String, Object> propsTable) {
+        
+        OSGiPropertyValueObjectFactory factory = new OSGiPropertyValueObjectFactory();
+        if (props != null) {
+            for (Object p : props) {
+             
+                Property prop = (Property)p;
+                ObjectFactory<?> objFactory = factory.createValueFactory(prop, prop.getValue());
+                Object value = objFactory.getInstance();           
+
+                propsTable.put(prop.getName(), value);
+            }
+        }
+    }
+
+   
+    private BundleContext getBundleContext() throws BundleException {
+
+    	if (bundleContext == null)
+    		bundleContext = OSGiRuntime.startAndGetBundleContext();   	
+		
+        return bundleContext;
+    }
+    
+    private Bundle getBundle() throws Exception {
+    	
+    	Bundle[] bundles = bundleContext.getBundles();
+        for (Bundle b : bundles) {
+        	if (b.getLocation().equals(implementation.getBundleName())) {
+        		return b;
+        	}
+        }
+        return null;
+    }
+
+    
+    // Install the bundle corresponding to this component.
+    private Bundle installBundle() throws ObjectCreationException {
+    	try {
+    		
+    		Bundle bundle = null;
+            
+            if ((bundle = getBundle()) == null) {
+               
+                String bundleName = implementation.getBundleLocation();
+            	            	
+			    bundle = bundleContext.installBundle(bundleName);
+				
+            }          
+
+			osgiServiceListener = new OSGiServiceListener(bundle);
+			
+			bundleContext.addServiceListener(osgiServiceListener);	
+
+			return bundle;
+			
+		} catch (Exception e) {
+			throw new ObjectCreationException(e);
+		}
+    }
+    
+    private String getOSGiFilter(ComponentService service) {
+        
+        String filter = "";
+        Hashtable<String, Object> props = new Hashtable<String, Object>();
+        processProperties(implementation.getServiceProperties(service.getName()), props);
+        
+        if (props != null && props.size() > 0) {
+            for (String propName : props.keySet()) {
+                filter = filter + "(" + propName + "=" + props.get(propName)  + ")";
+            }
+    
+            if (props.size() > 1) filter = "(&" + filter + ")";
+        }
+        else
+            filter = null;
+        return filter;
+    }
+    
+    /*
+     * Return a matching service registered by the specified bundle.
+     * If <implementation.osgi /> has the attribute filter defined, return a service
+     * reference that matches the filter. Otherwise, return a service which has a component
+     * name equal to this component's name. If not found, return a service which no
+     * component name set.
+     * 
+     * Even though services registered by this bundle can be filtered using the
+     * service listener, we use this method to filter all service references so that 
+     * the service matching functionality of OSGi can be directly used.
+     */
+    private org.osgi.framework.ServiceReference getOSGiServiceReference(Bundle bundle, 
+            String serviceName, String filter) 
+        throws InvalidSyntaxException {
+    	
+        if (filter != null && filter.length() > 0) {
+    	   org.osgi.framework.ServiceReference[] references = 
+   			    bundleContext.getServiceReferences(serviceName, filter);
+    	   
+    	   if (references != null) {
+    		   for (org.osgi.framework.ServiceReference ref : references) {
+    			   if (ref.getBundle() == bundle)
+    				   return ref;
+    		   }
+    	   }
+    	
+    	   return null;
+    	   
+        }
+    	
+    	filter = "(" + COMPONENT_NAME + "="+ runtimeComponent.getName() + ")";
+        
+		org.osgi.framework.ServiceReference[] references = 
+			bundleContext.getServiceReferences(serviceName, filter);
+		
+		if (references != null) {			
+			for (org.osgi.framework.ServiceReference ref : references) {
+ 			   if (ref.getBundle() == bundle)
+ 				   return ref;
+ 		    }
+		}
+		
+		references = bundleContext.getServiceReferences(serviceName, null);
+		
+		org.osgi.framework.ServiceReference reference = null;
+		
+		if (references != null) {
+		    for (org.osgi.framework.ServiceReference ref : references) {
+		    	
+		    	if (ref.getBundle() != bundle)
+		    		continue;
+			    Object compName = ref.getProperty(COMPONENT_NAME);
+			    if (compName == null && reference == null)
+			    	reference = ref;
+			    if (runtimeComponent.getName().equals(compName)) {
+				    reference = ref;
+				    break;
+			    }
+		    }
+		}
+		
+		return reference;
+    }
+    
+    protected void startBundle(final Bundle bundle) 
+            throws ObjectCreationException {
+
+        try {
+    
+            if (bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.STARTING) {
+        
+                setBundleProperties(runtimeComponent.getName());
+        
+                resolveBundle(bundle);
+            
+                if (bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.STARTING) {
+
+                    int retry = 0;
+                
+                    while (retry++ < 10) {
+                        try {
+                            bundle.start();
+                            break;
+                       } catch (BundleException e) {
+                            // It is possible that the thread "Refresh Packages" is in the process of
+                            // changing the state of this bundle. 
+                            Thread.yield();
+                        
+                            if (retry == 10)
+                            throw e;
+                        }
+                    }
+                }                   
+            }
+   
+        } catch (Exception e) {
+            throw new ObjectCreationException(e);
+        }
+    }
+    
+    
+    
+    protected org.osgi.framework.ServiceReference getOSGiServiceReference(final Bundle bundle, 
+            RuntimeComponentService service) 
+            throws ObjectCreationException {
+        
+    	try {
+    		
+            String filter = getOSGiFilter(service);
+            Interface serviceInterface = service.getInterfaceContract().getInterface();
+            String serviceInterfaceName = null;
+
+            org.osgi.framework.ServiceReference osgiServiceReference = null;
+            
+            if (serviceInterface instanceof JavaInterface) {
+                serviceInterfaceName = ((JavaInterface)serviceInterface).getJavaClass().getName();
+                                  
+    			if ((osgiServiceReference = getOSGiServiceReference(bundle, serviceInterfaceName, filter)) == null) {
+        			
+    				// The service listener for our bundle will notify us when the service is registered.
+    				synchronized (implementation) {							
+    					    					
+    					// When declarative services are used, the component is started asynchronously
+    					// So this thread has to wait for the service to be registered by the component
+    					// activate method
+    					// For regular bundle activators, bundle.start activates the bundle synchronously
+    					// and hence the service would probably have been started by the bundle activator
+    					while ((osgiServiceReference = getOSGiServiceReference(bundle, serviceInterfaceName, filter)) == null) {
+    		    							
+    					    // Wait for the bundle to register the service
+    				        implementation.wait(100);
+    					}
+    				}   
+                    
+    					
+        		}
+            }
+    			
+			
+    		
+    		
+    		return osgiServiceReference;
+    		
+		} catch (Exception e) {
+			throw new ObjectCreationException(e);
+		}
+    }
+    
+    
+    private Bundle installDummyBundle(Class<?> interfaceClass, boolean includeInterface)
+            throws Exception {
+        
+    	ByteArrayOutputStream out = new ByteArrayOutputStream();
+    	    	
+    	String EOL = "\n";
+    	
+    	String packageName = interfaceClass.getPackage().getName();
+    	String bundleName = interfaceClass.getName();
+    	
+    	
+    	String manifestStr = "Manifest-Version: 1.0" + EOL +
+						"Bundle-ManifestVersion: 2" + EOL +
+						"Bundle-Name: " + bundleName + EOL +
+						"Bundle-SymbolicName: " + bundleName + EOL +
+						"Bundle-Version: " + "1.0.0" + EOL +
+						"Bundle-Localization: plugin" + EOL;
+    	
+						
+    	StringBuilder manifestBuf = new StringBuilder();
+    	manifestBuf.append(manifestStr);
+    	manifestBuf.append("Export-Package: " + packageName + EOL);
+       
+    	ByteArrayInputStream manifestStream = new ByteArrayInputStream(manifestBuf.toString().getBytes());
+    	Manifest manifest = new Manifest();
+    	manifest.read(manifestStream);
+    	
+    	JarOutputStream jarOut = new JarOutputStream(out, manifest);
+    	
+        if (includeInterface) {
+    	    String interfaceClassName = interfaceClass.getName().replaceAll("\\.", "/") + ".class";
+    	
+    	    URL url = interfaceClass.getClassLoader().getResource(interfaceClassName);
+    	    String path = url.getPath();
+    	
+    	    ZipEntry ze = new ZipEntry(interfaceClassName);
+    
+    	    jarOut.putNextEntry(ze);
+    	    FileInputStream file = new FileInputStream(path);
+    	    byte[] fileContents = new byte[file.available()];
+    	    file.read(fileContents);
+            jarOut.write(fileContents);
+        
+            file.close();    	
+        }
+        
+    	jarOut.close();
+    	out.close();
+    	
+    	
+    	ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+        
+        
+        Bundle bundle = bundleContext.installBundle(
+                "file://" + interfaceClass.getName() + ".jar",
+        		in);
+        bundle.start();
+        
+        return bundle;
+        
+    }
+    
+    
+    
+    public InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException {
+    	
+        return new OSGiInstanceWrapper<Object>(this, bundleContext, osgiBundle);
+    }
+    
+   
+    
+    /*
+     * This method checks if the wires can be resolved, but it is not sufficient to check
+     * if proxies have been installed if necessary. Hence this has been replaced by a 
+     * simple check which guarantees that each wire gets processed once.
+     */
+    private boolean isWireResolved(String interfaceClassName, RuntimeWire wire) throws Exception {
+    	
+    	boolean wireResolved = false; 
+    	String componentName = null;
+        
+    	org.osgi.framework.ServiceReference[] refs = null;
+
+
+        if (wire.getTarget().getComponent() != null)
+            componentName = wire.getTarget().getComponent().getName();
+        
+    	// Properties specified in the reference element should be matched exactly
+    	// Target should be optionally matched against component.name
+    	// Reference name should be optionally matched against reference.name
+		ComponentReference scaRef = componentReferenceWires.get(wire);
+        
+		Hashtable<String, Object> props = new Hashtable<String, Object>();
+        processProperties(implementation.getReferenceProperties(scaRef.getName()), props);
+        
+		if (props.size() > 0) {
+			String filter = "";
+			
+			int numElements = 0;
+            // FIXME: Perhaps we should do a strict match using property type as well.
+            for (String propName : props.keySet()) {
+                if (propName.equals("component.name")) {
+                    componentName = (String)props.get(propName);
+                } else {
+                    filter = filter + "(" + propName + "=" + props.get(propName)  + ")";
+                    numElements++;
+                }
+            }
+
+			if (numElements > 1) filter = "(&" + filter + ")";
+			else if (numElements == 0) filter = null;
+			
+			refs = bundleContext.getServiceReferences(interfaceClassName, filter);
+			
+		} 
+		
+		if (refs != null) {
+    		for (org.osgi.framework.ServiceReference ref : refs) {
+   	    		Object refName = ref.getProperty(REFERENCE_NAME);
+   	    		Object compName = ref.getProperty(COMPONENT_NAME);
+			    if ((refName == null || refName.equals(scaRef.getName()))&&
+			    	(compName == null || compName.equals(componentName))){
+			    	
+			    	wireResolved = true;			   
+				    break;
+			    }
+			}
+    		
+    	}
+		return wireResolved;
+    }
+    
+    private  void resolveWireCreateDummyBundles(Bundle bundle, Class interfaceClass, RuntimeWire wire) throws Exception {
+        
+        
+        try {
+                    
+            bundle.loadClass(interfaceClass.getName());
+                            
+        } catch (ClassNotFoundException e) {
+                        
+            // The interface used by the proxy is not in the source bundle
+            // A dummy bundle needs to be installed to create the proxy
+                     
+            installDummyBundle(interfaceClass, true);
+                                
+            if (bundle.getState() == Bundle.INSTALLED && packageAdmin != null) {
+                                    
+                packageAdmin.resolveBundles(new Bundle[]{bundle});
+                              
+            } 
+
+        }
+    }
+    
+    /**
+     * For OSGi->Java wires, create a proxy corresponding to the Java interfaces
+     * and register the proxy with the OSGi registry, so that the source OSGi bundle can 
+     * locate the target Java instance from the registry like a regular OSGi service.
+     * 
+     * For OSGi->OSGi wires, start the target OSGi bundle, so that references of the
+     * target are resolved before the source OSGi bundle is started. If the reference
+     * has properties specified, create a Proxy and register a service with highest
+     * possible ranking. The Proxy should wire to the correct OSGi instance specified
+     * in the SCA composite.
+     * 
+     * The first phase determines whether a proxy should be installed. It also registers
+     * a dummy bundle if necessary to resolve the bundle. When phase1 is completed on all
+     * wires of the component, the bundle should be resolved. Phase2 registers the proxy service.
+     */
+    private boolean resolveWireResolveReferences(Bundle bundle, Class interfaceClass, RuntimeWire wire,
+            boolean isOSGiToOSGiWire) throws Exception {
+    	
+    	boolean createProxy = false;
+       
+	    ComponentReference scaRef = componentReferenceWires.get(wire);
+        Hashtable<String, Object> targetProperties = new Hashtable<String, Object>();
+        processProperties(implementation.getReferenceProperties(scaRef.getName()), targetProperties);
+            
+            
+		if (bundle.getState() != Bundle.ACTIVE) {
+
+			if (isOSGiToOSGiWire) {
+                    
+				OSGiImplementationProvider implProvider = (OSGiImplementationProvider)wire.getTarget().getComponent().getImplementationProvider();
+					
+				// This is an OSGi->OSGi wire
+				isOSGiToOSGiWire = true;
+					
+				// If the target component is stateless, use a proxy to create a new service each time 
+				if (!implProvider.getScope().equals(Scope.COMPOSITE)) createProxy = true;
+					
+				// If any of the operations in the target interface is non-blocking, create a proxy
+				List<Operation> ops = wire.getTarget().getInterfaceContract().getInterface().getOperations();
+				for (Operation op : ops) {
+					if (op.isNonBlocking())
+						createProxy = true;
+			    }
+                    
+                if (targetProperties.size() > 0) {
+                    createProxy = true;
+                }
+                    
+                    
+				// Since this is an OSGi->OSGi wire, start the target bundle before starting the
+				// source bundle if there is no proxy. For direct wiring without a proxy, this ordering 
+			    // is irrelevant in terms of class resolution, but the target needs to be started at some 
+				// point. But there is no opportunity later on to start the target OSGi bundle without a proxy.	
+				// When a Proxy is used, the target bundle needs to be resolved for the source bundle
+				// to be resolved so that the interface is visible to the source. In this case the bundle
+				// will be started when an instance is needed.					
+				if (!createProxy) {	
+					implProvider.startBundle(implProvider.osgiBundle);
+				}
+				else {
+					implProvider.resolveBundle(implProvider.osgiBundle);
+				}
+		    }
+            else {
+                createProxy = true;
+            }
+        }
+            
+        return createProxy;
+    }
+    
+    
+    // Register proxy service 
+    private void resolveWireRegisterProxyService(Bundle bundle, Class interfaceClass, RuntimeWire wire) throws Exception {
+          
+        ComponentReference scaRef = componentReferenceWires.get(wire);
+        Hashtable<String, Object> targetProperties = new Hashtable<String, Object>();
+        processProperties(implementation.getReferenceProperties(scaRef.getName()), targetProperties);
+        targetProperties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
+        
+        RuntimeComponent targetComponent = wire.getTarget().getComponent();
+        if (targetProperties.get(COMPONENT_NAME) == null && targetComponent != null)
+            targetProperties.put(COMPONENT_NAME, targetComponent.getName());
+        
+           
+        JDKProxyService proxyService = new JDKProxyService();
+              
+        Class<?> proxyInterface = bundle.loadClass(interfaceClass.getName());
+                
+
+        Object proxy = proxyService.createProxy(proxyInterface, wire);
+            
+        bundleContext.registerService(proxyInterface.getName(), proxy, targetProperties);
+            
+        
+    }
+    
+    
+    private void resolveBundle(Bundle bundle) throws ObjectCreationException {
+    	
+        
+		try {
+			
+			if (!wiresResolved) {
+            	wiresResolved = true;
+				    
+                boolean[] createProxyService = new boolean[referenceWires.size()];
+                Class<?>[] interfaceClasses = new Class<?>[referenceWires.size()] ;
+                boolean[] isOSGiToOSGiWire = new boolean[referenceWires.size()];
+                boolean[] wireResolved = new boolean[referenceWires.size()];
+                int index = 0;
+				for (RuntimeWire wire : referenceWires.keySet()) {
+				
+					Reference reference = referenceWires.get(wire);
+                    
+                    isOSGiToOSGiWire[index] = wire.getTarget().getComponent() != null &&
+                            wire.getTarget().getComponent().getImplementationProvider() 
+                            instanceof OSGiImplementationProvider;
+                            
+					Interface refInterface = reference.getInterfaceContract().getInterface();
+					if (refInterface instanceof JavaInterface) {
+						interfaceClasses[index] = ((JavaInterface)refInterface).getJavaClass();
+					
+                        if (!isOSGiToOSGiWire[index])
+                            resolveWireCreateDummyBundles(bundle, interfaceClasses[index], wire);
+
+					}
+                    if (interfaceClasses[index] != null &&
+                            !isWireResolved(interfaceClasses[index].getName(), wire)) {
+                        
+                        resolvedWires.add(wire);                       
+                    }
+                    else
+                        wireResolved[index] = true;
+                    
+                    index++;
+				}
+                
+                index = 0;
+                for (RuntimeWire wire : referenceWires.keySet()) {
+                    
+                    if (!wireResolved[index]) {
+                        createProxyService[index] = resolveWireResolveReferences(bundle, 
+                            interfaceClasses[index], 
+                            wire,
+                            isOSGiToOSGiWire[index]);
+                    }
+                    index++;
+                }
+                
+                index = 0;
+                for (RuntimeWire wire : referenceWires.keySet()) {
+                    
+                    if (createProxyService[index] && !wireResolved[index])
+                        resolveWireRegisterProxyService(bundle, interfaceClasses[index], wire);
+                    index++;
+                }
+            }
+            else if (bundle.getState() == Bundle.INSTALLED && packageAdmin != null) {
+                packageAdmin.resolveBundles(new Bundle[] {bundle});
+            }
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+			throw new ObjectCreationException(e);
+		} 		
+    }
+    
+   
+    
+    private void setBundleProperties(String pid) {
+    	   	
+    	try {
+
+    		if (componentProperties.size() == 0)
+    			return;
+    		
+			org.osgi.framework.ServiceReference configAdminReference = bundleContext.getServiceReference("org.osgi.service.cm.ConfigurationAdmin");
+			if (configAdminReference != null) {
+				
+				Object cm = bundleContext.getService(configAdminReference);
+				Class cmClass = cm.getClass().getClassLoader().loadClass("org.osgi.service.cm.ConfigurationAdmin");
+				Method m = cmClass.getMethod("getConfiguration", String.class, String.class);
+				
+				Object config = m.invoke(cm, pid, null);
+				Class configClass = cm.getClass().getClassLoader().loadClass("org.osgi.service.cm.Configuration");
+				
+				Method getMethod = configClass.getMethod("getProperties");
+				Dictionary props = (Dictionary)getMethod.invoke(config);
+				if (props == null)
+					props = new Hashtable<String, Object>();
+				
+				for (String propertyName : componentProperties.keySet()) {
+					props.put(propertyName, componentProperties.get(propertyName));
+				}
+				
+				Method updateMethod = configClass.getMethod("update", Dictionary.class);
+				updateMethod.invoke(config, props);
+				
+			}
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+
+	}
+
+    
+    public boolean isOptimizable() {
+        return false;
+    }
+    
+    public Scope getScope() {
+        return implementation.getScope();
+    }
+
+    public boolean isEagerInit() {
+        return implementation.isEagerInit();
+    }
+
+    public long getMaxAge() {
+        return implementation.getMaxAge();
+    }
+
+    public long getMaxIdleTime() {
+        return implementation.getMaxIdleTime();
+    }
+    
+    
+    public Invoker createTargetInvoker(RuntimeComponentService service, Operation operation)  {
+       
+        
+        Interface serviceInterface = operation.getInterface();
+        boolean passByValue = serviceInterface.isRemotable() && !implementation.isAllowsPassByReference(operation);
+
+
+        Invoker invoker = new OSGiTargetInvoker(operation, runtimeComponent, service);
+        if (passByValue) {
+            return new OSGiPassByValueInvoker(dataBindingRegistry, operation, runtimeComponent, service);
+        } else {
+            return invoker;
+        }
+        
+    }
+    
+    public Invoker createCallbackInvoker(Operation operation) {
+    	return createTargetInvoker(null, operation);
+	}
+
+	public Invoker createInvoker(RuntimeComponentService service, Operation operation) {
+		return createTargetInvoker(service, operation);
+	}
+
+	public void start() {
+        
+		
+		for (Reference ref: implementation.getReferences()) {
+			List<RuntimeWire> wireList = null;
+			ComponentReference compRef = null;
+            for (ComponentReference cRef : runtimeComponent.getReferences()) {
+                if (cRef.getName().equals(ref.getName())) {
+                    wireList = ((RuntimeComponentReference)cRef).getRuntimeWires();
+                    compRef = cRef;
+                    break;
+                }
+            }
+                
+            if (ref.getMultiplicity() == Multiplicity.ONE_N || ref.getMultiplicity() == Multiplicity.ZERO_N) {
+             	for (RuntimeWire wire : wireList) {
+                    referenceWires.put(wire, ref);
+                	componentReferenceWires.put(wire, compRef);
+                }
+                
+            } else {
+                if (wireList == null && ref.getMultiplicity() == Multiplicity.ONE_ONE) {
+                    throw new IllegalStateException("Required reference is missing: " + ref.getName());
+                }
+                if (wireList != null && !wireList.isEmpty()) {
+                    RuntimeWire wire = wireList.get(0);
+                    referenceWires.put(wire, ref);
+                    componentReferenceWires.put(wire, compRef);
+                }
+                
+            }
+			
+		}
+        
+        processProperties(implementation.getProperties(), componentProperties);
+		
+	}
+    
+    
+	public void stop() {
+        bundleContext.removeServiceListener(osgiServiceListener);
+	}
+
+    
+    private class OSGiServiceListener implements ServiceListener {
+    	
+    	private Bundle bundle;
+    	
+    	OSGiServiceListener(Bundle bundle) {
+    		this.bundle = bundle;
+    	}
+    	
+    	public void serviceChanged(org.osgi.framework.ServiceEvent event) {
+    		
+
+			org.osgi.framework.ServiceReference reference = event.getServiceReference();
+			
+			if (event.getType() == ServiceEvent.REGISTERED && reference.getBundle() == bundle) {
+				
+			    synchronized (implementation) {
+			    	
+					implementation.notifyAll();
+			    }
+			}
+			
+            if (event.getType() == ServiceEvent.UNREGISTERING && reference.getBundle() == bundle) {
+            	// TODO: Process deregistering of OSGi services.
+            }
+		}
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProviderFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProviderFactory.java?view=auto&rev=549122
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProviderFactory.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProviderFactory.java Wed Jun 20 07:58:18 2007
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.implementation.osgi.invocation;
+
+
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.implementation.osgi.OSGiImplementationInterface;
+import org.apache.tuscany.implementation.osgi.context.OSGiPropertyValueObjectFactory;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.osgi.framework.BundleException;
+
+
+/**
+ * Builds a OSGi-based implementation provider from a component definition
+ * 
+ */
+public class OSGiImplementationProviderFactory implements ImplementationProviderFactory<OSGiImplementationInterface> {
+	
+	
+	DataBindingExtensionPoint dataBindingRegistry;
+	
+	public OSGiImplementationProviderFactory(DataBindingExtensionPoint dataBindings,
+			OSGiPropertyValueObjectFactory factory) {
+		
+		dataBindingRegistry = dataBindings;
+		
+	}
+
+	public ImplementationProvider createImplementationProvider(RuntimeComponent component,
+            OSGiImplementationInterface implementation) {
+    			
+			try {
+				
+				return new OSGiImplementationProvider(component, implementation, dataBindingRegistry);
+				
+			} catch (BundleException e) {
+				throw new RuntimeException(e);
+			}
+		
+    }
+
+    public Class<OSGiImplementationInterface> getModelType() {
+        return OSGiImplementationInterface.class;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProviderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiImplementationProviderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiInstanceWrapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiInstanceWrapper.java?view=auto&rev=549122
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiInstanceWrapper.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiInstanceWrapper.java Wed Jun 20 07:58:18 2007
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.implementation.osgi.invocation;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.scope.InstanceWrapper;
+import org.apache.tuscany.sca.scope.TargetDestructionException;
+import org.apache.tuscany.sca.scope.TargetInitializationException;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+
+/**
+ * InstanceWrapper for creating instances for OSGi components. 
+ * This class needs to implement InstanceWrapper since the wrapper is stored in
+ * the scope container. But getInstance() is called on this wrapper only through the
+ * OSGi target invoker. OSGiTargetInvoker always invokes getInstance for a specific
+ * service since one OSGi SCA component can associate different objects with 
+ * different services (this is different from Java SCA components which always associate 
+ * a single component instance with multiple services).
+ * 
+ */
+public class OSGiInstanceWrapper<T> implements InstanceWrapper<T> {
+    
+    private OSGiImplementationProvider provider;
+    private Bundle bundle;
+    private BundleContext bundleContext;
+    private T osgiInstance;
+    private ServiceReference osgiServiceReference;
+
+    public OSGiInstanceWrapper(OSGiImplementationProvider provider, 
+            BundleContext bundleContext, 
+            Bundle bundle) {
+        
+        this.provider = provider;
+        this.bundleContext = bundleContext;
+        this.bundle = bundle;
+    }
+    
+    public T getInstance(RuntimeComponentService service) {
+
+        provider.startBundle(bundle);
+        osgiServiceReference = provider.getOSGiServiceReference(bundle, service);
+        
+        osgiInstance = (T)bundleContext.getService(osgiServiceReference);
+        
+        return osgiInstance;
+    }
+    
+    // This method is provided purely to implement InstanceWrapper interface, and is never called.
+    public T getInstance() {
+
+        return null;
+    }
+    
+    public void start() throws TargetInitializationException {
+        
+    }
+
+    public void stop() throws TargetDestructionException {
+        if (osgiInstance != null && osgiServiceReference != null) {
+            
+            bundleContext.ungetService(osgiServiceReference);
+            
+            osgiInstance = null;
+            osgiServiceReference = null;
+        }
+    }
+    
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiInstanceWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiInstanceWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiPassByValueInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiPassByValueInvoker.java?view=auto&rev=549122
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiPassByValueInvoker.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiPassByValueInvoker.java Wed Jun 20 07:58:18 2007
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.implementation.osgi.invocation;
+
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.databinding.DataBinding;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * An interceptor to enforce pass-by-value semantics for remotable interfaces
+ * 
+ */
+public class OSGiPassByValueInvoker extends OSGiTargetInvoker {
+    
+    private DataBindingExtensionPoint registry;
+    private Operation operation;
+
+    /**
+     * @param registry
+     * @param operation
+     * @param method
+     * @param component
+     */
+    public OSGiPassByValueInvoker(DataBindingExtensionPoint registry,
+                              Operation operation,
+                              RuntimeComponent component,
+                              RuntimeComponentService service) {
+        super(operation, component, service);
+        this.registry = registry;
+        this.operation = operation;
+    }
+
+    public Message invoke(Message msg) {
+        Object obj = msg.getBody();
+        msg.setBody(copy((Object[])obj));
+
+        Message result = super.invoke(msg);
+
+        if (!result.isFault() && operation.getOutputType() != null) {
+            String dataBindingId = operation.getOutputType().getDataBinding();
+            DataBinding dataBinding = registry.getDataBinding(dataBindingId);
+            result.setBody(copy(result.getBody(), dataBinding));
+        }
+        return result;
+    }
+
+    public Object[] copy(Object[] args) {
+        if (args == null) {
+            return null;
+        }
+        Object[] copiedArgs = new Object[args.length];
+        Map<Object, Object> map = new IdentityHashMap<Object, Object>();
+        for (int i = 0; i < args.length; i++) {
+            if (args[i] == null) {
+                copiedArgs[i] = null;
+            } else {
+                Object copiedArg = map.get(args[i]);
+                if (copiedArg != null) {
+                    copiedArgs[i] = copiedArg;
+                } else {
+                    String dataBindingId = operation.getInputType().getLogical().get(i).getDataBinding();
+                    DataBinding dataBinding = registry.getDataBinding(dataBindingId);
+                    copiedArg = copy(args[i], dataBinding);
+                    map.put(args[i], copiedArg);
+                    copiedArgs[i] = copiedArg;
+                }
+            }
+        }
+        return copiedArgs;
+    }
+
+    public Object copy(Object arg, DataBinding argDataBinding) {
+        if (arg == null) {
+            return null;
+        }
+        Object copiedArg;
+        if (argDataBinding != null) {
+            copiedArg = argDataBinding.copy(arg);
+        } else {
+            copiedArg = arg;
+            DataType<?> dataType = registry.introspectType(arg);
+            if (dataType != null) {
+                DataBinding binding = registry.getDataBinding(dataType.getDataBinding());
+                if (binding != null) {
+                    copiedArg = binding.copy(arg);
+                }
+            }
+            // FIXME: What to do if it's not recognized?
+        }
+        return copiedArg;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiPassByValueInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiPassByValueInvoker.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiTargetInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiTargetInvoker.java?view=auto&rev=549122
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiTargetInvoker.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiTargetInvoker.java Wed Jun 20 07:58:18 2007
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.implementation.osgi.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
+import org.apache.tuscany.sca.interfacedef.ConversationSequence;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.scope.Scope;
+import org.apache.tuscany.sca.scope.InstanceWrapper;
+import org.apache.tuscany.sca.scope.ScopeContainer;
+import org.apache.tuscany.sca.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.scope.TargetInvocationException;
+import org.apache.tuscany.sca.scope.TargetResolutionException;
+
+/**
+ * Java->OSGi references use OSGiTargetInvoker to call methods from OSGi bundles
+ * OSGi->Java references use JDKProxyService and invocation handler and do not use this class
+ * OSGi->OSGi references go through OSGi reference mechanisms when a proxy is not used
+ *    When a proxy is used, this invoker is used to call methods from OSGi bundles
+ *    A proxy is used for OSGi->OSGi if
+ *       1) target reference properties are specified  OR
+ *       2) there are one or more non-blocking methods in the target interface OR
+ *       3) scope is not COMPOSITE
+ */
+public class OSGiTargetInvoker<T> implements Invoker {
+    
+    private Operation operation;
+    protected InstanceWrapper<T> target;
+    protected boolean stateless;
+    protected boolean cacheable;
+
+    private final RuntimeComponentService service;
+    private final RuntimeComponent component;
+    private final ScopeContainer scopeContainer;
+
+    public OSGiTargetInvoker(Operation operation, RuntimeComponent component, RuntimeComponentService service) {
+    	
+    	this.operation = operation;
+		this.component = component;
+        this.service = service;
+        this.scopeContainer = ((ScopedRuntimeComponent) component).getScopeContainer();
+        this.cacheable = true;
+        stateless = Scope.STATELESS == scopeContainer.getScope();
+
+    }
+
+    /**
+     * Resolves the target service instance or returns a cached one
+     */
+    protected InstanceWrapper getInstance(ConversationSequence sequence, Object contextId)
+        throws TargetResolutionException, TargetInvocationException {
+    	
+        if (sequence == null) {
+            if (cacheable) {
+                if (target == null) {
+                    target = scopeContainer.getWrapper(contextId);
+                }
+                return target;
+            } else {
+                return scopeContainer.getWrapper(contextId);
+            }
+        } else {
+            switch (sequence) {
+            case CONVERSATION_START:
+                assert !cacheable;
+                return scopeContainer.getWrapper(contextId);
+            case CONVERSATION_CONTINUE:
+            case CONVERSATION_END:
+                assert !cacheable;
+                return scopeContainer.getAssociatedWrapper(contextId);
+            default:
+                throw new TargetInvocationException("Unknown sequence type: " + String.valueOf(sequence));
+            }
+        }
+    }
+
+    
+    public Object invokeTarget(final Object payload, final ConversationSequence sequence)
+        throws InvocationTargetException {
+
+    
+        Object contextId = ThreadMessageContext.getMessageContext().getConversationID();
+        try {
+            OSGiInstanceWrapper wrapper = (OSGiInstanceWrapper)getInstance(sequence, contextId);
+            Object instance = wrapper.getInstance(service);
+            Object ret;
+        
+            Method m = JavaInterfaceUtil.findMethod(instance.getClass(), operation);
+		
+            if (payload != null && !payload.getClass().isArray()) {
+                ret = m.invoke(instance, payload);
+            } else {
+                ret = m.invoke(instance, (Object[])payload);
+            }
+            scopeContainer.returnWrapper(wrapper, contextId);
+            if (sequence == ConversationSequence.CONVERSATION_END) {
+                // if end conversation, remove resource
+                scopeContainer.remove();
+            }
+            return ret;
+        } catch (InvocationTargetException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new InvocationTargetException(e);
+        }
+    }
+    
+    
+    public Message invoke(Message msg) {
+        try {
+            Object messageId = msg.getMessageID();
+            Message workContext = ThreadMessageContext.getMessageContext();
+            if (messageId != null) {
+                workContext.setCorrelationID(messageId);
+            }
+            Object resp = invokeTarget(msg.getBody(), msg.getConversationSequence());
+            msg.setBody(resp);
+        } catch (InvocationTargetException e) {
+            msg.setFaultBody(e.getCause());
+        }
+        return msg;
+    }
+
+    public boolean isCacheable() {
+        return cacheable;
+    }
+
+    public void setCacheable(boolean cacheable) {
+        this.cacheable = cacheable;
+    }
+
+    protected InvocationChain getInvocationChain(List<InvocationChain> chains, Operation targetOperation) {
+        for (InvocationChain chain : chains) {
+            if (chain.getTargetOperation().equals(targetOperation)) {
+                return chain;
+            }
+        }
+        return null;
+    }
+    
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiTargetInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/invocation/OSGiTargetInvoker.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/module/OSGiModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/module/OSGiModuleActivator.java?view=auto&rev=549122
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/module/OSGiModuleActivator.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/module/OSGiModuleActivator.java Wed Jun 20 07:58:18 2007
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.implementation.osgi.module;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.TransformerExtensionPoint;
+import org.apache.tuscany.sca.databinding.impl.MediatorImpl;
+import org.apache.tuscany.implementation.osgi.context.OSGiPropertyValueObjectFactory;
+import org.apache.tuscany.implementation.osgi.invocation.OSGiImplementationProviderFactory;
+import org.apache.tuscany.implementation.osgi.xml.OSGiImplementationProcessor;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+
+/**
+ * Module activator for OSGi implementation type
+ * 
+ * Registers OSGiImplementationProcessor and OSGiImplementationProviderFactory
+ */
+public class OSGiModuleActivator implements ModuleActivator {
+
+    public OSGiModuleActivator() {
+    }
+
+    public void start(ExtensionPointRegistry registry) {
+    	
+    	StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+        
+        ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+        AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class);
+        PolicyFactory policyFactory = factories.getFactory(PolicyFactory.class);
+        
+        JavaInterfaceFactory javaInterfaceFactory = new DefaultJavaInterfaceFactory();
+        JavaInterfaceIntrospectorExtensionPoint interfaceVisitors = 
+            registry.getExtensionPoint(JavaInterfaceIntrospectorExtensionPoint.class);
+        JavaInterfaceIntrospector interfaceIntrospector = 
+            new ExtensibleJavaInterfaceIntrospector(javaInterfaceFactory, interfaceVisitors);
+
+        OSGiImplementationProcessor implementationLoader = new OSGiImplementationProcessor(
+                interfaceIntrospector, 
+                javaInterfaceFactory, 
+                assemblyFactory,
+                policyFactory);
+        
+        processors.addArtifactProcessor(implementationLoader);
+        
+        DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class);
+        TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class);
+        MediatorImpl mediator =new MediatorImpl(dataBindings, transformers);
+        OSGiPropertyValueObjectFactory factory = new OSGiPropertyValueObjectFactory(mediator);
+        
+        OSGiImplementationProviderFactory providerFactory =
+            new OSGiImplementationProviderFactory(dataBindings, factory);
+        
+        ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+        providerFactories.addProviderFactory(providerFactory);
+        
+       
+    }
+
+    public Object[] getExtensionPoints() {
+        return null;
+    }
+    
+    public void stop(ExtensionPointRegistry registry) {
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/module/OSGiModuleActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/module/OSGiModuleActivator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/EquinoxRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/EquinoxRuntime.java?view=auto&rev=549122
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/EquinoxRuntime.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/EquinoxRuntime.java Wed Jun 20 07:58:18 2007
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.implementation.osgi.runtime;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osgi.framework.BundleContext;
+
+public class EquinoxRuntime extends OSGiRuntime  {
+    
+    
+    private static BundleContext bundleContext;
+    
+    private static EquinoxRuntime instance;
+    
+    private static Class eclipseStarterClass;
+    
+    public static OSGiRuntime getInstance() {
+        if (instance == null)
+            instance = new EquinoxRuntime();
+        return instance;
+    }
+    
+    
+    protected BundleContext startRuntime() throws Exception {
+        
+        if (bundleContext != null)
+            return bundleContext;
+                    
+        eclipseStarterClass = EquinoxRuntime.class.getClassLoader().loadClass("org.eclipse.core.runtime.adaptor.EclipseStarter");
+        Method startupMethod = eclipseStarterClass.getMethod("startup", String [].class, Runnable.class);
+        
+        // Equinox version 3.2 upwards have a startup method which returns BundleContext
+        if (startupMethod.getReturnType() == BundleContext.class) {
+            bundleContext = (BundleContext) startupMethod.invoke(null, (Object)new String[] {"-clean", "-console"}, null );
+        }
+        else {
+            
+            // Older versions of Equinox dont have a public method to obtain system bundlecontext
+            // Extract bundleContext from the private field 'context'. We are assuming that 
+            // there is no access restriction
+            Method mainMethod = eclipseStarterClass.getMethod("main", String [].class);
+            mainMethod.invoke(null, (Object)new String[] {"-clean", "-console"});
+            
+            Field contextField = eclipseStarterClass.getDeclaredField("context");
+            contextField.setAccessible(true);
+            bundleContext = (BundleContext) contextField.get(null);
+            
+        }
+            
+        
+        return bundleContext;
+        
+    }
+
+
+    @Override
+    protected void shutdownRuntime() throws Exception {
+
+        if (bundleContext == null)
+            return;
+        bundleContext = null;
+        if (eclipseStarterClass != null) {
+            Method shutdownMethod = eclipseStarterClass.getMethod("shutdown");
+            try {
+                shutdownMethod.invoke(eclipseStarterClass);
+            } catch (Exception e) {
+                // Ignore errors.
+            }
+        }
+    }
+    
+    
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/EquinoxRuntime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/implementation/osgi/runtime/EquinoxRuntime.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



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


Mime
View raw message