tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r552470 [2/3] - in /incubator/tuscany/java/sca/modules/implementation-osgi/src: main/java/org/apache/tuscany/implementation/osgi/context/ main/java/org/apache/tuscany/implementation/osgi/invocation/ main/java/org/apache/tuscany/implementati...
Date Mon, 02 Jul 2007 11:26:41 GMT
Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTargetInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTargetInvoker.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTargetInvoker.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTargetInvoker.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,189 @@
+/*
+ * 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.sca.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));
+            }
+        }
+    }
+
+    
+    private Object invokeTarget(Message msg) throws InvocationTargetException {
+
+    
+        ConversationSequence sequence = msg.getConversationSequence();
+        Object contextId = ThreadMessageContext.getMessageContext().getConversationID();
+        try {
+            OSGiInstanceWrapper wrapper = (OSGiInstanceWrapper)getInstance(sequence, contextId);
+            Object instance = wrapper.getInstance(service);
+        
+            Method m = JavaInterfaceUtil.findMethod(instance.getClass(), operation);
+        
+            Object ret = invokeMethod(instance, m, msg);
+            
+            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);
+        }
+    }
+    
+    protected Object invokeMethod(Object instance,
+            Method m,
+            Message msg)    
+        throws InvocationTargetException {
+
+        
+        try {
+            
+            Object payload = msg.getBody();
+            
+            if (payload != null && !payload.getClass().isArray()) {
+                return m.invoke(instance, payload);
+            } else {
+                return m.invoke(instance, (Object[]) payload);
+            }
+            
+        } 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);
+            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/sca/implementation/osgi/invocation/OSGiTargetInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/module/OSGiModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/module/OSGiModuleActivator.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/module/OSGiModuleActivator.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/module/OSGiModuleActivator.java Mon Jul  2 04:26:39 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.sca.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.sca.implementation.osgi.context.OSGiPropertyValueObjectFactory;
+import org.apache.tuscany.sca.implementation.osgi.invocation.OSGiImplementationProviderFactory;
+import org.apache.tuscany.sca.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/sca/implementation/osgi/module/OSGiModuleActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/EquinoxRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/EquinoxRuntime.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/EquinoxRuntime.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/EquinoxRuntime.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,106 @@
+/*
+ * 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.sca.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() throws Exception {
+        if (instance == null) {
+            EquinoxRuntime runtime = new EquinoxRuntime();
+            runtime.startRuntime();
+            instance = runtime;
+        }
+        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
+    public BundleContext getBundleContext() {
+        return bundleContext;
+    }
+
+    @Override
+    public void shutdown() throws Exception {
+
+        if (bundleContext == null)
+            return;
+        bundleContext = null;
+        instance = null;
+        if (eclipseStarterClass != null) {
+            Method shutdownMethod = eclipseStarterClass.getMethod("shutdown");
+            try {
+                shutdownMethod.invoke(eclipseStarterClass);
+            } catch (Exception e) {
+                // Ignore errors.
+            }
+        }
+    }
+
+
+    @Override
+    public boolean supportsBundleFragments() {
+        return false;
+    }
+    
+    
+
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/FelixRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/FelixRuntime.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/FelixRuntime.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/FelixRuntime.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,162 @@
+/*
+ * 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.sca.implementation.osgi.runtime;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class FelixRuntime extends OSGiRuntime implements BundleActivator {
+    
+    private static BundleContext bundleContext;
+    
+    private static FelixRuntime instance;
+    
+    private static Class felixClass;
+    private static Object felix;
+    
+    public static OSGiRuntime getInstance() throws Exception {
+        if (instance == null) {
+            FelixRuntime runtime = new FelixRuntime();
+            runtime.startRuntime();
+            instance = runtime;
+        }
+        return instance;
+    }
+    
+    
+    private static void deleteDirectory(File dir) {
+        
+        File[] files = dir.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            if (files[i].isDirectory())
+                deleteDirectory(files[i]);
+            else
+                files[i].delete();
+        }
+        dir.delete();
+        
+    }
+    
+    private BundleContext startRuntime() throws Exception {
+        
+        if (bundleContext != null)
+            return bundleContext;
+        
+               
+        ClassLoader cl = FelixRuntime.class.getClassLoader();
+        
+        Class felixMainClass = cl.loadClass("org.apache.felix.main.Main");
+        felixClass = cl.loadClass("org.apache.felix.framework.Felix");
+        Class propertyResolverClass = cl.loadClass("org.apache.felix.framework.util.MutablePropertyResolver");
+        Class propertyResolverImplClass = cl.loadClass("org.apache.felix.framework.util.MutablePropertyResolverImpl");
+        
+        Method propsMethod = felixMainClass.getMethod("loadConfigProperties");
+        Properties props = (Properties)propsMethod.invoke(null);
+        
+        File profileDir = new File(".felix"); 
+        if (profileDir.isDirectory()) 
+            deleteDirectory(profileDir);
+        else
+            profileDir.delete();
+        profileDir.mkdir();
+        profileDir.deleteOnExit();
+        
+        props.put("felix.cache.profiledir", profileDir.getAbsolutePath());
+        props.put("felix.embedded.execution", "true");
+        props.put("org.osgi.framework.system.packages", 
+                "org.osgi.framework; version=1.3.0," +
+                "org.osgi.service.packageadmin; version=1.2.0, " +
+                "org.osgi.service.startlevel; version=1.0.0, " +
+                "org.osgi.service.url; version=1.0.0 ");
+        
+        
+        
+        Constructor implConstructor = propertyResolverImplClass.getConstructor(Map.class);
+        Object mutableProps = implConstructor.newInstance(props);
+        
+        felix = felixClass.newInstance();
+        Method startMethod = felixClass.getMethod("start", propertyResolverClass, List.class);
+        List<BundleActivator> activators = new ArrayList<BundleActivator>();
+        BundleActivator activator = new FelixRuntime();
+        activators.add(activator);
+        startMethod.invoke(felix, mutableProps, activators);
+        
+        synchronized (activator) {
+            int retries = 0;
+            while (bundleContext == null && retries++ < 10) {
+                activator.wait(1000);
+            }
+        }
+        
+        return bundleContext;
+        
+    }
+
+    public void start(BundleContext context) throws Exception {
+        
+        bundleContext = context;
+        synchronized (this) {
+            this.notify();
+        }
+    }
+
+    public void stop(BundleContext context) throws Exception {
+        bundleContext = null;
+    }
+    
+    
+    
+    @Override
+    public BundleContext getBundleContext() {
+        return bundleContext;
+    }
+
+
+    @Override
+    public void shutdown() throws Exception {
+
+        if (bundleContext == null)
+            return;
+        bundleContext = null;
+        instance = null;
+        if (felix != null) {
+            Method shutdownMethod = felixClass.getMethod("shutdown");
+            try {
+                shutdownMethod.invoke(felix);
+            } catch (Exception e) {
+                // Ignore errors
+            }            
+            felix = null;
+        }
+    }
+    
+    @Override
+    public boolean supportsBundleFragments() {
+        return false;
+    }
+
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/KnopflerfishRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/KnopflerfishRuntime.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/KnopflerfishRuntime.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/KnopflerfishRuntime.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,156 @@
+/*
+ * 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.sca.implementation.osgi.runtime;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+public class KnopflerfishRuntime extends OSGiRuntime  {
+    
+    private static BundleContext bundleContext;
+    
+    private static KnopflerfishRuntime instance;
+    
+
+    private static Class frameworkClass;
+    
+    private static Object framework;
+    
+    public static OSGiRuntime getInstance() throws Exception {
+        if (instance == null) {
+            KnopflerfishRuntime runtime = new KnopflerfishRuntime();
+            runtime.startRuntime();
+            instance = runtime;
+        }
+        return instance;
+    }
+    
+   
+
+    // FIXME: Knopflerfish does not expose the methods used for configuration as public methods
+    //        It may be worth using the private methods in org.knopflerfish.framework.Main for
+    //        configuring using reflection if security policies allow it.
+    //        For now, a simple configuration routine reads sca.xargs from the directory in 
+    //        the classpath which contains framework.jar. The entries in init.xargs starting with
+    //        -install are assumed to be single-line entries with full bundle location.
+    //
+    private BundleContext startRuntime() throws Exception {
+        
+        if (bundleContext != null)
+            return bundleContext;
+        
+        
+        
+        System.setProperty("org.knopflerfish.framework.bundlestorage", "memory");
+                    
+        frameworkClass = KnopflerfishRuntime.class.getClassLoader().loadClass("org.knopflerfish.framework.Framework");
+        Constructor frameworkConstructor = frameworkClass.getConstructor(Object.class);
+        framework = frameworkConstructor.newInstance(new KnopflerfishRuntime());
+        Method launchMethod = frameworkClass.getMethod("launch", long.class);
+        launchMethod.invoke(framework, 0);
+        Method getContextMethod = frameworkClass.getMethod("getSystemBundleContext");
+        bundleContext = (BundleContext)getContextMethod.invoke(framework);
+       
+        System.setProperty("com.gatespace.bundle.cm.store", "knopflerfish.store");
+        File xargsFile = null;
+        String classpath = System.getProperty("java.class.path");
+        String[] classpathEntries = classpath.split(System.getProperty("path.separator"));
+        for (int i = 0; i < classpathEntries.length; i++) {
+            if (classpathEntries[i].endsWith("framework.jar")) {
+                String path = classpathEntries[i].substring(0, classpathEntries[i].length() - "framework.jar".length());
+                path = path + "sca.xargs";
+                xargsFile = new File(path);
+                if (!xargsFile.exists())
+                    xargsFile = null;
+                break;
+            }
+        }
+        if (xargsFile != null) {
+            BufferedReader reader = new BufferedReader(new FileReader(xargsFile));
+            String line;
+            Hashtable<String, Bundle> bundles = new Hashtable<String, Bundle>();
+            while ((line = reader.readLine()) != null) {
+                line = line.trim();
+                if (line.startsWith("-install")) {
+                    try {
+
+                        String bundleLocation = line.substring("-install".length()).trim();
+                        Bundle bundle = bundleContext.installBundle(bundleLocation);
+                        bundles.put(bundleLocation, bundle);
+                        
+                    } catch (BundleException e) {
+                        e.printStackTrace();
+                    }
+                    
+                }
+                if (line.startsWith("-start")) {
+
+                    try {
+                        String bundleLocation = line.substring("-start".length()).trim();
+                        Bundle bundle = bundles.get(bundleLocation);
+                        bundle.start();
+                    } catch (BundleException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+        
+        
+        return bundleContext;
+        
+    }
+    
+    @Override
+    public BundleContext getBundleContext() {
+        return bundleContext;
+    }
+
+    @Override
+    public void shutdown() throws Exception {
+
+        if (bundleContext == null)
+            return;
+        bundleContext = null;
+        instance = null;
+        if (framework != null) {
+            Method shutdownMethod = frameworkClass.getMethod("shutdown");
+            try {
+                shutdownMethod.invoke(framework);
+            } catch (Exception e) {
+                // Ignore errors
+            }
+            framework = null;
+        }
+        
+    }
+    
+    @Override
+    public boolean supportsBundleFragments() {
+        return true;
+    }
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRuntime.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRuntime.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRuntime.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,91 @@
+/*
+ * 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.sca.implementation.osgi.runtime;
+
+
+import java.lang.reflect.Method;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+public abstract class OSGiRuntime  {
+    
+    public abstract BundleContext getBundleContext();
+    
+    public abstract void shutdown() throws Exception;
+    
+    public abstract boolean supportsBundleFragments();
+    
+   
+    /**
+     * System property org.apache.tuscany.implementation.osgi.runtime.OSGiRuntime can be set to the
+     * name of the OSGiRuntime class (eg. EquinoxRuntime). If set, start this runtime and return the
+     * system bundlecontext. If not set, start Equinox/Felix/Knopflerfish (in that order) from the
+     * classpath.
+     * 
+     * @throws BundleException
+     */
+    public static OSGiRuntime getRuntime() throws BundleException {
+        
+        String runtimeClassName = System.getProperty(OSGiRuntime.class.getName());
+
+        if (runtimeClassName != null) {
+            try {
+                Class<?> runtimeClass = OSGiRuntime.class.getClassLoader().loadClass(runtimeClassName);
+                Method method = runtimeClass.getMethod("getInstance");
+                return (OSGiRuntime) method.invoke(null);
+                
+            } catch (Exception e) {
+                throw new BundleException("Could not start OSGi runtime " + runtimeClassName, e);
+            }
+        }
+        
+        try {
+            
+            return EquinoxRuntime.getInstance();
+            
+        } catch (ClassNotFoundException e) {
+        } catch (Throwable e) {   
+            e.printStackTrace();
+        } 
+        
+        try {
+            
+            return FelixRuntime.getInstance();
+            
+        } catch (ClassNotFoundException e) {
+        } catch (Throwable e) {   
+            e.printStackTrace();
+        } 
+        
+        try {
+            
+            return KnopflerfishRuntime.getInstance();
+            
+        } catch (ClassNotFoundException e) {
+        } catch (Throwable e) {   
+            e.printStackTrace();
+        } 
+        
+        throw new BundleException("Could not start OSGi runtime from the classpath");
+    }
+    
+   
+
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,131 @@
+/*
+ * 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.sca.implementation.osgi.xml;
+
+
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.impl.ComponentTypeImpl;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationInterface;
+import org.apache.tuscany.sca.scope.Scope;
+
+
+/**
+ * OSGi implementation 
+ *    All attributes from <implementation.osgi> have getters in this class
+ * This class implements OSGiImplementationInterface which is associated with OSGiImplementationProvider.
+ */
+public class OSGiImplementation extends ComponentTypeImpl implements OSGiImplementationInterface {
+    
+    private String bundleName;
+    private String bundleLocation;
+    private String[] imports;
+    private Scope scope;
+    private String[] allowsPassByRef;
+    private boolean needsPropertyInjection;
+    Hashtable<String, List<ComponentProperty>> referenceProperties;
+    Hashtable<String, List<ComponentProperty>> serviceProperties;
+
+    public OSGiImplementation(String bundleName, 
+            String bundleLocation,
+            String[] imports, 
+            String scopeName,
+            String[] allowsPassByRef,
+            Hashtable<String, List<ComponentProperty>> refProperties,
+            Hashtable<String, List<ComponentProperty>> serviceProperties,
+            boolean needsPropertyInjection) {
+        
+        super();
+        this.bundleName = bundleName;
+        this.bundleLocation = bundleLocation;
+        this.imports = imports;
+        this.scope = new Scope(scopeName == null?"COMPOSITE":scopeName);
+        this.allowsPassByRef = allowsPassByRef;
+        this.referenceProperties = refProperties;
+        this.serviceProperties = serviceProperties;
+        this.needsPropertyInjection = needsPropertyInjection;
+        
+    }
+
+    
+    public String getBundleName() {
+        return bundleName;
+    }
+    
+    public String getBundleLocation() {
+        return bundleLocation;
+    }
+
+    
+    public String[] getImports() {
+        return imports;
+    }
+    
+    
+    public Scope getScope() {
+        return scope;
+    }
+    
+    public List<ComponentProperty> getReferenceProperties(String referenceName) {
+        return referenceProperties.get(referenceName);
+    }
+    
+    public List<ComponentProperty> getServiceProperties(String serviceName) {
+        return serviceProperties.get(serviceName);
+    }
+    
+
+    public boolean isAllowsPassByReference(Method method) {
+        
+        if (allowsPassByRef == null || allowsPassByRef.length == 0)
+            return false;
+        
+        String className = method.getDeclaringClass().getName();
+        String methodName = className + "." + method.getName();
+        
+        for (String opName : allowsPassByRef) {
+            if (className.equals(opName) || methodName.equals(opName))
+                return true;
+        }
+        return false;
+    }
+
+    
+    public boolean needsPropertyInjection() {
+        return needsPropertyInjection;
+    }
+
+
+    public boolean isEagerInit() {
+        return false;
+    }
+
+    public long getMaxAge() {
+        return Long.MAX_VALUE;
+    }
+
+    public long getMaxIdleTime() {
+        return Long.MAX_VALUE;
+    }
+    
+    
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,488 @@
+/*
+ * 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.sca.implementation.osgi.xml;
+
+import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
+import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static org.osoa.sca.Constants.SCA_NS;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.StringTokenizer;
+
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospector;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * 
+ * Process an <implementation.osgi/> element in a component definition. An instance of
+ * OSGiImplementation is created.
+ * Also associates the component type file with the implementation.
+ * 
+ *
+ */
+public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiImplementation> {
+    
+    public static final QName IMPLEMENTATION_OSGI  = new QName(SCA_NS, "implementation.osgi");
+    
+    private static final String BUNDLE             = "bundle";
+    private static final String BUNDLE_LOCATION    = "bundleLocation";
+    private static final String SCOPE              = "scope";
+    private static final String IMPORTS            = "imports";
+    private static final String ALLOWS_PASS_BY_REF = "allowsPassByReference";
+    private static final String INJECT_PROPERTIES  = "injectProperties";
+   
+    private static final QName PROPERTIES_QNAME    = new QName(SCA_NS, "properties");
+    private static final QName PROPERTY_QNAME      = new QName(SCA_NS, "property");
+    
+    private JavaInterfaceIntrospector interfaceIntrospector;
+    private JavaInterfaceFactory javaInterfaceFactory;
+    private AssemblyFactory assemblyFactory;
+    //private PolicyFactory policyFactory;
+    
+    private static final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
+    static {
+        domFactory.setNamespaceAware(true);
+    }
+
+    public OSGiImplementationProcessor(JavaInterfaceIntrospector interfaceIntrospector,
+            JavaInterfaceFactory javaInterfaceFactory,
+            AssemblyFactory assemblyFactory,
+            PolicyFactory policyFactory) {
+        
+        this.interfaceIntrospector = interfaceIntrospector;
+        this.assemblyFactory = assemblyFactory;
+        this.javaInterfaceFactory = javaInterfaceFactory;
+        //this.policyFactory = policyFactory;
+    }
+    
+    public QName getArtifactType() {
+        return IMPLEMENTATION_OSGI;
+    }
+
+    public Class<OSGiImplementation> getModelType() {
+        return OSGiImplementation.class;
+    }
+
+    private String[] tokenize(String str) {
+        StringTokenizer tokenizer = new StringTokenizer(str);
+        String[] tokens = new String[tokenizer.countTokens()];
+        for (int i= 0; i < tokens.length; i++) {
+            tokens[i] = tokenizer.nextToken();
+        }
+        
+        return tokens;
+    }
+    
+    public OSGiImplementation read(XMLStreamReader reader) throws ContributionReadException {
+        
+        assert IMPLEMENTATION_OSGI.equals(reader.getName());
+        
+        try {
+            String bundleName = reader.getAttributeValue(null, BUNDLE);
+            String bundleLocation = reader.getAttributeValue(null, BUNDLE_LOCATION);
+            String imports = reader.getAttributeValue(null, IMPORTS);
+            String[] importList;
+            if (imports != null)
+                importList = tokenize(imports);
+            else
+                importList = new String[0];
+            String scope = reader.getAttributeValue(null, SCOPE);  
+            String allowsPassByRef = reader.getAttributeValue(null, ALLOWS_PASS_BY_REF);
+            String[] allowsPassByRefList;
+            if (allowsPassByRef != null)
+                allowsPassByRefList = tokenize(allowsPassByRef);
+            else
+                allowsPassByRefList = new String[0];
+            
+            boolean injectProperties = !"false".equalsIgnoreCase(reader.getAttributeValue(null, INJECT_PROPERTIES));
+            
+            
+            Hashtable<String, List<ComponentProperty>> refProperties = 
+                new Hashtable<String, List<ComponentProperty>>();
+            Hashtable<String, List<ComponentProperty>> serviceProperties = 
+                new Hashtable<String, List<ComponentProperty>>();
+            
+            while (reader.hasNext()) {
+                
+                int next = reader.next();
+                if (next == END_ELEMENT && IMPLEMENTATION_OSGI.equals(reader.getName())) {
+                    break;
+                }
+                else if (next == START_ELEMENT && PROPERTIES_QNAME.equals(reader.getName())) {
+                    
+                    // FIXME: This is temporary code which allows reference and service properties used
+                    //        for filtering OSGi services to be specified in <implementation.osgi/>
+                    //        This should really be provided in the component type file since these
+                    //        properties are associated with an implementation rather than a configured
+                    //        instance of an implementation.
+                    String refName = reader.getAttributeValue(null, "reference");
+                    String serviceName = reader.getAttributeValue(null, "service");
+                    List<ComponentProperty> props = readProperties(reader);
+                    if (refName != null)
+                        refProperties.put(refName, props);
+                    else if (serviceName != null)
+                        serviceProperties.put(serviceName, props);
+                    else
+                        throw new ContributionReadException("Properties in implementation.osgi should specify service or reference");                }
+            }
+                
+            OSGiImplementation implementation = new OSGiImplementation(
+                    bundleName, 
+                    bundleLocation,
+                    importList, 
+                    scope,
+                    allowsPassByRefList,
+                    refProperties,
+                    serviceProperties,
+                    injectProperties);
+            
+            
+            processComponentType(bundleName, implementation);
+            
+            implementation.setUnresolved(true);
+            
+            return implementation;
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionReadException(e);
+        }
+    }
+
+    public void resolve(OSGiImplementation impl, ModelResolver resolver) throws ContributionResolveException {
+        
+        try {
+            
+            impl.setUnresolved(false);
+            
+            // FIXME: Tuscany will only process the component type file if it is visible
+            //        to its classloader. So it can't really be located anywhere in the
+            //        directory structure like the bundle. So even though the bundle name
+            //        is used to find the relative pathname of the component type file,
+            //        its absolute location is obtained from the classloader. This doesn't
+            //        seem right, since the bundle could potentially be located anywhere.
+            ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            String bundleName = impl.getBundleName();
+            String ctName = bundleName.replaceAll("\\.", "/") + ".componentType";
+            String ctURI = cl.getResource(ctName).toString();
+            
+            impl.setURI(ctURI);
+            ComponentType componentType = resolver.resolveModel(ComponentType.class, impl);
+            if (componentType.isUnresolved()) {
+                throw new ContributionResolveException("missing .componentType side file");
+            }
+            
+            List<Service> services = componentType.getServices();
+            for (Service service : services) {
+                Interface interfaze = service.getInterfaceContract().getInterface();
+                if (interfaze instanceof JavaInterface) {
+                    JavaInterface javaInterface = (JavaInterface)interfaze;
+                    if (javaInterface.getJavaClass() == null) {
+                        Class<?> javaClass = Class.forName(javaInterface.getName());
+                        javaInterface.setJavaClass(javaClass);
+                    }
+                    Service serv = createService(service, javaInterface.getJavaClass());
+                    impl.getServices().add(serv);
+                }
+            }
+            
+            List<Reference> references = componentType.getReferences();
+            for (Reference reference : references) {
+                Interface interfaze = reference.getInterfaceContract().getInterface();
+                if (interfaze instanceof JavaInterface) {
+                    JavaInterface javaInterface = (JavaInterface)interfaze;
+                    if (javaInterface.getJavaClass() == null) {
+                        Class<?> javaClass = Class.forName(javaInterface.getName());
+                        javaInterface.setJavaClass(javaClass);
+                    }
+                    Reference ref = createReference(reference, javaInterface.getJavaClass());
+                    impl.getReferences().add(ref);
+                }
+                else
+                    impl.getReferences().add(reference);
+            }
+            
+            List<Property> properties = componentType.getProperties();
+            for (Property property : properties) {
+                impl.getProperties().add(property);
+            }
+            impl.setConstrainingType(componentType.getConstrainingType());
+            
+            
+        } catch (Exception e) {
+            throw new ContributionResolveException(e);
+        }
+        
+    }
+    
+    private Service createService(Service serv, Class<?> interfaze) throws InvalidInterfaceException {
+        Service service = assemblyFactory.createService();
+        JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+        service.setInterfaceContract(interfaceContract);
+
+        // create a relative URI
+        service.setName(serv.getName());
+
+        JavaInterface callInterface = interfaceIntrospector.introspect(interfaze);
+        service.getInterfaceContract().setInterface(callInterface);
+        if (callInterface.getCallbackClass() != null) {
+            JavaInterface callbackInterface = interfaceIntrospector.introspect(callInterface.getCallbackClass());
+            service.getInterfaceContract().setCallbackInterface(callbackInterface);
+        }
+        return service;
+    }
+    
+    private Reference createReference(Reference ref, Class<?> clazz) throws InvalidInterfaceException {
+        org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference();
+        JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+        reference.setInterfaceContract(interfaceContract);
+        
+        reference.setName(ref.getName());
+        reference.setMultiplicity(ref.getMultiplicity());
+
+        JavaInterface callInterface = interfaceIntrospector.introspect(clazz);
+        reference.getInterfaceContract().setInterface(callInterface);
+        if (callInterface.getCallbackClass() != null) {
+            JavaInterface callbackInterface = interfaceIntrospector.introspect(callInterface.getCallbackClass());
+            reference.getInterfaceContract().setCallbackInterface(callbackInterface);
+        }
+       
+        return reference;
+    }
+
+    public void write(OSGiImplementation model, XMLStreamWriter outputSource) throws ContributionWriteException {
+    }
+    
+    private void processComponentType(String bundleName, OSGiImplementation implementation) {
+        
+        // Form the URI of the expected .componentType file;
+        String ctName = bundleName.replaceAll("\\.", "/") + ".componentType";
+        String uri = ctName;
+
+        
+        implementation.setURI(uri);
+        implementation.setUnresolved(true);
+    }
+
+    private QName getQNameValue(XMLStreamReader reader, String value) {
+        if (value != null) {
+            int index = value.indexOf(':');
+            String prefix = index == -1 ? "" : value.substring(0, index);
+            String localName = index == -1 ? value : value.substring(index + 1);
+            String ns = reader.getNamespaceContext().getNamespaceURI(prefix);
+            if (ns == null) {
+                ns = "";
+            }
+            return new QName(ns, localName, prefix);
+        } else {
+            return null;
+        }
+    }
+    
+    private void declareNamespace(Element element, String prefix, String ns) {
+        String qname = null;
+        if ("".equals(prefix)) {
+            qname = "xmlns";
+        } else {
+            qname = "xmlns:" + prefix;
+        }
+        Node node = element;
+        boolean declared = false;
+        while (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
+            NamedNodeMap attrs = node.getAttributes();
+            if (attrs == null) {
+                break;
+            }
+            Node attr = attrs.getNamedItem(qname);
+            if (attr != null) {
+                declared = ns.equals(attr.getNodeValue());
+                break;
+            }
+            node = node.getParentNode();
+        }
+        if (!declared) {
+            org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname);
+            attr.setValue(ns);
+            element.setAttributeNodeNS(attr);
+        }
+    }
+    
+    private Element createElement(Document document, QName name) {
+        String prefix = name.getPrefix();
+        String qname = (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name
+            .getLocalPart();
+        return document.createElementNS(name.getNamespaceURI(), qname);
+    }
+
+    private void loadElement(XMLStreamReader reader, Element root) throws XMLStreamException {
+        Document document = root.getOwnerDocument();
+        Node current = root;
+        while (true) {
+            switch (reader.next()) {
+                case XMLStreamConstants.START_ELEMENT:
+                    QName name = reader.getName();
+                    Element child = createElement(document, name);
+
+                    // push the new element and make it the current one
+                    current.appendChild(child);
+                    current = child;
+
+                    declareNamespace(child, name.getPrefix(), name.getNamespaceURI());
+
+                    int count = reader.getNamespaceCount();
+                    for (int i = 0; i < count; i++) {
+                        String prefix = reader.getNamespacePrefix(i);
+                        String ns = reader.getNamespaceURI(i);
+                        declareNamespace(child, prefix, ns);
+                    }
+
+                    // add the attributes for this element
+                    count = reader.getAttributeCount();
+                    for (int i = 0; i < count; i++) {
+                        String ns = reader.getAttributeNamespace(i);
+                        String prefix = reader.getAttributePrefix(i);
+                        String localPart = reader.getAttributeLocalName(i);
+                        String value = reader.getAttributeValue(i);
+                        child.setAttributeNS(ns, localPart, value);
+                        declareNamespace(child, prefix, ns);
+                    }
+
+                    break;
+                case XMLStreamConstants.CDATA:
+                    current.appendChild(document.createCDATASection(reader.getText()));
+                    break;
+                case XMLStreamConstants.CHARACTERS:
+                    current.appendChild(document.createTextNode(reader.getText()));
+                    break;
+                case XMLStreamConstants.END_ELEMENT:
+                    // if we are back at the root then we are done
+                    if (current == root) {
+                        return;
+                    }
+
+                    // pop the element off the stack
+                    current = current.getParentNode();
+            }
+        }
+    }
+    
+    private Document readPropertyValue(XMLStreamReader reader, QName type)
+            throws XMLStreamException, ParserConfigurationException {
+    
+        Document doc = domFactory.newDocumentBuilder().newDocument();
+
+        // root element has no namespace and local name "value"
+        Element root = doc.createElementNS(null, "value");
+        if (type != null) {
+            org.w3c.dom.Attr xsi = doc.createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi");
+             xsi.setValue(W3C_XML_SCHEMA_INSTANCE_NS_URI);
+            root.setAttributeNodeNS(xsi);
+
+            String prefix = type.getPrefix();
+            if (prefix == null || prefix.length() == 0) {
+                prefix = "ns";
+            }
+
+            declareNamespace(root, prefix, type.getNamespaceURI());
+
+            org.w3c.dom.Attr xsiType = doc.createAttributeNS(W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type");
+            xsiType.setValue(prefix + ":" + type.getLocalPart());
+            root.setAttributeNodeNS(xsiType);
+        }
+        doc.appendChild(root);
+
+        loadElement(reader, root);
+        return doc;
+    }
+    
+    private  void readProperty(ComponentProperty prop, XMLStreamReader reader)
+            throws XMLStreamException, ContributionReadException {
+        
+    
+        prop.setName(reader.getAttributeValue(null, "name"));
+        String xsdType = reader.getAttributeValue(null, "type");
+        if (xsdType != null)       
+            prop.setXSDType(getQNameValue(reader, xsdType));
+        else
+            prop.setXSDType(SimpleTypeMapperImpl.XSD_STRING);
+        
+        try {
+            Document value = readPropertyValue(reader, prop.getXSDType());
+            prop.setValue(value);
+        } catch (ParserConfigurationException e) {
+            throw new ContributionReadException(e);
+        }
+    }
+    
+    private  List<ComponentProperty> readProperties(XMLStreamReader reader)
+            throws XMLStreamException, ContributionReadException {
+        
+        List<ComponentProperty> properties = new ArrayList<ComponentProperty>();
+        
+        while (reader.hasNext()) {
+            
+            int next = reader.next();
+            if (next == END_ELEMENT && PROPERTIES_QNAME.equals(reader.getName())) {
+                break;
+            }
+            else if (next == START_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
+                
+                ComponentProperty componentProperty = assemblyFactory.createComponentProperty();
+                readProperty(componentProperty, reader);
+                properties.add(componentProperty);
+            }
+        }
+        
+        return properties;
+
+    }
+}

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

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

Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator?view=diff&rev=552470&r1=552469&r2=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator Mon Jul  2 04:26:39 2007
@@ -15,4 +15,4 @@
 # specific language governing permissions and limitations
 # under the License.
 # Implementation class for the ExtensionActivator
-org.apache.tuscany.implementation.osgi.module.OSGiModuleActivator
+org.apache.tuscany.sca.implementation.osgi.module.OSGiModuleActivator

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiPropertyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiPropertyTestCase.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiPropertyTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiPropertyTestCase.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,47 @@
+/*
+ * 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.sca.implementation.osgi.invocation;
+
+import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestBundles;
+import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface;
+import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestWithPropertyImpl;
+
+
+/**
+ * 
+ * Test the execution of an OSGi implementation type
+ *
+ */
+public class OSGiPropertyTestCase extends OSGiTestCase {
+    
+    @Override
+    protected void setUp() throws Exception {
+        
+        className = OSGiTestWithPropertyImpl.class.getName();
+        
+        OSGiTestBundles.createBundle("target/OSGiTestService.jar", 
+                OSGiTestInterface.class, 
+                OSGiTestWithPropertyImpl.class);        
+        
+    }
+    
+    
+
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTestCase.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTestCase.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,70 @@
+/*
+ * 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.sca.implementation.osgi.invocation;
+
+import java.lang.reflect.Proxy;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.implementation.osgi.runtime.OSGiRuntime;
+import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestBundles;
+import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestImpl;
+import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface;
+
+
+/**
+ * 
+ * Test the execution of an OSGi implementation type
+ *
+ */
+public class OSGiTestCase extends TestCase {
+    
+    protected String className;
+   
+    protected void setUp() throws Exception {
+
+        className = OSGiTestImpl.class.getName();
+        OSGiTestBundles.createBundle("target/OSGiTestService.jar", OSGiTestInterface.class, OSGiTestImpl.class);
+        
+    }
+    
+    protected void tearDown() throws Exception {
+        OSGiRuntime.getRuntime().shutdown();
+    }
+    
+    public void testOSGiComponent() throws Exception {
+        
+        SCADomain scaDomain = SCADomain.newInstance("osgitest.composite");
+        OSGiTestInterface testService = scaDomain.getService(OSGiTestInterface.class, "OSGiTestServiceComponent");
+        assert(testService != null);
+        
+        assert(testService instanceof Proxy);
+        
+        String str = testService.testService();
+        
+        System.out.println("className " + className + " str " + str);
+        assertEquals(className, str);
+
+        scaDomain.close();
+              
+    }
+
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRuntimeTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRuntimeTestCase.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRuntimeTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRuntimeTestCase.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,58 @@
+/*
+ * 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.sca.implementation.osgi.runtime;
+
+import org.apache.tuscany.sca.implementation.osgi.runtime.OSGiRuntime;
+import org.osgi.framework.BundleContext;
+
+import junit.framework.TestCase;
+
+/**
+ * Test OSGi runtime.
+ * 
+ */
+public class OSGiRuntimeTestCase extends TestCase {
+    
+    public void testRuntime() throws Exception {
+        
+        BundleContext bc1 = OSGiRuntime.getRuntime().getBundleContext();
+        
+        assertNotNull(bc1);
+        
+        BundleContext bc2 = OSGiRuntime.getRuntime().getBundleContext();
+        
+        assertNotNull(bc2);
+        
+        assertTrue(bc1 == bc2);
+        
+        OSGiRuntime.getRuntime().shutdown();
+        
+        BundleContext bc3 = OSGiRuntime.getRuntime().getBundleContext();
+        
+        assertNotNull(bc3);
+        
+        assertTrue(bc1 != bc3);
+        
+        
+        
+    }
+
+   
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,110 @@
+/*
+ * 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.sca.implementation.osgi.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+
+/**
+ * 
+ * Utility class to create OSGi bundles
+ *
+ */
+public class OSGiTestBundles {
+    
+    public static void createBundle(String jarName,
+            Class<?> interfaceClass, Class<?> implClass) throws Exception {
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+        String EOL = System.getProperty("line.separator");
+        
+        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);
+        manifestBuf.append("Import-Package: org.osgi.framework" + EOL);
+        manifestBuf.append("Bundle-Activator: " + implClass.getName() + EOL);
+
+        ByteArrayInputStream manifestStream = new ByteArrayInputStream(manifestBuf.toString().getBytes());
+        Manifest manifest = new Manifest();
+        manifest.read(manifestStream);
+        
+
+        JarOutputStream jarOut = new JarOutputStream(out, manifest);
+
+        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);
+        
+        String implClassName = implClass.getName().replaceAll("\\.",
+                "/")
+                + ".class";
+
+        url = implClass.getClassLoader().getResource(implClassName);
+        path = url.getPath();
+
+        ze = new ZipEntry(implClassName);
+
+        jarOut.putNextEntry(ze);
+        file = new FileInputStream(path);
+        fileContents = new byte[file.available()];
+        file.read(fileContents);
+        jarOut.write(fileContents);
+
+        file.close();
+
+        jarOut.close();
+        out.close();
+
+        FileOutputStream fileOut = new FileOutputStream(jarName);
+        fileOut.write(out.toByteArray());
+        fileOut.close();
+
+
+    }
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,50 @@
+/*
+ * 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.sca.implementation.osgi.test;
+
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * 
+ * Test class - Implementation of an OSGi service
+ *
+ */
+public class OSGiTestImpl implements OSGiTestInterface, BundleActivator {
+    
+    public String testService() {
+        
+        return OSGiTestImpl.class.getName();
+        
+    }
+
+    public void start(BundleContext bc) throws Exception {
+        
+        bc.registerService(OSGiTestInterface.class.getName(), this, new Hashtable<String, Object>());
+        
+    }
+
+    public void stop(BundleContext bc) throws Exception {
+    }
+
+    
+}

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

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

Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java Mon Jul  2 04:26:39 2007
@@ -0,0 +1,31 @@
+/*
+ * 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.sca.implementation.osgi.test;
+
+/**
+ * 
+ * Test class - Interface for an OSGi service
+ *
+ */
+public interface OSGiTestInterface {
+    
+    public String testService() throws Exception ;
+
+}

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

Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.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