servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r386642 [1/2] - in /incubator/servicemix/trunk/servicemix-sca: ./ src/main/java/org/apache/servicemix/sca/ src/main/java/org/apache/servicemix/sca/assembly/ src/main/java/org/apache/servicemix/sca/assembly/impl/ src/main/java/org/apache/ser...
Date Fri, 17 Mar 2006 14:30:12 GMT
Author: gnodet
Date: Fri Mar 17 06:30:08 2006
New Revision: 386642

URL: http://svn.apache.org/viewcvs?rev=386642&view=rev
Log:
SM-353: Upgrade sca to latest tuscany scn head
SM-313: [ERROR] TEST org.apache.servicemix.sca.ScaComponentTest FAILED

Added:
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceBuilder.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceWireBuilder.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/JbiServiceEntryPointBuilder.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/ExternalJbiServiceContextFactory.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/JbiServiceEntryPointContextFactory.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceClient.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceTargetInvoker.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/loader/
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/loader/JbiBindingLoader.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/BootstrapHelper.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/CommonsLoggingMonitorFactory.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/TuscanyRuntime.java
    incubator/servicemix/trunk/servicemix-sca/src/main/resources/system.fragment
    incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/account/
    incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl
      - copied, changed from r385380, incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl
Removed:
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/CommonsLoggingLogProvider.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/sdo/
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceConfigurationHandler.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceHandler.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/osoa/sca/model/
    incubator/servicemix/trunk/servicemix-sca/src/main/resources/org/
    incubator/servicemix/trunk/servicemix-sca/src/main/resources/sca.fragment
    incubator/servicemix/trunk/servicemix-sca/src/main/resources/tuscany-model.config
    incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl
    incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/tuscany-model.config
Modified:
    incubator/servicemix/trunk/servicemix-sca/project.xml
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaLifeCycle.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaServiceUnit.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/JbiAssemblyFactory.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/JbiBinding.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiAssemblyFactoryImpl.java
    incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiBindingImpl.java
    incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/AssemblyLoaderTest.java
    incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/ScaComponentTest.java
    incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountServiceImpl.java
    incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/sca.module

Modified: incubator/servicemix/trunk/servicemix-sca/project.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/project.xml?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/project.xml (original)
+++ incubator/servicemix/trunk/servicemix-sca/project.xml Fri Mar 17 06:30:08 2006
@@ -54,110 +54,106 @@
         <jbi.bootstrap>true</jbi.bootstrap>
       </properties>
     </dependency>
+    
     <dependency>
-      <groupId>org.eclipse.emf</groupId>
-      <artifactId>commonj-sdo</artifactId>
-      <version>${eclipse_emf_version}</version>
+      <groupId>commonj</groupId>
+      <artifactId>sdo-api</artifactId>
+      <version>20060317</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
     <dependency>
-      <groupId>org.eclipse.emf</groupId>
-      <artifactId>ecore</artifactId>
-      <version>${eclipse_emf_version}</version>
-      <properties>
-        <jbi.bundle>true</jbi.bundle>
-      </properties>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.emf</groupId>
-      <artifactId>common</artifactId>
-      <version>${eclipse_emf_version}</version>
+      <groupId>org.osoa</groupId>
+      <artifactId>sca-api</artifactId>
+      <version>${tuscany_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
+    
     <dependency>
-      <groupId>org.eclipse.emf</groupId>
-      <artifactId>ecore-sdo</artifactId>
-      <version>2.1.1</version>
+      <groupId>org.apache.tuscany</groupId>
+      <artifactId>tuscany-common</artifactId>
+      <version>${tuscany_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
     <dependency>
-      <groupId>org.eclipse.emf</groupId>
-      <artifactId>ecore-change</artifactId>
-      <version>${eclipse_emf_version}</version>
+      <groupId>org.apache.tuscany</groupId>
+      <artifactId>tuscany-container-java</artifactId>
+      <version>${tuscany_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
     <dependency>
-      <groupId>org.eclipse.emf</groupId>
-      <artifactId>ecore-xmi</artifactId>
-      <version>${eclipse_emf_version}</version>
+      <groupId>org.apache.tuscany</groupId>
+      <artifactId>tuscany-core</artifactId>
+      <version>${tuscany_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
     <dependency>
-      <groupId>org.eclipse.wtp</groupId>
-      <artifactId>wsdl</artifactId>
-      <version>${eclipse_wtp_version}</version>
+      <groupId>org.apache.tuscany</groupId>
+      <artifactId>tuscany-model</artifactId>
+      <version>${tuscany_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
     <dependency>
-      <groupId>org.eclipse.xsd</groupId>
-      <artifactId>xsd</artifactId>
-      <version>${eclipse_xsd_version}</version>
+      <groupId>org.apache.tuscany</groupId>
+      <artifactId>tuscany-sdo-impl</artifactId>
+      <version>${tuscany_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
+    
     <dependency>
-      <groupId>servicemix</groupId>
-      <artifactId>tuscany-common</artifactId>
-      <version>dev-200512</version>
+      <groupId>org.eclipse.emf</groupId>
+      <artifactId>common</artifactId>
+      <version>${eclipse_emf_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
     <dependency>
-      <groupId>servicemix</groupId>
-      <artifactId>tuscany-container-java</artifactId>
-      <version>dev-200512</version>
+      <groupId>org.eclipse.emf</groupId>
+      <artifactId>ecore</artifactId>
+      <version>${eclipse_emf_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
     <dependency>
-      <groupId>servicemix</groupId>
-      <artifactId>tuscany-core</artifactId>
-      <version>dev-200512</version>
+      <groupId>org.eclipse.emf</groupId>
+      <artifactId>ecore-change</artifactId>
+      <version>${eclipse_emf_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
     <dependency>
-      <groupId>servicemix</groupId>
-      <artifactId>tuscany-model</artifactId>
-      <version>dev-200512</version>
+      <groupId>org.eclipse.emf</groupId>
+      <artifactId>ecore-xmi</artifactId>
+      <version>${eclipse_emf_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
     <dependency>
-      <groupId>servicemix</groupId>
-      <artifactId>sca-api</artifactId>
-      <version>dev-200512</version>
+      <groupId>org.eclipse.xsd</groupId>
+      <artifactId>xsd</artifactId>
+      <version>${eclipse_xsd_version}</version>
       <properties>
         <jbi.bundle>true</jbi.bundle>
       </properties>
     </dependency>
+    
     <dependency>
       <groupId>servicemix</groupId>
       <artifactId>jaxb-impl</artifactId>
@@ -195,6 +191,13 @@
       <properties>
       </properties>
     </dependency>
+    <dependency>
+      <groupId>woodstox</groupId>
+      <artifactId>wstx-asl</artifactId>
+      <version>${woodstox_version}</version>
+      <properties>
+      </properties>
+    </dependency>
 
       <!-- Provided dependencies -->
 		<dependency>
@@ -324,37 +327,5 @@
         <url>http://incubator.apache.org/beehive/</url>
       </dependency>
   </dependencies>
-
-  <build>
-
-    <unitTest>
-        <includes>
-            <include>**/*Test.*</include>
-        </includes>
-        <excludes>
-           <!-- http://jira.activemq.org/jira/browse/SM-313 -->
-          <exclude>**/ScaComponentTest.*</exclude>
-        </excludes>
-    </unitTest>
-
-    <resources>
-      <resource>
-          <directory>src/main/resources</directory>
-        <includes>
-          <include>**/*.xml</include>
-          <include>**/*.properties</include>
-          <include>**/*</include>
-        </includes>
-      </resource>
-      <!--
-      <resource>
-        <directory>target/generated</directory>
-        <includes>
-          <include>**/*</include>
-        </includes>
-      </resource>
-      -->
-    </resources>
-  </build>
 
 </project>

Modified: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaEndpoint.java Fri Mar 17 06:30:08 2006
@@ -16,8 +16,9 @@
 package org.apache.servicemix.sca;
 
 import java.io.StringWriter;
-import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.lang.reflect.UndeclaredThrowableException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -35,14 +36,11 @@
 import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.ExchangeProcessor;
 import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.tuscany.core.context.EntryPointContext;
 import org.apache.tuscany.core.invocation.spi.ProxyFactory;
 import org.apache.tuscany.model.assembly.ConfiguredReference;
 import org.apache.tuscany.model.assembly.ConfiguredService;
 import org.apache.tuscany.model.assembly.EntryPoint;
-import org.apache.tuscany.model.assembly.Interface;
-import org.apache.tuscany.model.types.InterfaceType;
-import org.apache.tuscany.model.types.OperationType;
-import org.apache.tuscany.model.types.java.JavaOperationType;
 
 /**
  * 
@@ -76,26 +74,22 @@
         channel = ctx.getDeliveryChannel();
         // Get the target service
         ConfiguredReference referenceValue = entryPoint.getConfiguredReference();
-        ConfiguredService targetServiceEndpoint = referenceValue.getConfiguredServices().get(0);
+        ConfiguredService targetServiceEndpoint = referenceValue.getTargetConfiguredServices().get(0);
         // Create a proxy
         ProxyFactory proxyFactory = (ProxyFactory) targetServiceEndpoint.getProxyFactory();
         proxy = proxyFactory.createProxy();
         // Get the business interface
-        Interface targetInterface = targetServiceEndpoint.getService().getInterfaceContract();
-        InterfaceType targetInterfaceType = targetInterface.getInterfaceType();
+        Class serviceInterface = targetServiceEndpoint.getService().getServiceContract().getInterface();
         List<Class> classes = new ArrayList<Class>();
         methodMap = new HashMap<Class, Method>();
-        for (OperationType oper : targetInterfaceType.getOperationTypes()) {
-        	if (oper instanceof JavaOperationType) {
-        		Method mth = ((JavaOperationType) oper).getJavaMethod();
-        		Class[] params = mth.getParameterTypes();
-        		if (params.length != 1) {
-        			throw new IllegalStateException("Supports only methods with one parameter");
-        		}
-        		methodMap.put(params[0], mth);
-        		classes.add(mth.getReturnType());
-        		classes.add(params[0]);
-        	}
+        for (Method mth : serviceInterface.getMethods()) {
+    		Class[] params = mth.getParameterTypes();
+    		if (params.length != 1) {
+    			throw new IllegalStateException("Supports only methods with one parameter");
+    		}
+    		methodMap.put(params[0], mth);
+    		classes.add(mth.getReturnType());
+    		classes.add(params[0]);
         }
         jaxbContext = JAXBContext.newInstance(classes.toArray(new Class[0]));
 	}
@@ -115,8 +109,6 @@
 		if (exchange.getStatus() == ExchangeStatus.DONE) {
 			return;
 		} else if (exchange.getStatus() == ExchangeStatus.ERROR) {
-			exchange.setStatus(ExchangeStatus.DONE);
-			channel.send(exchange);
 			return;
 		}
 		Object input = jaxbContext.createUnmarshaller().unmarshal(exchange.getMessage("in").getContent());
@@ -127,15 +119,19 @@
 		boolean oneWay = method.getReturnType() == null;
 		Object output;
 		try {
-			output = method.invoke(proxy, new Object[] { input });
-		} catch (InvocationTargetException e) {
-			if (e.getCause() instanceof Exception) {
-				throw (Exception) e.getCause();
-			} else if (e.getCause() instanceof Error) {
-				throw (Error) e.getCause();
-			} else {
-				throw new RuntimeException(e.getCause());
-			}
+            EntryPointContext entryPointContext = (EntryPointContext) ((ScaServiceUnit) serviceUnit).getTuscanyRuntime().getModuleContext().getContext(entryPoint.getName());
+            InvocationHandler handler = (InvocationHandler) entryPointContext.getImplementationInstance();
+			output = handler.invoke(null, method, new Object[] { input });
+        } catch (UndeclaredThrowableException e) {
+            throw e;
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Error e) {
+            throw e;
+        } catch (Exception e) {
+            throw e;
+		} catch (Throwable e) {
+			throw new RuntimeException(e);
 		}
 		if (oneWay) {
 			exchange.setStatus(ExchangeStatus.DONE);

Modified: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaLifeCycle.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaLifeCycle.java?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaLifeCycle.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaLifeCycle.java Fri Mar 17 06:30:08 2006
@@ -15,10 +15,6 @@
  */
 package org.apache.servicemix.sca;
 
-import java.util.List;
-
-import org.apache.tuscany.common.discovery.util.ServiceProviderRegistry;
-import org.apache.tuscany.common.logging.LogProvider;
 import org.apache.servicemix.common.BaseComponent;
 import org.apache.servicemix.common.BaseLifeCycle;
 
@@ -26,9 +22,6 @@
 
 	public ScaLifeCycle(BaseComponent component) {
 		super(component);
-		List l = ServiceProviderRegistry.getInstance().getServiceProviders(LogProvider.class);
-		l.clear();
-		l.add(new CommonsLoggingLogProvider());
 	}
 
 }

Modified: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaServiceUnit.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaServiceUnit.java?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaServiceUnit.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/ScaServiceUnit.java Fri Mar 17 06:30:08 2006
@@ -22,33 +22,15 @@
 import java.util.Iterator;
 
 import javax.wsdl.Definition;
-import javax.wsdl.Port;
-import javax.wsdl.Service;
 import javax.wsdl.factory.WSDLFactory;
-import javax.xml.namespace.QName;
 
 import org.apache.servicemix.common.ServiceUnit;
-import org.apache.tuscany.common.resource.loader.ResourceLoader;
-import org.apache.tuscany.common.resource.loader.ResourceLoaderFactory;
-import org.apache.tuscany.core.runtime.EventContext;
-import org.apache.tuscany.core.runtime.TuscanyModuleComponentContext;
-import org.apache.tuscany.core.runtime.config.ConfigurationLoader;
-import org.apache.tuscany.core.runtime.config.impl.EMFConfigurationLoader;
-import org.apache.tuscany.core.runtime.impl.EventContextImpl;
-import org.apache.tuscany.core.runtime.impl.TuscanyModuleComponentContextImpl;
-import org.apache.tuscany.core.runtime.scopes.DefaultScopeStrategy;
-import org.apache.tuscany.core.runtime.webapp.TuscanyWebAppRuntime;
-import org.apache.tuscany.model.assembly.AssemblyFactory;
-import org.apache.tuscany.model.assembly.AssemblyModelContext;
+import org.apache.servicemix.sca.assembly.JbiBinding;
+import org.apache.servicemix.sca.tuscany.CommonsLoggingMonitorFactory;
+import org.apache.servicemix.sca.tuscany.TuscanyRuntime;
+import org.apache.tuscany.model.assembly.Binding;
 import org.apache.tuscany.model.assembly.EntryPoint;
 import org.apache.tuscany.model.assembly.Module;
-import org.apache.tuscany.model.assembly.ModuleComponent;
-import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl;
-import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl;
-import org.apache.tuscany.model.types.wsdl.WSDLTypeHelper;
-import org.osoa.sca.model.Binding;
-import org.osoa.sca.model.JbiBinding;
-import org.w3c.dom.Document;
 
 public class ScaServiceUnit extends ServiceUnit {
 
@@ -58,12 +40,14 @@
 		return SERVICE_UNIT.get();
 	}
 	
-	protected TuscanyWebAppRuntime tuscanyRuntime;
+	protected TuscanyRuntime tuscanyRuntime;
 	protected ClassLoader classLoader;
 	
 	public void init() throws Exception {
+        SERVICE_UNIT.set(this);
 		createScaRuntime();
 		createEndpoints();
+        SERVICE_UNIT.set(null);
 	}
 	
 	protected void createScaRuntime() throws Exception {
@@ -75,69 +59,27 @@
 		}
 		urls[urls.length - 1] = root.toURL();
 		classLoader = new URLClassLoader(urls, getClass().getClassLoader());
-        Thread.currentThread().setContextClassLoader(classLoader);
 		
-        ResourceLoader resourceLoader = ResourceLoaderFactory.getResourceLoader(classLoader);
-        AssemblyModelContext modelContext = new AssemblyModelContextImpl(resourceLoader);
-        ConfigurationLoader moduleComponentLoader = new EMFConfigurationLoader(modelContext);
-        ModuleComponent moduleComponent = moduleComponentLoader.loadModuleComponent(getName(), getName());
-        EventContext eventContext = new EventContextImpl();
-        DefaultScopeStrategy scopeStrategy = new DefaultScopeStrategy();
-        TuscanyModuleComponentContext moduleComponentContext = new TuscanyModuleComponentContextImpl(moduleComponent, eventContext, scopeStrategy, modelContext);
-        tuscanyRuntime = new TuscanyWebAppRuntime(moduleComponentContext);
+        tuscanyRuntime = new TuscanyRuntime(getName(), getRootPath(), classLoader, new CommonsLoggingMonitorFactory());
 	}
 	
 	protected void createEndpoints() throws Exception {
-        AssemblyFactory assemblyFactory = new AssemblyFactoryImpl();
-        TuscanyModuleComponentContext moduleComponentContext = tuscanyRuntime.getModuleComponentContext(); 
-        Module module = moduleComponentContext.getModuleComponent().getModuleImplementation();
+        Module module = tuscanyRuntime.getModuleComponent().getModuleImplementation();
         for (Iterator i = module.getEntryPoints().iterator(); i.hasNext();) {
             EntryPoint entryPoint = (EntryPoint) i.next();
             Binding binding = (Binding) entryPoint.getBindings().get(0);
             if (binding instanceof JbiBinding) {
                 JbiBinding jbiBinding = (JbiBinding) binding;
-                Definition definition = null;
-                Document description = null;
-                QName serviceName = null;
-                QName interfaceName = null;
-                String endpointName = null;
-                QName qname = assemblyFactory.createQName(jbiBinding.getPort());
-                if (qname != null) {
-                	try {
-	                    WSDLTypeHelper typeHelper = moduleComponentContext.getAssemblyModelContext().getWSDLTypeHelper();
-	                    definition = typeHelper.getWSDLDefinition(qname.getNamespaceURI());
-	                    for (Iterator itSvc = definition.getServices().values().iterator(); itSvc.hasNext();) {
-	                    	Service svc = (Service) itSvc.next();
-	                    	if (svc.getQName().getNamespaceURI().equals(qname.getNamespaceURI())) {
-	                    		for (Iterator itPort = svc.getPorts().values().iterator(); itPort.hasNext();) {
-	                    			Port port = (Port) itPort.next();
-	                    			if (port.getName().equals(qname.getLocalPart())) {
-	                    				serviceName = svc.getQName();
-	                    				endpointName = port.getName();
-	                    				interfaceName = port.getBinding().getPortType().getQName();
-	                    			}
-	                    		}
-	                    	}
-	                    }
-	                    javax.wsdl.Binding b = definition.getBinding(qname);
-	                    description = WSDLFactory.newInstance().newWSDLWriter().getDocument(definition);
-                	} catch (Exception e) {
-                		// TODO warn
-                	}
-                	if (serviceName == null) {
-                		serviceName = new QName(qname.getNamespaceURI(), entryPoint.getName());
-                	}
-                	if (endpointName == null) {
-                		endpointName = qname.getLocalPart();
-                	}
-                }
                 ScaEndpoint endpoint = new ScaEndpoint(entryPoint);
                 endpoint.setServiceUnit(this);
-                endpoint.setService(serviceName);
-                endpoint.setEndpoint(endpointName);
-                endpoint.setInterfaceName(interfaceName);
-                endpoint.setDefinition(definition);
-                endpoint.setDescription(description);
+                endpoint.setService(jbiBinding.getServiceName());
+                endpoint.setEndpoint(jbiBinding.getEndpointName());
+                endpoint.setInterfaceName(jbiBinding.getInterfaceName());
+                Definition definition = jbiBinding.getDefinition();
+                if (definition != null) {
+                    endpoint.setDefinition(definition);
+                    endpoint.setDescription(WSDLFactory.newInstance().newWSDLWriter().getDocument(definition));
+                }
                 addEndpoint(endpoint);
             }
         }
@@ -149,34 +91,20 @@
         }
 	}
 
-	public TuscanyWebAppRuntime getTuscanyRuntime() {
+	public TuscanyRuntime getTuscanyRuntime() {
 		return tuscanyRuntime;
 	}
 
 	@Override
 	public void start() throws Exception {
-		tuscanyRuntime.start();
-		try {
-			SERVICE_UNIT.set(this);
-			tuscanyRuntime.getModuleComponentContext().start();
-			tuscanyRuntime.getModuleComponentContext().fireEvent(EventContext.MODULE_START, null);
-		} finally {
-			tuscanyRuntime.stop();
-			SERVICE_UNIT.set(null);
-		}
+	    tuscanyRuntime.start();
 		super.start();
 	}
 
 	@Override
 	public void stop() throws Exception {
 		super.stop();
-		tuscanyRuntime.start();
-		try {
-			tuscanyRuntime.getModuleComponentContext().fireEvent(EventContext.MODULE_STOP, null);
-			tuscanyRuntime.getModuleComponentContext().stop();
-		} finally {
-			tuscanyRuntime.stop();
-		}
+		tuscanyRuntime.stop();
 	}
 
 }

Modified: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/JbiAssemblyFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/JbiAssemblyFactory.java?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/JbiAssemblyFactory.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/JbiAssemblyFactory.java Fri Mar 17 06:30:08 2006
@@ -16,7 +16,6 @@
 package org.apache.servicemix.sca.assembly;
 
 import org.apache.tuscany.model.assembly.AssemblyFactory;
-import org.osoa.sca.model.JbiBinding;
 
 /**
  * The <b>Factory</b> for the model.
@@ -24,13 +23,8 @@
 public interface JbiAssemblyFactory extends AssemblyFactory {
 
     /**
-     * Returns a new object of class '<em>ServiceMix Binding</em>'.
-     * <!-- begin-user-doc -->
-     * <!-- end-user-doc -->
-     *
-     * @return a new object of class '<em>ServiceMix Binding</em>'.
-     * @generated
+     * Returns a new JbiBinding
      */
     JbiBinding createJbiBinding();
 
-} //TWebServiceAssemblyFactory
+}

Modified: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/JbiBinding.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/JbiBinding.java?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/JbiBinding.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/JbiBinding.java Fri Mar 17 06:30:08 2006
@@ -15,11 +15,68 @@
  */
 package org.apache.servicemix.sca.assembly;
 
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.xml.namespace.QName;
+
 import org.apache.tuscany.model.assembly.Binding;
 
 public interface JbiBinding extends Binding {
 
-	void setPort(String port);
-	
-	String getPort();
+    /**
+     * Returns the URI of the WSDL port for this binding.
+     * @return the URI of the WSDL port for this binding
+     */
+    String getPortURI();
+
+    /**
+     * Set the URI of the WSDL port for this binding.
+     * @param portURI the URI of the WSDL port
+     */
+    void setPortURI(String portURI);
+    
+    /**
+     * Returns the service name. 
+     * @return the service name
+     */
+    QName getServiceName();
+    
+    /**
+     * Returns the endpoint name.
+     * @return the endpoint name
+     */
+    String getEndpointName();
+    
+    /**
+     * Returns the interface name.
+     * @returnthe interface name
+     */
+    QName getInterfaceName();
+    
+    /**
+     * Returns the WSDL definition containing the WSDL port.
+     * @return the WSDL definition containing the WSDL port
+     */
+    Definition getDefinition();
+
+    /**
+     * Returns the the WSDL service.
+     * @return the WSDL service
+     */
+    Service getService();
+    
+    /**
+     * Returns the WSDL port defining this binding.
+     * @return the WSDL port defining this binding
+     */
+    Port getPort();
+    
+    /**
+     * Returns the WSDL port type.
+     * @return the WSDL port type
+     */
+    PortType getPortType();
+    
 }

Modified: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiAssemblyFactoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiAssemblyFactoryImpl.java?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiAssemblyFactoryImpl.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiAssemblyFactoryImpl.java Fri Mar 17 06:30:08 2006
@@ -16,8 +16,8 @@
 package org.apache.servicemix.sca.assembly.impl;
 
 import org.apache.servicemix.sca.assembly.JbiAssemblyFactory;
+import org.apache.servicemix.sca.assembly.JbiBinding;
 import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl;
-import org.osoa.sca.model.JbiBinding;
 
 /**
  * An implementation of the model <b>Factory</b>.
@@ -31,11 +31,11 @@
         super();
     }
 
-    /**
-     * @see org.apache.servicemix.sca.assembly#createJbiBinding()
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.sca.assembly.JbiAssemblyFactory#createJbiBinding()
      */
     public JbiBinding createJbiBinding() {
         return new JbiBindingImpl();
     }
 
-} //WebServiceAssemblyFactoryImpl
+}

Modified: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiBindingImpl.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiBindingImpl.java?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiBindingImpl.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/assembly/impl/JbiBindingImpl.java Fri Mar 17 06:30:08 2006
@@ -15,17 +15,32 @@
  */
 package org.apache.servicemix.sca.assembly.impl;
 
+import java.util.List;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.xml.namespace.QName;
+
 import org.apache.servicemix.sca.assembly.JbiBinding;
 import org.apache.tuscany.model.assembly.AssemblyModelContext;
-import org.apache.tuscany.model.assembly.AssemblyModelVisitor;
-import org.apache.tuscany.model.assembly.impl.AssemblyModelVisitorHelperImpl;
+import org.apache.tuscany.model.assembly.impl.BindingImpl;
 
 /**
  * An implementation of the model object '<em><b>Web Service Binding</b></em>'.
  */
-public class JbiBindingImpl extends org.apache.servicemix.sca.assembly.sdo.impl.JbiBindingImpl implements JbiBinding {
+public class JbiBindingImpl extends BindingImpl implements JbiBinding {
+
+    private String portURI;
+    private QName serviceName;
+    private String endpointName;
+    private QName interfaceName;
+    private Definition definition;
+    private Service service;
+    private PortType portType;
+    private Port port;
 
-    private Object runtimeConfiguration;
 
     /**
      * Constructor
@@ -33,65 +48,116 @@
     protected JbiBindingImpl() {
     }
 
-    /**
-     * @see org.apache.tuscany.binding.axis.assembly.sdo.impl.JbiBindingImpl#getPort()
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.sca.assembly.JbiBinding#getPortURI()
      */
-    public String getPort() {
-        return super.getPort();
+    public String getPortURI() {
+        return portURI;
     }
 
-    /**
-     * @see org.apache.tuscany.binding.axis.assembly.sdo.impl.JbiBindingImpl#setPort(java.lang.String)
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.sca.assembly.JbiBinding#setPortURI(java.lang.String)
      */
-    public void setPort(String newPort) {
-        super.setPort(newPort);
+    public void setPortURI(String portURI) {
+        this.portURI = portURI;
     }
 
-    /**
-     * @see org.apache.tuscany.model.assembly.Binding#setURI(java.lang.String)
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.sca.assembly.JbiBinding#getServiceName()
      */
-    public void setURI(String value) {
-        super.setUri(value);
+    public QName getServiceName() {
+        return serviceName;
     }
 
-    /**
-     * @see org.apache.tuscany.model.assembly.Binding#getURI()
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.sca.assembly.JbiBinding#getEndpointName()
      */
-    public String getURI() {
-        return super.getUri();
+    public String getEndpointName() {
+        return endpointName;
     }
 
-    /**
-     * @see org.apache.tuscany.model.assembly.ConfiguredRuntimeObject#getRuntimeConfiguration()
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.sca.assembly.JbiBinding#getInterfaceName()
      */
-    public Object getRuntimeConfiguration() {
-        return runtimeConfiguration;
+    public QName getInterfaceName() {
+        return interfaceName;
     }
 
-    /**
-     * @see org.apache.tuscany.model.assembly.ConfiguredRuntimeObject#setRuntimeConfiguration(java.lang.Object)
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.sca.assembly.JbiBinding#getDefinition()
      */
-    public void setRuntimeConfiguration(Object configuration) {
-        this.runtimeConfiguration = configuration;
+    public Definition getDefinition() {
+        return definition;
     }
 
-    /**
-     * @see org.apache.tuscany.model.assembly.AssemblyModelObject#initialize(org.apache.tuscany.model.assembly.AssemblyModelContext)
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.sca.assembly.JbiBinding#getService()
      */
-    public void initialize(AssemblyModelContext modelContext) {
+    public Service getService() {
+        return service;
     }
 
-    /**
-     * @see org.apache.tuscany.model.assembly.AssemblyModelObject#freeze()
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.sca.assembly.JbiBinding#getPort()
      */
-    public void freeze() {
+    public Port getPort() {
+        return port;
     }
 
-    /**
-     * @see org.apache.tuscany.model.assembly.AssemblyModelObject#accept(org.apache.tuscany.model.assembly.AssemblyModelVisitor)
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.sca.assembly.JbiBinding#getPortType()
      */
-    public boolean accept(AssemblyModelVisitor visitor) {
-        return AssemblyModelVisitorHelperImpl.accept(this, visitor);
+    public PortType getPortType() {
+        return portType;
     }
 
-} //TWebServiceBindingImpl
+    /**
+     * @see org.apache.tuscany.model.assembly.impl.BindingImpl#initialize(org.apache.tuscany.model.assembly.AssemblyModelContext)
+     */
+    public void initialize(AssemblyModelContext modelContext) {
+        if (isInitialized())
+            return;
+        super.initialize(modelContext);
+
+        // Get the service name and endpoint name
+        String[] parts = split(portURI);
+        serviceName = new QName(parts[0], parts[1]);
+        endpointName = parts[2];
+        
+        // Load the WSDL definitions for the given namespace
+        List<Definition> definitions = modelContext.getAssemblyLoader().loadDefinitions(parts[0]);
+        if (definitions != null) {
+            for (Definition definition : definitions) {
+                Service service = definition.getService(serviceName);
+                if (service != null) {
+                    Port port = service.getPort(endpointName);
+                    if (port != null) {
+                        this.service = service;
+                        this.port = port;
+                        this.portType = port.getBinding().getPortType();
+                        this.interfaceName = portType.getQName();
+                        this.definition = definition;
+                        return;
+                    }
+                }
+            }
+        }
+    }
+
+    protected String[] split(String uri) {
+        char sep;
+        uri = uri.trim();
+        if (uri.indexOf('/') > 0) {
+            sep = '/';
+        } else {
+            sep = ':';
+        }
+        int idx1 = uri.lastIndexOf(sep);
+        int idx2 = uri.lastIndexOf(sep, idx1 - 1);
+        String epName = uri.substring(idx1 + 1);
+        String svcName = uri.substring(idx2 + 1, idx1);
+        String nsUri   = uri.substring(0, idx2);
+        return new String[] { nsUri, svcName, epName };
+    }
+    
+}

Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceBuilder.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceBuilder.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceBuilder.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.sca.builder;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.servicemix.sca.assembly.JbiBinding;
+import org.apache.servicemix.sca.config.ExternalJbiServiceContextFactory;
+import org.apache.servicemix.sca.handler.ExternalJbiServiceClient;
+import org.apache.tuscany.core.builder.BuilderException;
+import org.apache.tuscany.core.builder.ContextFactoryBuilder;
+import org.apache.tuscany.core.config.JavaIntrospectionHelper;
+import org.apache.tuscany.core.context.QualifiedName;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.apache.tuscany.core.invocation.InvocationConfiguration;
+import org.apache.tuscany.core.invocation.MethodHashMap;
+import org.apache.tuscany.core.invocation.ProxyConfiguration;
+import org.apache.tuscany.core.invocation.impl.InvokerInterceptor;
+import org.apache.tuscany.core.invocation.spi.ProxyFactory;
+import org.apache.tuscany.core.invocation.spi.ProxyFactoryFactory;
+import org.apache.tuscany.core.message.MessageFactory;
+import org.apache.tuscany.core.runtime.RuntimeContext;
+import org.apache.tuscany.core.system.annotation.Autowire;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
+import org.apache.tuscany.model.assembly.ConfiguredService;
+import org.apache.tuscany.model.assembly.ExternalService;
+import org.apache.tuscany.model.assembly.Service;
+import org.apache.tuscany.model.assembly.ServiceContract;
+import org.apache.tuscany.model.scdl.WebServiceBinding;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * Creates a <code>RuntimeConfigurationBuilder</code> for an external service configured with the {@link WebServiceBinding}
+ */
+@Scope("MODULE")
+public class ExternalJbiServiceBuilder implements ContextFactoryBuilder {
+
+    private RuntimeContext runtimeContext;
+
+    private ProxyFactoryFactory proxyFactoryFactory;
+
+    private MessageFactory messageFactory;
+
+    private ContextFactoryBuilder policyBuilder;
+
+    public ExternalJbiServiceBuilder() {
+    }
+
+    @Init(eager = true)
+    public void init() {
+        runtimeContext.addBuilder(this);
+    }
+
+    /**
+     * @param runtimeContext The runtimeContext to set.
+     */
+    @Autowire
+    public void setRuntimeContext(RuntimeContext runtimeContext) {
+        this.runtimeContext = runtimeContext;
+    }
+
+    /**
+     * Sets the factory used to construct proxies implmementing the business interface required by a reference
+     */
+    @Autowire
+    public void setProxyFactoryFactory(ProxyFactoryFactory factory) {
+        this.proxyFactoryFactory = factory;
+    }
+
+    /**
+     * Sets the factory used to construct invocation messages
+     * 
+     * @param msgFactory
+     */
+    @Autowire
+    public void setMessageFactory(MessageFactory msgFactory) {
+        this.messageFactory = msgFactory;
+    }
+
+    /**
+     * Sets a builder responsible for creating source-side and target-side invocation chains for a reference. The
+     * reference builder may be hierarchical, containing other child reference builders that operate on specific
+     * metadata used to construct and invocation chain.
+     * 
+     * @see org.apache.tuscany.core.builder.impl.HierarchicalBuilder
+     */
+    public void setPolicyBuilder(ContextFactoryBuilder builder) {
+        policyBuilder = builder;
+    }
+
+    public void build(AssemblyModelObject object) throws BuilderException {
+        if (!(object instanceof ExternalService)) {
+            return;
+        }
+        ExternalService externalService = (ExternalService) object;
+        if (externalService.getBindings().size() < 1 || !(externalService.getBindings().get(0) instanceof JbiBinding)) {
+            return;
+        }
+
+        ExternalJbiServiceClient externalJbiServiceClient = new ExternalJbiServiceClient(externalService);
+        ExternalJbiServiceContextFactory config = new ExternalJbiServiceContextFactory(externalService.getName(), new SingletonObjectFactory<ExternalJbiServiceClient>(externalJbiServiceClient));
+
+        ConfiguredService configuredService = externalService.getConfiguredService();
+        Service service = configuredService.getService();
+        ServiceContract serviceContract = service.getServiceContract();
+        Map<Method, InvocationConfiguration> iConfigMap = new MethodHashMap();
+        ProxyFactory proxyFactory = proxyFactoryFactory.createProxyFactory();
+        Set<Method> javaMethods = JavaIntrospectionHelper.getAllUniqueMethods(serviceContract.getInterface());
+        for (Method method : javaMethods) {
+            InvocationConfiguration iConfig = new InvocationConfiguration(method);
+            iConfigMap.put(method, iConfig);
+        }
+        QualifiedName qName = new QualifiedName(externalService.getName() + "/" + service.getName());
+        ProxyConfiguration pConfiguration = new ProxyConfiguration(qName, iConfigMap, serviceContract.getInterface().getClassLoader(), messageFactory);
+        proxyFactory.setBusinessInterface(serviceContract.getInterface());
+        proxyFactory.setProxyConfiguration(pConfiguration);
+        config.addTargetProxyFactory(service.getName(), proxyFactory);
+        configuredService.setProxyFactory(proxyFactory);
+        if (policyBuilder != null) {
+            // invoke the reference builder to handle additional policy metadata
+            policyBuilder.build(configuredService);
+        }
+        // add tail interceptor
+        for (InvocationConfiguration iConfig : (Collection<InvocationConfiguration>) iConfigMap.values()) {
+            iConfig.addTargetInterceptor(new InvokerInterceptor());
+        }
+
+        externalService.getConfiguredService().setContextFactory(config);
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceWireBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceWireBuilder.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceWireBuilder.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/ExternalJbiServiceWireBuilder.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.sca.builder;
+
+import org.apache.servicemix.sca.config.ExternalJbiServiceContextFactory;
+import org.apache.servicemix.sca.handler.ExternalJbiServiceTargetInvoker;
+import org.apache.tuscany.core.builder.BuilderConfigException;
+import org.apache.tuscany.core.builder.WireBuilder;
+import org.apache.tuscany.core.context.ScopeContext;
+import org.apache.tuscany.core.invocation.InvocationConfiguration;
+import org.apache.tuscany.core.invocation.spi.ProxyFactory;
+import org.apache.tuscany.core.runtime.RuntimeContext;
+import org.apache.tuscany.core.system.annotation.Autowire;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("MODULE")
+public class ExternalJbiServiceWireBuilder implements WireBuilder {
+
+    private RuntimeContext runtimeContext;
+
+    /**
+     * Constructs a new ExternalWebServiceWireBuilder.
+     */
+    public ExternalJbiServiceWireBuilder() {
+        super();
+    }
+
+    @Autowire
+    public void setRuntimeContext(RuntimeContext context) {
+        runtimeContext = context;
+    }
+
+    @Init(eager=true)
+    public void init() {
+        runtimeContext.addBuilder(this);
+    }
+
+    public void connect(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope, ScopeContext targetScopeContext) throws BuilderConfigException {
+        if (!(ExternalJbiServiceContextFactory.class.isAssignableFrom(targetType))) {
+            return;
+        }
+        for (InvocationConfiguration sourceInvocationConfig : sourceFactory.getProxyConfiguration().getInvocationConfigurations().values()) {
+            ExternalJbiServiceTargetInvoker invoker = new ExternalJbiServiceTargetInvoker(sourceFactory.getProxyConfiguration().getTargetName(), sourceInvocationConfig.getMethod(), targetScopeContext);
+            sourceInvocationConfig.setTargetInvoker(invoker);
+        }
+    }
+
+    public void completeTargetChain(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext)
+            throws BuilderConfigException {
+        //TODO implement
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/JbiServiceEntryPointBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/JbiServiceEntryPointBuilder.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/JbiServiceEntryPointBuilder.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/builder/JbiServiceEntryPointBuilder.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.sca.builder;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.servicemix.sca.assembly.JbiBinding;
+import org.apache.servicemix.sca.config.JbiServiceEntryPointContextFactory;
+import org.apache.tuscany.core.builder.BuilderException;
+import org.apache.tuscany.core.builder.ContextFactoryBuilder;
+import org.apache.tuscany.core.builder.impl.EntryPointContextFactory;
+import org.apache.tuscany.core.config.JavaIntrospectionHelper;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.QualifiedName;
+import org.apache.tuscany.core.invocation.Interceptor;
+import org.apache.tuscany.core.invocation.InvocationConfiguration;
+import org.apache.tuscany.core.invocation.InvocationRuntimeException;
+import org.apache.tuscany.core.invocation.ProxyConfiguration;
+import org.apache.tuscany.core.invocation.TargetInvoker;
+import org.apache.tuscany.core.invocation.spi.ProxyFactory;
+import org.apache.tuscany.core.invocation.spi.ProxyFactoryFactory;
+import org.apache.tuscany.core.message.Message;
+import org.apache.tuscany.core.message.MessageFactory;
+import org.apache.tuscany.core.runtime.RuntimeContext;
+import org.apache.tuscany.core.system.annotation.Autowire;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
+import org.apache.tuscany.model.assembly.ConfiguredService;
+import org.apache.tuscany.model.assembly.EntryPoint;
+import org.apache.tuscany.model.assembly.Service;
+import org.apache.tuscany.model.assembly.ServiceContract;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("MODULE")
+public class JbiServiceEntryPointBuilder implements ContextFactoryBuilder<AggregateContext> {
+
+    private RuntimeContext runtimeContext;
+
+    private ProxyFactoryFactory proxyFactoryFactory;
+
+    private MessageFactory messageFactory;
+
+    private ContextFactoryBuilder policyBuilder;
+
+    public JbiServiceEntryPointBuilder() {
+    }
+
+    @Init(eager = true)
+    public void init() {
+        runtimeContext.addBuilder(this);
+    }
+
+    /**
+     * @param runtimeContext The runtimeContext to set.
+     */
+    @Autowire
+    public void setRuntimeContext(RuntimeContext runtimeContext) {
+        this.runtimeContext = runtimeContext;
+    }
+
+    /**
+     * Sets the factory used to construct proxies implmementing the business interface required by a reference
+     */
+    @Autowire
+    public void setProxyFactoryFactory(ProxyFactoryFactory factory) {
+        this.proxyFactoryFactory = factory;
+    }
+
+    /**
+     * Sets the factory used to construct invocation messages
+     * 
+     * @param msgFactory
+     */
+    @Autowire
+    public void setMessageFactory(MessageFactory msgFactory) {
+        this.messageFactory = msgFactory;
+    }
+
+    /**
+     * Sets a builder responsible for creating source-side and target-side invocation chains for a reference. The
+     * reference builder may be hierarchical, containing other child reference builders that operate on specific
+     * metadata used to construct and invocation chain.
+     * 
+     * @see org.apache.tuscany.core.builder.impl.HierarchicalBuilder
+     */
+    public void setPolicyBuilder(ContextFactoryBuilder builder) {
+        policyBuilder = builder;
+    }
+
+    public void build(AssemblyModelObject object) throws BuilderException {
+        if (!(object instanceof EntryPoint)) {
+            return;
+        }
+        EntryPoint entryPoint = (EntryPoint) object;
+        if (entryPoint.getBindings().size() < 1 || !(entryPoint.getBindings().get(0) instanceof JbiBinding)) {
+            return;
+        }
+
+        EntryPointContextFactory config = new JbiServiceEntryPointContextFactory(entryPoint.getName(), entryPoint.getConfiguredService().getService().getName(), messageFactory);
+
+        ConfiguredService configuredService = entryPoint.getConfiguredService();
+        Service service = configuredService.getService();
+        ServiceContract serviceContract = service.getServiceContract();
+        Map<Method, InvocationConfiguration> iConfigMap = new HashMap<Method, InvocationConfiguration>();
+        ProxyFactory proxyFactory = proxyFactoryFactory.createProxyFactory();
+        Set<Method> javaMethods = JavaIntrospectionHelper.getAllUniqueMethods(serviceContract.getInterface());
+        for (Method method : javaMethods) {
+            InvocationConfiguration iConfig = new InvocationConfiguration(method);
+            iConfigMap.put(method, iConfig);
+        }
+        QualifiedName qName = new QualifiedName(entryPoint.getConfiguredReference().getTargetConfiguredServices().get(0).getAggregatePart().getName() + "/" + service.getName());
+        ProxyConfiguration pConfiguration = new ProxyConfiguration(qName, iConfigMap, serviceContract.getInterface().getClassLoader(), messageFactory);
+        proxyFactory.setBusinessInterface(serviceContract.getInterface());
+        proxyFactory.setProxyConfiguration(pConfiguration);
+        config.addSourceProxyFactory(service.getName(), proxyFactory);
+        configuredService.setProxyFactory(proxyFactory);
+        if (policyBuilder != null) {
+            // invoke the reference builder to handle additional policy metadata
+            policyBuilder.build(configuredService);
+        }
+        // add tail interceptor
+        for (InvocationConfiguration iConfig : (Collection<InvocationConfiguration>) iConfigMap.values()) {
+            iConfig.addTargetInterceptor(new EntryPointInvokerInterceptor());
+        }
+        entryPoint.getConfiguredReference().setContextFactory(config);
+    }
+    
+    //FIXME same as the InvokerInterceptor except that it doesn't throw an exception in setNext
+    // For some reason another InvokerInterceptor is added after this one, need Jim to look into it
+    // and figure out why.
+    public class EntryPointInvokerInterceptor implements Interceptor {
+        
+        public EntryPointInvokerInterceptor() {
+        }
+
+        public Message invoke(Message msg) throws InvocationRuntimeException {
+            TargetInvoker invoker = msg.getTargetInvoker();
+            if (invoker == null) {
+                throw new InvocationRuntimeException("No target invoker specified on message");
+            }
+            return invoker.invoke(msg);
+        }
+
+        public void setNext(Interceptor next) {
+        }
+
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/ExternalJbiServiceContextFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/ExternalJbiServiceContextFactory.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/ExternalJbiServiceContextFactory.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/ExternalJbiServiceContextFactory.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.sca.config;
+
+import org.apache.tuscany.core.builder.ObjectFactory;
+import org.apache.tuscany.core.builder.impl.BaseExternalServiceContextFactory;
+
+public class ExternalJbiServiceContextFactory extends BaseExternalServiceContextFactory {
+
+    public ExternalJbiServiceContextFactory(String name, ObjectFactory objectFactory) {
+        super(name, objectFactory);
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/JbiServiceEntryPointContextFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/JbiServiceEntryPointContextFactory.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/JbiServiceEntryPointContextFactory.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/config/JbiServiceEntryPointContextFactory.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.sca.config;
+
+import org.apache.tuscany.core.builder.impl.EntryPointContextFactory;
+import org.apache.tuscany.core.message.MessageFactory;
+
+public class JbiServiceEntryPointContextFactory extends EntryPointContextFactory {
+
+    public JbiServiceEntryPointContextFactory(String name, String referenceName, MessageFactory msgFactory) {
+        super(name, referenceName, msgFactory);
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceClient.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceClient.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceClient.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceClient.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.sca.handler;
+
+import java.io.ByteArrayOutputStream;
+import java.lang.reflect.Method;
+
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.bind.JAXBContext;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.sca.ScaServiceUnit;
+import org.apache.servicemix.sca.assembly.JbiBinding;
+import org.apache.tuscany.model.assembly.ExternalService;
+
+public class ExternalJbiServiceClient {
+
+    private ExternalService externalService;
+    
+    private JbiBinding jbiBinding;
+
+    private ScaServiceUnit serviceUnit;
+
+    /**
+     * Constructs a new ExternalWebServiceClient.
+     * 
+     * @param externalService
+     * @param wsBinding
+     */
+    public ExternalJbiServiceClient(ExternalService externalService) {
+        this.serviceUnit = ScaServiceUnit.getCurrentScaServiceUnit();
+        this.externalService = externalService;
+        this.jbiBinding = (JbiBinding) this.externalService.getBindings().get(0);
+    }
+
+    /**
+     * Invoke an operation on the external Web service.
+     * 
+     * @param method
+     * @param args
+     * @return
+     */
+    public Object invoke(Method method, Object[] args) {
+        if (args == null || args.length != 1) {
+            throw new IllegalStateException("args should have exactly one object");
+        }
+        try {
+            Object payload = args[0];
+            Class inputClass = method.getParameterTypes()[0];
+            Class outputClass = method.getReturnType();
+            JAXBContext context = JAXBContext.newInstance(inputClass, outputClass);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            context.createMarshaller().marshal(payload, baos);
+            
+            DeliveryChannel channel = serviceUnit.getComponent().getComponentContext().getDeliveryChannel();
+            // TODO: in-only case ?
+            // TODO: interface based routing ?
+            // TODO: explicit endpoint selection ?
+            InOut inout = channel.createExchangeFactory().createInOutExchange();
+            inout.setService(jbiBinding.getServiceName());
+            NormalizedMessage in = inout.createMessage();
+            inout.setInMessage(in);
+            in.setContent(new StringSource(baos.toString()));
+            boolean sent = channel.sendSync(inout);
+            // TODO: check for error ?
+            NormalizedMessage out = inout.getOutMessage();
+            Object response = context.createUnmarshaller().unmarshal(out.getContent());
+            inout.setStatus(ExchangeStatus.DONE);
+            channel.send(inout);
+            return response;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceTargetInvoker.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceTargetInvoker.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceTargetInvoker.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/handler/ExternalJbiServiceTargetInvoker.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.sca.handler;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.core.context.ExternalServiceContext;
+import org.apache.tuscany.core.context.InstanceContext;
+import org.apache.tuscany.core.context.QualifiedName;
+import org.apache.tuscany.core.context.ScopeContext;
+import org.apache.tuscany.core.context.TargetException;
+import org.apache.tuscany.core.invocation.Interceptor;
+import org.apache.tuscany.core.invocation.TargetInvoker;
+import org.apache.tuscany.core.message.Message;
+
+public class ExternalJbiServiceTargetInvoker implements TargetInvoker {
+
+    private QualifiedName serviceName;
+    private String esName;
+    private Method method;
+    private ScopeContext container;
+
+    private ExternalServiceContext context;
+
+    /**
+     * Constructs a new ExternalJbiServiceTargetInvoker.
+     * @param esName
+     * @param container
+     */
+    public ExternalJbiServiceTargetInvoker(QualifiedName serviceName, Method method, ScopeContext container) {
+        assert (serviceName != null) : "No service name specified";
+        assert (method != null) : "No method specified";
+        assert (container != null) : "No scope container specified";
+        this.serviceName = serviceName;
+        this.esName = serviceName.getPartName();
+        this.method = method;
+        this.container = container;
+    }
+
+    public Object invokeTarget(Object payload) throws InvocationTargetException {
+        if (context == null) {
+            InstanceContext iContext = container.getContext(esName);
+            if (!(iContext instanceof ExternalServiceContext)) {
+                TargetException te = new TargetException("Unexpected target context type");
+                te.setIdentifier(iContext.getClass().getName());
+                te.addContextName(iContext.getName());
+                throw te;
+            }
+            context = (ExternalServiceContext) iContext;
+        }
+        ExternalJbiServiceClient client = (ExternalJbiServiceClient) context.getImplementationInstance(true);
+        if (payload != null) {
+            return client.invoke(method, (Object[])payload);
+        } else {
+            return client.invoke(method, null);
+        }
+    }
+
+    public boolean isCacheable() {
+        return false;
+    }
+
+    public Message invoke(Message msg) {
+        try {
+            Object resp = invokeTarget(msg.getBody());
+            msg.setBody(resp);
+        } catch (InvocationTargetException e) {
+            msg.setBody(e.getCause());
+        } catch (Throwable e) {
+            msg.setBody(e);
+        }
+        return msg;
+    }
+
+    public void setNext(Interceptor next) {
+        throw new UnsupportedOperationException();
+    }
+
+    public Object clone() {
+        try {
+            ExternalJbiServiceTargetInvoker invoker = (ExternalJbiServiceTargetInvoker) super.clone();
+            invoker.container = container;
+            invoker.context = this.context;
+            invoker.esName = this.esName;
+            invoker.method = this.method;
+            invoker.serviceName = this.serviceName;
+            return invoker;
+        } catch (CloneNotSupportedException e) {
+            return null; // will not happen
+        }
+    }  
+    
+}

Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/loader/JbiBindingLoader.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/loader/JbiBindingLoader.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/loader/JbiBindingLoader.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/loader/JbiBindingLoader.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.sca.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.servicemix.sca.assembly.JbiAssemblyFactory;
+import org.apache.servicemix.sca.assembly.JbiBinding;
+import org.apache.servicemix.sca.assembly.impl.JbiAssemblyFactoryImpl;
+import org.apache.tuscany.common.resource.ResourceLoader;
+import org.apache.tuscany.core.config.ConfigurationLoadException;
+import org.apache.tuscany.core.loader.StAXElementLoader;
+import org.apache.tuscany.core.loader.StAXLoaderRegistry;
+import org.apache.tuscany.core.system.annotation.Autowire;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+
+@Scope("MODULE")
+public class JbiBindingLoader implements StAXElementLoader<JbiBinding>{
+
+    public static final QName BINDING_JBI = new QName("http://www.osoa.org/xmlns/sca/0.9", "binding.jbi");
+
+    private static final JbiAssemblyFactory jbiFactory = new JbiAssemblyFactoryImpl();
+
+    private StAXLoaderRegistry registry;
+
+    @Autowire
+    public void setRegistry(StAXLoaderRegistry registry) {
+        this.registry = registry;
+    }
+
+    @Init(eager = true)
+    public void start() {
+        registry.registerLoader(this);
+    }
+
+    @Destroy
+    public void stop() {
+        registry.unregisterLoader(this);
+    }
+
+    public QName getXMLType() {
+        return BINDING_JBI;
+    }
+
+    public Class<JbiBinding> getModelType() {
+        return JbiBinding.class;
+    }
+
+    public JbiBinding load(XMLStreamReader reader, ResourceLoader resourceLoader) throws XMLStreamException, ConfigurationLoadException {
+        JbiBinding binding = jbiFactory.createJbiBinding();
+        binding.setURI(reader.getAttributeValue(null, "uri"));
+        binding.setPortURI(reader.getAttributeValue(null, "port"));
+        return binding;
+    }
+}

Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/BootstrapHelper.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/BootstrapHelper.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/BootstrapHelper.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/BootstrapHelper.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.sca.tuscany;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.tuscany.common.resource.ResourceLoader;
+import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
+import org.apache.tuscany.core.builder.ContextFactoryBuilder;
+import org.apache.tuscany.core.config.ConfigurationException;
+import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader;
+import org.apache.tuscany.core.config.impl.ModuleComponentConfigurationLoaderImpl;
+import org.apache.tuscany.core.config.impl.StAXModuleComponentConfigurationLoaderImpl;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.EventContext;
+import org.apache.tuscany.core.context.SystemAggregateContext;
+import org.apache.tuscany.core.loader.StAXLoaderRegistry;
+import org.apache.tuscany.core.loader.StAXUtil;
+import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl;
+import org.apache.tuscany.core.system.builder.SystemContextFactoryBuilder;
+import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder;
+import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder;
+import org.apache.tuscany.core.system.loader.SystemSCDLModelLoader;
+import org.apache.tuscany.model.assembly.AssemblyFactory;
+import org.apache.tuscany.model.assembly.AssemblyModelContext;
+import org.apache.tuscany.model.assembly.ModuleComponent;
+import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl;
+import org.apache.tuscany.model.assembly.loader.AssemblyModelLoader;
+import org.apache.tuscany.model.scdl.loader.SCDLModelLoader;
+import org.apache.tuscany.model.scdl.loader.impl.SCDLAssemblyModelLoaderImpl;
+
+public class BootstrapHelper {
+    
+    /**
+     * Returns a default AssemblyModelContext.
+     *
+     * @param classLoader the classloader to use for application artifacts
+     * @return a default AssemblyModelContext
+     */
+    public static AssemblyModelContext getModelContext(ClassLoader classLoader) {
+        // Create an assembly model factory
+        AssemblyFactory modelFactory = new SystemAssemblyFactoryImpl();
+
+        // Create a default assembly model loader
+        List<SCDLModelLoader> scdlLoaders = new ArrayList<SCDLModelLoader>();
+        scdlLoaders.add(new SystemSCDLModelLoader());
+        AssemblyModelLoader modelLoader = new SCDLAssemblyModelLoaderImpl(scdlLoaders);
+
+        // Create a resource loader from the supplied classloader
+        ResourceLoader resourceLoader = new ResourceLoaderImpl(classLoader);
+
+        // Create an assembly model context
+        return new AssemblyModelContextImpl(modelFactory, modelLoader, resourceLoader);
+    }
+
+    /**
+     * Returns a default list of configuration builders.
+     *
+     * @return a default list of configuration builders
+     */
+    public static List<ContextFactoryBuilder> getBuilders() {
+        List<ContextFactoryBuilder> configBuilders = new ArrayList<ContextFactoryBuilder>();
+        configBuilders.add((new SystemContextFactoryBuilder()));
+        configBuilders.add(new SystemEntryPointBuilder());
+        configBuilders.add(new SystemExternalServiceBuilder());
+        return configBuilders;
+    }
+
+    private static final boolean useStax = true;
+    private static final String SYSTEM_LOADER_COMPONENT = "tuscany.loader";
+
+    /**
+     * Returns the default module configuration loader.
+     *
+     * @param systemContext the runtime's system context
+     * @param modelContext  the model context the loader will use
+     * @return the default module configuration loader
+     */
+    public static ModuleComponentConfigurationLoader getConfigurationLoader(SystemAggregateContext systemContext, AssemblyModelContext modelContext) throws ConfigurationException {
+        if (useStax) {
+            // Bootstrap the StAX loader module
+            bootstrapStaxLoader(systemContext, modelContext);
+            return new StAXModuleComponentConfigurationLoaderImpl(modelContext, XMLInputFactory.newInstance(), systemContext.resolveInstance(StAXLoaderRegistry.class));
+        } else {
+            return new ModuleComponentConfigurationLoaderImpl(modelContext);
+        }
+    }
+
+    private static AggregateContext bootstrapStaxLoader(SystemAggregateContext systemContext, AssemblyModelContext modelContext) throws ConfigurationException {
+        AggregateContext loaderContext = (AggregateContext) systemContext.getContext(SYSTEM_LOADER_COMPONENT);
+        if (loaderContext == null) {
+            ModuleComponent loaderComponent = StAXUtil.bootstrapLoader(SYSTEM_LOADER_COMPONENT, modelContext);
+            loaderContext = registerModule(systemContext, loaderComponent);
+            loaderContext.fireEvent(EventContext.MODULE_START, null);
+        }
+        return loaderContext;
+    }
+
+    public static AggregateContext registerModule(AggregateContext parent, ModuleComponent component) throws ConfigurationException {
+        // register the component
+        parent.registerModelObject(component);
+
+        // Get the aggregate context representing the component
+        return (AggregateContext) parent.getContext(component.getName());
+    }
+}
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/CommonsLoggingMonitorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/CommonsLoggingMonitorFactory.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/CommonsLoggingMonitorFactory.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/CommonsLoggingMonitorFactory.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.sca.tuscany;
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tuscany.common.monitor.MonitorFactory;
+
+public class CommonsLoggingMonitorFactory implements MonitorFactory {
+
+    private final Map<Class<?>, WeakReference<?>> proxies = new WeakHashMap<Class<?>, WeakReference<?>>();
+    
+    public CommonsLoggingMonitorFactory() {
+    }
+
+    public <T> T getMonitor(Class<T> monitorInterface) {
+        T proxy = getCachedMonitor(monitorInterface);
+        if (proxy == null) {
+            proxy = createMonitor(monitorInterface);
+            proxies.put(monitorInterface, new WeakReference<T>(proxy));
+        }
+        return proxy;
+    }
+
+    private <T>T getCachedMonitor(Class<T> monitorInterface) {
+        WeakReference<T> ref = (WeakReference<T>) proxies.get(monitorInterface);
+        return (ref != null) ? ref.get() : null;
+    }
+
+    private <T>T createMonitor(Class<T> monitorInterface) {
+        String className = monitorInterface.getName();
+        Log logger = LogFactory.getLog(className);
+        InvocationHandler handler = new LoggingHandler(logger);
+        return (T) Proxy.newProxyInstance(monitorInterface.getClassLoader(), new Class<?>[]{monitorInterface}, handler);
+    }
+
+    private static final class LoggingHandler implements InvocationHandler {
+        private final Log logger;
+
+        public LoggingHandler(Log logger) {
+            this.logger = logger;
+        }
+
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+            String sourceMethod = method.getName();
+            if (logger.isDebugEnabled()) {
+                // if the only argument is a Throwable use the special logger for it
+                if (args != null && args.length == 1 && args[0] instanceof Throwable) {
+                    logger.debug(sourceMethod, (Throwable) args[0]);
+                } else {
+                    StringBuilder sb = new StringBuilder();
+                    sb.append(sourceMethod);
+                    sb.append("(");
+                    for (int i = 0; i < args.length; i++) {
+                        if (i > 0) {
+                            sb.append(", ");
+                        }
+                        sb.append(args[i]);
+                    }
+                    sb.append(")");
+                    logger.debug(sb.toString());
+                }
+            }
+            return null;
+        }
+    }
+}



Mime
View raw message