servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r641065 - in /servicemix/smx3/trunk: ./ common/servicemix-common/ common/servicemix-common/src/main/java/org/apache/servicemix/common/ common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ core/servicemix-core/ core/ser...
Date Tue, 25 Mar 2008 22:55:43 GMT
Author: gnodet
Date: Tue Mar 25 15:55:37 2008
New Revision: 641065

URL: http://svn.apache.org/viewvc?rev=641065&view=rev
Log:
SM-1289, SM-1290: get rid of xbean-server / xbean-kernel, inject component and component context into the spring bean factory

Added:
    servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/
    servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java
Removed:
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpointComponentContext.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeXBeanDeployer.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/EndpointComponentContext.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/EndpointDeliveryChannel.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181XBeanDeployer.java
Modified:
    servicemix/smx3/trunk/common/servicemix-common/pom.xml
    servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java
    servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/BaseComponent.java
    servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
    servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointComponentContext.java
    servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointDeliveryChannel.java
    servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java
    servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
    servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java
    servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java
    servicemix/smx3/trunk/core/servicemix-core/pom.xml
    servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/Main.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeComponent.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Component.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java
    servicemix/smx3/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerXBeanDeployer.java
    servicemix/smx3/trunk/distributions/apache-servicemix/src/main/assembly/bin.xml
    servicemix/smx3/trunk/pom.xml

Modified: servicemix/smx3/trunk/common/servicemix-common/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/common/servicemix-common/pom.xml?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/common/servicemix-common/pom.xml (original)
+++ servicemix/smx3/trunk/common/servicemix-common/pom.xml Tue Mar 25 15:55:37 2008
@@ -49,11 +49,6 @@
       <scope>provided</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.xbean</groupId>
-      <artifactId>xbean-server</artifactId>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring</artifactId>
       <scope>provided</scope>

Modified: servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java (original)
+++ servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java Tue Mar 25 15:55:37 2008
@@ -399,18 +399,30 @@
         return new ExecutorFactoryImpl();
     }
 
-    protected ExecutorFactory findExecutorFactory() {
-        // If inside ServiceMix, retrieve its executor factory
+    public Object getSmx3Container() {
         try {
             Method getContainerMth = context.getClass().getMethod("getContainer", new Class[0]);
             Object container = getContainerMth.invoke(context, new Object[0]);
-            Method getWorkManagerMth = container.getClass().getMethod("getExecutorFactory", new Class[0]);
-            return (ExecutorFactory) getWorkManagerMth.invoke(container, new Object[0]);
+            return container;
         } catch (Throwable t) {
             if (logger.isDebugEnabled()) {
-                logger.debug("JBI container is not ServiceMix. Will create our own ExecutorFactory", t);
+                logger.debug("JBI container is not ServiceMix 3 (" + t + ")");
             }
         }
+        return null;
+    }
+
+    protected ExecutorFactory findExecutorFactory() {
+        // If inside ServiceMix, retrieve its executor factory
+        try {
+            Object container = getSmx3Container();
+            if (container != null) {
+                Method getWorkManagerMth = container.getClass().getMethod("getExecutorFactory", new Class[0]);
+                return (ExecutorFactory) getWorkManagerMth.invoke(container, new Object[0]);
+            }
+        } catch (Throwable t) {
+            // Ignore
+        }
         // TODO: should look in jndi for an existing ExecutorFactory
         return null;
     }
@@ -535,8 +547,10 @@
             if (logger.isDebugEnabled()) {
                 logger.debug("Retrieved correlation id: " + correlationID);
             }
+            EndpointDeliveryChannel.setEndpoint(ep);
             processor.process(exchange);
         } finally {
+            EndpointDeliveryChannel.setEndpoint(null);
             Thread.currentThread().setContextClassLoader(oldCl);
             // Clean the threadlocal variable
             correlationId.set(null);

Modified: servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/BaseComponent.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/BaseComponent.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/BaseComponent.java (original)
+++ servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/BaseComponent.java Tue Mar 25 15:55:37 2008
@@ -190,6 +190,10 @@
         return lifeCycle.getExecutor();
     }
 
+    public Object getSmx3Container() {
+        return lifeCycle.getSmx3Container();
+    }
+
     public void sendConsumerExchange(MessageExchange exchange, Endpoint endpoint) throws MessagingException {
         lifeCycle.sendConsumerExchange(exchange, endpoint);
     }

Modified: servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java (original)
+++ servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java Tue Mar 25 15:55:37 2008
@@ -21,6 +21,7 @@
 
 import javax.jbi.management.DeploymentException;
 import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.MessageExchange.Role;
 import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
@@ -118,6 +119,10 @@
     public boolean isExchangeOkay(MessageExchange exchange) {
         // TODO: We could check the MEP here 
         return true;
+    }
+
+    public void prepareConsumerExchange(MessageExchange exchange) throws MessagingException {
+        getServiceUnit().getComponent().prepareConsumerExchange(exchange, this);
     }
 
     public abstract void activate() throws Exception;

Modified: servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointComponentContext.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointComponentContext.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointComponentContext.java (original)
+++ servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointComponentContext.java Tue Mar 25 15:55:37 2008
@@ -42,7 +42,11 @@
         this.endpoint = endpoint;
         this.context = endpoint.getServiceUnit().getComponent().getComponentContext();
     }
-    
+
+    public EndpointComponentContext(ComponentContext context) {
+        this.context = context;
+    }
+
     public Endpoint getEndpoint() {
         return endpoint;
     }
@@ -69,7 +73,11 @@
 
     public DeliveryChannel getDeliveryChannel() throws MessagingException {
         if (this.channel == null) {
-            this.channel = new EndpointDeliveryChannel(endpoint);
+            if (endpoint != null) {
+                this.channel = new EndpointDeliveryChannel(endpoint);
+            } else {
+                this.channel = new EndpointDeliveryChannel(context);
+            }
         }
         return this.channel;
     }

Modified: servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointDeliveryChannel.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointDeliveryChannel.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointDeliveryChannel.java (original)
+++ servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointDeliveryChannel.java Tue Mar 25 15:55:37 2008
@@ -16,12 +16,15 @@
  */
 package org.apache.servicemix.common;
 
+import java.util.List;
+
+import javax.jbi.component.ComponentContext;
 import javax.jbi.messaging.DeliveryChannel;
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessageExchange.Role;
 import javax.jbi.messaging.MessageExchangeFactory;
 import javax.jbi.messaging.MessagingException;
-import javax.jbi.messaging.MessageExchange.Role;
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.xml.namespace.QName;
 
@@ -35,14 +38,21 @@
  */
 public class EndpointDeliveryChannel implements DeliveryChannel {
 
+    private static final ThreadLocal<Endpoint> ENDPOINT_TLS = new ThreadLocal<Endpoint>();
+
     private final DeliveryChannel channel;
     private final Endpoint endpoint;
-    
+
     public EndpointDeliveryChannel(Endpoint endpoint) throws MessagingException {
         this.endpoint = endpoint;
         this.channel = endpoint.getServiceUnit().getComponent().getComponentContext().getDeliveryChannel();
     }
 
+    public EndpointDeliveryChannel(ComponentContext context) throws MessagingException {
+        this.endpoint = null;
+        this.channel = context.getDeliveryChannel();
+    }
+
     public MessageExchange accept() throws MessagingException {
         throw new UnsupportedOperationException();
     }
@@ -72,26 +82,35 @@
     }
 
     public void send(MessageExchange exchange) throws MessagingException {
-        if (exchange.getStatus() == ExchangeStatus.ACTIVE && exchange.getRole() == Role.CONSUMER) {
-            ServiceMixComponent comp = endpoint.getServiceUnit().getComponent();
-            comp.prepareConsumerExchange(exchange, endpoint);
-        }
+        prepareExchange(exchange);
         channel.send(exchange);
     }
 
     public boolean sendSync(MessageExchange exchange, long timeout) throws MessagingException {
-        if (exchange.getStatus() == ExchangeStatus.ACTIVE && exchange.getRole() == Role.CONSUMER) {
-            ServiceMixComponent comp = endpoint.getServiceUnit().getComponent();
-            comp.prepareConsumerExchange(exchange, endpoint);
-        }
+        prepareExchange(exchange);
         return channel.sendSync(exchange, timeout);
     }
 
     public boolean sendSync(MessageExchange exchange) throws MessagingException {
+        prepareExchange(exchange);
+        return channel.sendSync(exchange);
+    }
+
+    protected void prepareExchange(MessageExchange exchange) throws MessagingException {
         if (exchange.getStatus() == ExchangeStatus.ACTIVE && exchange.getRole() == Role.CONSUMER) {
-            ServiceMixComponent comp = endpoint.getServiceUnit().getComponent();
-            comp.prepareConsumerExchange(exchange, endpoint);
+            Endpoint ep = getEndpoint();
+            getEndpoint().prepareConsumerExchange(exchange);
         }
-        return channel.sendSync(exchange);
+    }
+
+    protected Endpoint getEndpoint() {
+        if (endpoint != null) {
+            return endpoint;
+        }
+        return ENDPOINT_TLS.get();
+    }
+
+    public static void setEndpoint(Endpoint endpoint) {
+        ENDPOINT_TLS.set(endpoint);
     }
 }

Modified: servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java (original)
+++ servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java Tue Mar 25 15:55:37 2008
@@ -54,6 +54,11 @@
     public ComponentContext getComponentContext();
 
     /**
+     * @return the servicemix 3 container if deployed into it
+     */
+    public Object getSmx3Container();
+
+    /**
      * @return Returns the name of the component
      */
     public String getComponentName();

Modified: servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java (original)
+++ servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java Tue Mar 25 15:55:37 2008
@@ -16,27 +16,31 @@
  */
 package org.apache.servicemix.common.xbean;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.jbi.management.DeploymentException;
+
 import org.apache.servicemix.common.AbstractDeployer;
+import org.apache.servicemix.common.BaseLifeCycle;
 import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.common.EndpointComponentContext;
 import org.apache.servicemix.common.ServiceMixComponent;
 import org.apache.servicemix.common.ServiceUnit;
 import org.apache.servicemix.jbi.container.JBIContainer;
 import org.apache.servicemix.jbi.framework.ComponentContextImpl;
-import org.apache.xbean.kernel.Kernel;
-import org.apache.xbean.kernel.KernelFactory;
-import org.apache.xbean.kernel.ServiceName;
-import org.apache.xbean.server.repository.FileSystemRepository;
-import org.apache.xbean.server.spring.loader.SpringLoader;
+import org.apache.xbean.spring.context.FileSystemXmlApplicationContext;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.core.io.FileSystemResource;
 
-import javax.jbi.component.ComponentContext;
-import javax.jbi.management.DeploymentException;
-import java.io.File;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
 public class AbstractXBeanDeployer extends AbstractDeployer {
 
     public AbstractXBeanDeployer(ServiceMixComponent component) {
@@ -62,11 +66,10 @@
      * @see org.apache.servicemix.common.Deployer#deploy(java.lang.String, java.lang.String)
      */
     public ServiceUnit deploy(String serviceUnitName, String serviceUnitRootPath) throws DeploymentException {
-        Kernel kernel = KernelFactory.newInstance().createKernel(component.getComponentName() + "/" + serviceUnitName);
+        AbstractXmlApplicationContext applicationContext = null;
         try {
             // Create service unit
             XBeanServiceUnit su = new XBeanServiceUnit();
-            su.setKernel(kernel);
             su.setComponent(component);
             su.setName(serviceUnitName);
             su.setRootPath(serviceUnitRootPath);
@@ -74,24 +77,27 @@
             ClassLoader classLoader = component.getClass().getClassLoader();
             Thread.currentThread().setContextClassLoader(classLoader);
 
-            SpringLoader springLoader = createSpringLoader();
-            springLoader.setKernel(kernel);
-            springLoader.setBaseDir(new File(serviceUnitRootPath));
-            springLoader.setXmlPreprocessors(getXmlPreProcessors(serviceUnitRootPath));
-            springLoader.setBeanFactoryPostProcessors(getBeanFactoryPostProcessors(serviceUnitRootPath));
-            
-            ServiceName configurationName = springLoader.load(getXBeanFile());
-            kernel.startService(configurationName);
-            su.setConfiguration(configurationName);
+            File baseDir = new File(serviceUnitRootPath);
+            String location = getXBeanFile();
+            applicationContext = createApplicationContext(serviceUnitRootPath);
+
+            for (Iterator iter = getBeanFactoryPostProcessors(serviceUnitRootPath).iterator(); iter.hasNext();) {
+                BeanFactoryPostProcessor processor = (BeanFactoryPostProcessor) iter.next();
+                applicationContext.addBeanFactoryPostProcessor(processor);
+            }
+
+            applicationContext.refresh();
+            su.setApplicationContext(applicationContext);
             // Use SU classloader
             Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
+            initApplicationContext(applicationContext);
+
             // Retrieve endpoints
-            List services = getServices(kernel);
-            if (services == null || services.size() == 0) {
+            Collection<Endpoint> endpoints = getServices(applicationContext);
+            if (endpoints != null || endpoints.size() == 0) {
                 throw failure("deploy", "No endpoints found", null);
             }
-            for (Iterator iter = services.iterator(); iter.hasNext();) {
-                Endpoint endpoint = (Endpoint) iter.next();
+            for (Endpoint endpoint : endpoints) {
                 endpoint.setServiceUnit(su);
                 validate(endpoint);
                 su.addEndpoint(endpoint);
@@ -101,10 +107,12 @@
             }
             return su;
         } catch (Throwable e) {
+            if (applicationContext != null) {
+                applicationContext.destroy();
+            }
             // There is a chance the thread context classloader has been changed by the xbean kernel,
             // so put back a good one
             Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-            kernel.destroy();
             if (e instanceof DeploymentException) {
                 throw ((DeploymentException) e);
             } else {
@@ -115,37 +123,57 @@
         }
     }
 
-    /**
-     * A factory method to allow derived classes to create alternative spring loaders
-     */
-    protected SpringLoader createSpringLoader() {
-        return new SpringLoader();
+    protected void initApplicationContext(AbstractXmlApplicationContext applicationContext) throws Exception {
     }
 
-    protected List getServices(Kernel kernel) throws DeploymentException {
-        return kernel.getServices(Endpoint.class);
+    protected Collection<Endpoint> getServices(AbstractXmlApplicationContext applicationContext) throws Exception {
+        return applicationContext.getBeansOfType(Endpoint.class).values();
     }
-    
+
+    protected FileSystemXmlApplicationContext createApplicationContext(String serviceUnitRootPath) {
+        File baseDir = new File(serviceUnitRootPath);
+        String location = getXBeanFile();
+        return new FileSystemXmlApplicationContext(
+                                        new String[] { "/" + baseDir.toURI().resolve(location).getPath() + ".xml" },
+                                        false,
+                                        getXmlPreProcessors(serviceUnitRootPath));
+    }
+
     protected List getXmlPreProcessors(String serviceUnitRootPath) {
         JBIContainer container = null;
         try {
             container = ((ComponentContextImpl) component.getComponentContext()).getContainer();
         } catch (Throwable t) { }
-        FileSystemRepository repository = new FileSystemRepository(new File(serviceUnitRootPath));
-        ClassLoaderXmlPreprocessor classLoaderXmlPreprocessor = new ClassLoaderXmlPreprocessor(repository, container);
+        ClassLoaderXmlPreprocessor classLoaderXmlPreprocessor = new ClassLoaderXmlPreprocessor(new File(serviceUnitRootPath), container);
         return Collections.singletonList(classLoaderXmlPreprocessor);
     }
     
     protected List getBeanFactoryPostProcessors(String serviceUnitRootPath) {
+        List processors = new ArrayList();
+        // Property place holder
         PropertyPlaceholderConfigurer propertyPlaceholder = new PropertyPlaceholderConfigurer();
-        FileSystemResource propertiesFile = new FileSystemResource(
-                new File(serviceUnitRootPath) + "/" + getXBeanFile()
-                        + ".properties");
+        FileSystemResource propertiesFile = new FileSystemResource(new File(serviceUnitRootPath) + "/" + getXBeanFile() + ".properties");
         if (propertiesFile.getFile().exists()) {                
             propertyPlaceholder.setLocation(propertiesFile);
-            return Collections.singletonList(propertyPlaceholder);
-        } 
-        return Collections.EMPTY_LIST;
+            processors.add(propertyPlaceholder);
+        }
+        // Parent beans map
+        Map beans = getParentBeansMap();
+        if (beans != null) {
+            processors.add(new ParentBeanFactoryPostProcessor(beans));
+        }
+        return processors;
+    }
+
+    protected Map getParentBeansMap() {
+        Map beans = new HashMap();
+        beans.put("context", new EndpointComponentContext(((BaseLifeCycle) component.getLifeCycle()).getContext()));
+        beans.put("component", component);
+        Object smx3 = component.getSmx3Container();
+        if (smx3 != null) {
+            beans.put("container", smx3);
+        }
+        return beans;
     }
     
 }

Modified: servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java (original)
+++ servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java Tue Mar 25 15:55:37 2008
@@ -20,6 +20,7 @@
 import java.io.FilenameFilter;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.ListIterator;
@@ -31,9 +32,6 @@
 import org.apache.servicemix.jbi.framework.ComponentMBeanImpl;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.xbean.classloader.JarFileClassLoader;
-import org.apache.xbean.server.repository.FileSystemRepository;
-import org.apache.xbean.server.repository.Repository;
-import org.apache.xbean.server.spring.loader.SpringLoader;
 import org.apache.xbean.spring.context.SpringApplicationContext;
 import org.apache.xbean.spring.context.SpringXmlPreprocessor;
 import org.springframework.beans.FatalBeanException;
@@ -54,18 +52,15 @@
     public static final String CLASSPATH_XML = "classpath.xml";
     public static final String LIB_DIR = "/lib";
     
-    private final FileSystemRepository repository;
+    private final File root;
     private final JBIContainer container;
     
-    public ClassLoaderXmlPreprocessor(Repository repository) {
-        this(repository, null);
+    public ClassLoaderXmlPreprocessor(File root) {
+        this(root, null);
     }
 
-    public ClassLoaderXmlPreprocessor(Repository repository, JBIContainer container) {
-        if (repository instanceof FileSystemRepository == false) {
-            throw new IllegalArgumentException("repository must be a FileSystemRepository");
-        }
-        this.repository = (FileSystemRepository) repository;
+    public ClassLoaderXmlPreprocessor(File root, JBIContainer container) {
+        this.root = root;
         this.container = container;
     }
 
@@ -75,7 +70,7 @@
         NodeList classpathElements = document.getDocumentElement().getElementsByTagName("classpath");
         if (classpathElements.getLength() == 0) {
             // Check if a classpath.xml file exists in the root of the SU
-            URL url = repository.getResource(CLASSPATH_XML);
+            URL url = getResource(CLASSPATH_XML);
             if (url != null) {
                 try {
                     DocumentBuilder builder = new SourceTransformer().createDocumentBuilder();
@@ -102,10 +97,24 @@
         applicationContext.setClassLoader(classLoader);
         Thread.currentThread().setContextClassLoader(classLoader);
     }
+
+    protected URL getResource(String location) {
+        URI uri = root.toURI().resolve(location);
+        File file = new File(uri);
+
+        if (!file.canRead()) {
+            return null;
+        }
+
+        try {
+            return file.toURL();
+        } catch (MalformedURLException e) {
+            throw new IllegalArgumentException("Malformed resource " + uri);
+        }
+    }
     
     protected URL[] getDefaultLocations() {
         try {
-            File root = repository.getRoot();
             File[] jars = new File(root, LIB_DIR).listFiles(new FilenameFilter() {
                 public boolean accept(File dir, String name) {
                     name = name.toLowerCase();
@@ -200,7 +209,7 @@
                 urls = new URL[classpath.size()];
                 for (ListIterator<String> iterator = classpath.listIterator(); iterator.hasNext();) {
                     String location = iterator.next();
-                    URL url = repository.getResource(location);
+                    URL url = getResource(location);
                     if (url == null) {
                         throw new FatalBeanException("Unable to resolve classpath location " + location);
                     }
@@ -240,13 +249,13 @@
         return classLoader;
     }
 
-    private static ClassLoader getParentClassLoader(SpringApplicationContext applicationContext) {
+    private ClassLoader getParentClassLoader(SpringApplicationContext applicationContext) {
         ClassLoader classLoader = applicationContext.getClassLoader();
         if (classLoader == null) {
             classLoader = Thread.currentThread().getContextClassLoader();
         }
         if (classLoader == null) {
-            classLoader = SpringLoader.class.getClassLoader();
+            classLoader = getClass().getClassLoader();
         }
         return classLoader;
     }

Modified: servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java (original)
+++ servicemix/smx3/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java Tue Mar 25 15:55:37 2008
@@ -16,61 +16,43 @@
  */
 package org.apache.servicemix.common.xbean;
 
-import org.apache.servicemix.common.ServiceUnit;
-import org.apache.xbean.kernel.Kernel;
-import org.apache.xbean.kernel.ServiceFactory;
-import org.apache.xbean.kernel.ServiceName;
-import org.apache.xbean.kernel.ServiceNotFoundException;
-
 import javax.jbi.JBIException;
 
+import org.apache.servicemix.common.ServiceUnit;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
 public class XBeanServiceUnit extends ServiceUnit {
 
-    private Kernel kernel;
-    private ServiceName configuration;
     private ClassLoader classLoader;
+    private AbstractXmlApplicationContext applicationContext;
 
-    /**
-     * @return Returns the kernel.
-     */
-    public Kernel getKernel() {
-        return kernel;
-    }
-
-    /**
-     * @param kernel The kernel to set.
-     */
-    public void setKernel(Kernel kernel) {
-        this.kernel = kernel;
+    public AbstractXmlApplicationContext getApplicationContext() {
+        return applicationContext;
     }
 
-    public ServiceName getConfiguration() {
-        return configuration;
+    public void setApplicationContext(AbstractXmlApplicationContext applicationContext) {
+        this.applicationContext = applicationContext;
     }
 
-    public void setConfiguration(ServiceName configuration) {
-        this.configuration = configuration;
-    }
-    
     /* (non-Javadoc)
      * @see org.apache.servicemix.common.ServiceUnit#shutDown()
      */
     public void shutDown() throws JBIException {
         super.shutDown();
         classLoader = null;
-        if (kernel != null) {
-            kernel.destroy();
+        try {
+            if (applicationContext != null) {
+                applicationContext.destroy();
+            }
+            applicationContext = null;
+        } catch (Exception e) {
+            throw new JBIException("Unable to close application context", e);
         }
     }
     
     public ClassLoader getConfigurationClassLoader() {
-        if (classLoader == null && kernel != null && configuration != null) {
-            try {
-                ServiceFactory sf = kernel.getServiceFactory(configuration);
-                classLoader = sf.getClassLoader();
-            } catch (ServiceNotFoundException e) {
-                // This should never happen
-            }
+        if (classLoader == null && applicationContext != null) {
+            classLoader = applicationContext.getClassLoader();
         }
         ClassLoader cl = classLoader;
         if (cl == null) {

Modified: servicemix/smx3/trunk/core/servicemix-core/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/core/servicemix-core/pom.xml?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/core/servicemix-core/pom.xml (original)
+++ servicemix/smx3/trunk/core/servicemix-core/pom.xml Tue Mar 25 15:55:37 2008
@@ -97,10 +97,6 @@
     </dependency>
     <dependency>
       <groupId>org.apache.xbean</groupId>
-      <artifactId>xbean-server</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.xbean</groupId>
       <artifactId>xbean-spring</artifactId>
     </dependency>
 

Modified: servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/Main.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/Main.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/Main.java (original)
+++ servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/Main.java Tue Mar 25 15:55:37 2008
@@ -21,8 +21,7 @@
 import java.util.List;
 
 import org.apache.servicemix.jbi.container.SpringJBIContainer;
-import org.apache.xbean.server.repository.FileSystemRepository;
-import org.apache.xbean.server.spring.configuration.ClassLoaderXmlPreprocessor;
+import org.apache.servicemix.xbean.ClassLoaderXmlPreprocessor;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 import org.apache.xbean.spring.context.FileSystemXmlApplicationContext;
 import org.springframework.beans.factory.DisposableBean;
@@ -62,7 +61,7 @@
                 }
                 
                 List processors = new ArrayList();
-                processors.add(new ClassLoaderXmlPreprocessor(new FileSystemRepository(new File("."))));
+                processors.add(new ClassLoaderXmlPreprocessor(new File(".")));
                 System.out.println("Loading Apache ServiceMix from file: " + file);
                 context = new FileSystemXmlApplicationContext(file, processors);
             }

Added: servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java?rev=641065&view=auto
==============================================================================
--- servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java (added)
+++ servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/xbean/ClassLoaderXmlPreprocessor.java Tue Mar 25 15:55:37 2008
@@ -0,0 +1,217 @@
+/*
+ * 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.servicemix.xbean;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import javax.xml.parsers.DocumentBuilder;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.xbean.classloader.JarFileClassLoader;
+import org.apache.xbean.spring.context.SpringApplicationContext;
+import org.apache.xbean.spring.context.SpringXmlPreprocessor;
+import org.springframework.beans.FatalBeanException;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+
+/**
+ * An advanced xml preprocessor that will create a default classloader for the SU if none
+ * is configured.
+ * 
+ * @author gnodet
+ */
+public class ClassLoaderXmlPreprocessor implements SpringXmlPreprocessor {
+
+    public static final String CLASSPATH_XML = "classpath.xml";
+    public static final String LIB_DIR = "/lib";
+    
+    private final File root;
+    
+    public ClassLoaderXmlPreprocessor(File root) {
+        this.root = root;
+    }
+
+    public void preprocess(SpringApplicationContext applicationContext, XmlBeanDefinitionReader reader, Document document) {
+        // determine the classLoader
+        ClassLoader classLoader;
+        NodeList classpathElements = document.getDocumentElement().getElementsByTagName("classpath");
+        if (classpathElements.getLength() == 0) {
+            // Check if a classpath.xml file exists in the root of the SU
+            URL url = getResource(CLASSPATH_XML);
+            if (url != null) {
+                try {
+                    DocumentBuilder builder = new SourceTransformer().createDocumentBuilder();
+                    Document doc = builder.parse(url.toString());
+                    classLoader = getClassLoader(applicationContext, reader, doc);
+                } catch (Exception e) {
+                    throw new FatalBeanException("Unable to load classpath.xml file", e);
+                }
+            } else {
+                try {
+                    URL[] urls = getDefaultLocations();
+                    ClassLoader parentLoader = getParentClassLoader(applicationContext);
+                    classLoader = new JarFileClassLoader(applicationContext.getDisplayName(), urls, parentLoader);
+                    // assign the class loader to the xml reader and the
+                    // application context
+                } catch (Exception e) {
+                    throw new FatalBeanException("Unable to create default classloader for SU", e);
+                }
+            }
+        } else {
+            classLoader = getClassLoader(applicationContext, reader, document);
+        }
+        reader.setBeanClassLoader(classLoader);
+        applicationContext.setClassLoader(classLoader);
+        Thread.currentThread().setContextClassLoader(classLoader);
+    }
+
+    protected URL getResource(String location) {
+        URI uri = root.toURI().resolve(location);
+        File file = new File(uri);
+
+        if (!file.canRead()) {
+            return null;
+        }
+
+        try {
+            return file.toURL();
+        } catch (MalformedURLException e) {
+            throw new IllegalArgumentException("Malformed resource " + uri);
+        }
+    }
+    
+    protected URL[] getDefaultLocations() {
+        try {
+            File[] jars = new File(root, LIB_DIR).listFiles(new FilenameFilter() {
+                public boolean accept(File dir, String name) {
+                    name = name.toLowerCase();
+                    return name.endsWith(".jar") || name.endsWith(".zip");
+                }
+            });
+            URL[] urls = new URL[jars != null ? jars.length + 1 : 1];
+            urls[0] = root.toURL();
+            if (jars != null) {
+                for (int i = 0; i < jars.length; i++) {
+                    urls[i + 1] = jars[i].toURL();
+                }
+            }
+            return urls;
+        } catch (MalformedURLException e) {
+            throw new FatalBeanException("Unable to get default classpath locations", e);
+        }
+    }
+    
+    protected ClassLoader getClassLoader(SpringApplicationContext applicationContext, XmlBeanDefinitionReader reader, Document document) {
+        // determine the classLoader
+        ClassLoader classLoader;
+        NodeList classpathElements = document.getDocumentElement().getElementsByTagName("classpath");
+        if (classpathElements.getLength() < 1) {
+            classLoader = getParentClassLoader(applicationContext);
+        } else if (classpathElements.getLength() > 1) {
+            throw new FatalBeanException("Expected only classpath element but found " + classpathElements.getLength());
+        } else {
+            Element classpathElement = (Element) classpathElements.item(0);
+            
+            // Delegation mode
+            boolean inverse = false;
+            String inverseAttr = classpathElement.getAttribute("inverse");
+            if (inverseAttr != null && "true".equalsIgnoreCase(inverseAttr)) {
+                inverse = true;
+            }
+
+            // build hidden classes
+            List<String> hidden = new ArrayList<String>();
+            NodeList hiddenElems = classpathElement.getElementsByTagName("hidden");
+            for (int i = 0; i < hiddenElems.getLength(); i++) {
+                Element hiddenElement = (Element) hiddenElems.item(i);
+                String pattern = ((Text) hiddenElement.getFirstChild()).getData().trim();
+                hidden.add(pattern);
+            }
+
+            // build non overridable classes
+            List<String> nonOverridable = new ArrayList<String>();
+            NodeList nonOverridableElems = classpathElement.getElementsByTagName("nonOverridable");
+            for (int i = 0; i < nonOverridableElems.getLength(); i++) {
+                Element nonOverridableElement = (Element) nonOverridableElems.item(i);
+                String pattern = ((Text) nonOverridableElement.getFirstChild()).getData().trim();
+                nonOverridable.add(pattern);
+            }
+
+            // build the classpath
+            List<String> classpath = new ArrayList<String>();
+            NodeList locations = classpathElement.getElementsByTagName("location");
+            for (int i = 0; i < locations.getLength(); i++) {
+                Element locationElement = (Element) locations.item(i);
+                String location = ((Text) locationElement.getFirstChild()).getData().trim();
+                classpath.add(location);
+            }
+            
+            // convert the paths to URLS
+            URL[] urls;
+            if (classpath.size() != 0) {
+                urls = new URL[classpath.size()];
+                for (ListIterator<String> iterator = classpath.listIterator(); iterator.hasNext();) {
+                    String location = iterator.next();
+                    URL url = getResource(location);
+                    if (url == null) {
+                        throw new FatalBeanException("Unable to resolve classpath location " + location);
+                    }
+                    urls[iterator.previousIndex()] = url;
+                }
+            } else {
+                urls = getDefaultLocations();
+            }
+
+            // create the classloader
+            List<ClassLoader> parents = new ArrayList<ClassLoader>();
+            parents.add(getParentClassLoader(applicationContext));
+            classLoader = new JarFileClassLoader(applicationContext.getDisplayName(),
+                                                 urls, 
+                                                 parents.toArray(new ClassLoader[parents.size()]),
+                                                 inverse,
+                                                 hidden.toArray(new String[hidden.size()]),
+                                                 nonOverridable.toArray(new String[nonOverridable.size()]));
+
+            // remove the classpath element so Spring doesn't get confused
+            document.getDocumentElement().removeChild(classpathElement);
+        }
+        return classLoader;
+    }
+
+    private ClassLoader getParentClassLoader(SpringApplicationContext applicationContext) {
+        ClassLoader classLoader = applicationContext.getClassLoader();
+        if (classLoader == null) {
+            classLoader = Thread.currentThread().getContextClassLoader();
+        }
+        if (classLoader == null) {
+            classLoader = getClass().getClassLoader();
+        }
+        return classLoader;
+    }
+    
+}

Modified: servicemix/smx3/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java (original)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-camel/src/main/java/org/apache/servicemix/camel/CamelSpringDeployer.java Tue Mar 25 15:55:37 2008
@@ -19,6 +19,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 import javax.jbi.management.DeploymentException;
 
@@ -27,13 +28,7 @@
 import org.apache.camel.spring.SpringCamelContext;
 import org.apache.servicemix.common.ServiceUnit;
 import org.apache.servicemix.common.xbean.AbstractXBeanDeployer;
-import org.apache.xbean.kernel.Kernel;
-import org.apache.xbean.server.spring.loader.PureSpringLoader;
-import org.apache.xbean.server.spring.loader.SpringLoader;
-import org.apache.xbean.spring.context.FileSystemXmlApplicationContext;
-import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
 
 /**
  * A deployer of the spring XML file
@@ -41,15 +36,8 @@
  * @version $Revision: 1.1 $
  */
 public class CamelSpringDeployer extends AbstractXBeanDeployer {
-    private final CamelJbiComponent component;
 
-    private PureSpringLoader springLoader = new PureSpringLoader() {
-        @Override
-        protected AbstractXmlApplicationContext createXmlApplicationContext(String configLocation) {
-            ApplicationContext parentAppContext = createParentApplicationContext(getXmlPreprocessors());
-            return new FileSystemXmlApplicationContext(new String[] {configLocation}, false, parentAppContext, getXmlPreprocessors());
-        }
-    };
+    private final CamelJbiComponent component;
 
     private List<CamelJbiEndpoint> activatedEndpoints = new ArrayList<CamelJbiEndpoint>();
 
@@ -90,51 +78,35 @@
     }
 
     @Override
-    protected List getServices(Kernel kernel) {
-        try {
-            List<CamelJbiEndpoint> services = new ArrayList<CamelJbiEndpoint>(activatedEndpoints);
-            activatedEndpoints.clear();
-
-            ApplicationContext applicationContext = springLoader.getApplicationContext();
-            SpringCamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext);
-
-            // now lets iterate through all the endpoints
-            Collection<Endpoint> endpoints = camelContext.getSingletonEndpoints();
-
-            for (Endpoint endpoint : endpoints) {
-                if (component.isEndpointExposedOnNmr(endpoint)) {
-                    services.add(component.createJbiEndpointFromCamel(endpoint));
-                }
+    protected Collection<org.apache.servicemix.common.Endpoint> getServices(
+                        AbstractXmlApplicationContext applicationContext) throws Exception {
+        List<org.apache.servicemix.common.Endpoint> services = new ArrayList<org.apache.servicemix.common.Endpoint>(activatedEndpoints);
+        activatedEndpoints.clear();
+
+        SpringCamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext);
+
+        // now lets iterate through all the endpoints
+        Collection<Endpoint> endpoints = camelContext.getSingletonEndpoints();
+
+        for (Endpoint endpoint : endpoints) {
+            if (component.isEndpointExposedOnNmr(endpoint)) {
+                services.add(component.createJbiEndpointFromCamel(endpoint));
             }
-
-            // lets add a control bus endpoint to ensure we have at least one endpoint to deploy
-            BeanComponent beanComponent = camelContext.getComponent("bean", BeanComponent.class);
-            Endpoint endpoint = beanComponent.createEndpoint(new CamelControlBus(camelContext),
-                                                             "camel:" + serviceUnitName + "-controlBus");
-            services.add(component.createJbiEndpointFromCamel(endpoint));
-
-            return services;
-        } catch (Exception e) {
-            throw new RuntimeException(e);
         }
-    }
 
-    @Override
-    protected SpringLoader createSpringLoader() {
-        return springLoader;
+        // lets add a control bus endpoint to ensure we have at least one endpoint to deploy
+        BeanComponent beanComponent = camelContext.getComponent("bean", BeanComponent.class);
+        Endpoint endpoint = beanComponent.createEndpoint(new CamelControlBus(camelContext),
+                                                         "camel:" + serviceUnitName + "-controlBus");
+        services.add(component.createJbiEndpointFromCamel(endpoint));
+
+        return services;
     }
 
-    /**
-     * Returns the parent application context which can be used to auto-wire any
-     * JBI based components using the jbi prefix
-     */
-    protected ApplicationContext createParentApplicationContext(List xmlProcessors) {
-        GenericApplicationContext answer = new GenericApplicationContext();
-        answer.getBeanFactory().registerSingleton("jbi", component);
-        answer.setClassLoader(Thread.currentThread().getContextClassLoader());
-        answer.start();
-        answer.refresh();
-        return answer;
+    protected Map getParentBeansMap() {
+        Map beans =  super.getParentBeansMap();
+        beans.put("jbi", component);
+        return beans;
     }
 
 }

Modified: servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeComponent.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeComponent.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeComponent.java (original)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeComponent.java Tue Mar 25 15:55:37 2008
@@ -20,9 +20,7 @@
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
-import org.apache.servicemix.common.BaseServiceUnitManager;
 import org.apache.servicemix.common.DefaultComponent;
-import org.apache.servicemix.common.Deployer;
 
 /**
  * 
@@ -63,16 +61,6 @@
     protected Class[] getEndpointClasses() {
         return new Class[] {CxfSeEndpoint.class };
     }
-    
-    /* (non-Javadoc)
-     * @see org.servicemix.common.BaseComponent#createServiceUnitManager()
-     */
-    @Override
-    public BaseServiceUnitManager createServiceUnitManager() {
-        Deployer[] deployers = new Deployer[] {new CxfSeXBeanDeployer(this) };
-        return new BaseServiceUnitManager(this, deployers);
-    }
-
     
     @Override
     protected void doInit() throws Exception {

Modified: servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Component.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Component.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Component.java (original)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Component.java Tue Mar 25 15:55:37 2008
@@ -20,9 +20,7 @@
 
 import javax.jbi.component.ComponentContext;
 
-import org.apache.servicemix.common.BaseServiceUnitManager;
 import org.apache.servicemix.common.DefaultComponent;
-import org.apache.servicemix.common.Deployer;
 import org.apache.servicemix.jsr181.xfire.JbiTransport;
 import org.codehaus.xfire.DefaultXFire;
 import org.codehaus.xfire.XFire;
@@ -58,14 +56,6 @@
         return new Class[] {Jsr181Endpoint.class };
     }
     
-    /* (non-Javadoc)
-     * @see org.servicemix.common.BaseComponent#createServiceUnitManager()
-     */
-    public BaseServiceUnitManager createServiceUnitManager() {
-        Deployer[] deployers = new Deployer[] {new Jsr181XBeanDeployer(this) };
-        return new BaseServiceUnitManager(this, deployers);
-    }
-
     /**
      * @return Returns the xfire.
      */

Modified: servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java (original)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java Tue Mar 25 15:55:37 2008
@@ -23,12 +23,18 @@
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
+import javax.activation.DataHandler;
 import javax.jbi.component.ComponentContext;
 import javax.jbi.management.DeploymentException;
-import javax.jbi.messaging.MessageExchange.Role;
-import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOptionalOut;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
 import javax.wsdl.Binding;
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
@@ -44,22 +50,34 @@
 import org.xml.sax.SAXException;
 
 import com.ibm.wsdl.Constants;
-
-import org.apache.servicemix.common.Endpoint;
-import org.apache.servicemix.common.EndpointComponentContext;
-import org.apache.servicemix.common.ExchangeProcessor;
+import org.apache.servicemix.JbiConstants;
+import org.apache.servicemix.common.EndpointDeliveryChannel;
 import org.apache.servicemix.common.ManagementSupport;
+import org.apache.servicemix.common.endpoints.ProviderEndpoint;
 import org.apache.servicemix.common.tools.wsdl.WSDLFlattener;
 import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.StAXSourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.jsr181.xfire.JbiFaultSerializer;
+import org.apache.servicemix.jsr181.xfire.JbiTransport;
 import org.apache.servicemix.jsr181.xfire.ServiceFactoryHelper;
+import org.codehaus.xfire.MessageContext;
 import org.codehaus.xfire.XFire;
 import org.codehaus.xfire.annotations.AnnotationServiceFactory;
+import org.codehaus.xfire.attachments.Attachment;
+import org.codehaus.xfire.attachments.Attachments;
+import org.codehaus.xfire.attachments.JavaMailAttachments;
+import org.codehaus.xfire.attachments.SimpleAttachment;
+import org.codehaus.xfire.exchange.InMessage;
+import org.codehaus.xfire.fault.XFireFault;
 import org.codehaus.xfire.jaxb2.JaxbType;
+import org.codehaus.xfire.service.OperationInfo;
 import org.codehaus.xfire.service.Service;
 import org.codehaus.xfire.service.binding.ObjectServiceFactory;
 import org.codehaus.xfire.service.invoker.BeanInvoker;
 import org.codehaus.xfire.soap.SoapConstants;
+import org.codehaus.xfire.transport.Channel;
+import org.codehaus.xfire.transport.Transport;
 import org.springframework.core.io.Resource;
 
 /**
@@ -70,8 +88,14 @@
  *                  description="A jsr181 endpoint"
  * 
  */
-public class Jsr181Endpoint extends Endpoint {
+public class Jsr181Endpoint extends ProviderEndpoint {
 
+    public static final String SOAP_FAULT_CODE = "org.apache.servicemix.soap.fault.code";
+    public static final String SOAP_FAULT_SUBCODE = "org.apache.servicemix.soap.fault.subcode";
+    public static final String SOAP_FAULT_REASON = "org.apache.servicemix.soap.fault.reason";
+    public static final String SOAP_FAULT_NODE = "org.apache.servicemix.soap.fault.node";
+    public static final String SOAP_FAULT_ROLE = "org.apache.servicemix.soap.fault.role";
+    
     protected Object pojo;
     protected String pojoClass;
     protected String annotations;
@@ -79,12 +103,11 @@
     protected String serviceInterface;
     protected String style = "wrapped";
     
-    protected ServiceEndpoint activated;
     protected Service xfireService;
-    protected ExchangeProcessor processor;
     protected Resource wsdlResource;
     protected boolean mtomEnabled;
     protected Map properties;
+    protected StAXSourceTransformer transformer;
 
     /* should the payload be automaticaly validated by the ws engine
      * if not set then it is up to the engine to decide
@@ -92,7 +115,7 @@
     private Boolean validationEnabled;
     
     public Jsr181Endpoint() {
-        processor = new Jsr181ExchangeProcessor(this);
+        this.transformer = new StAXSourceTransformer();
     }
     
     /**
@@ -190,34 +213,19 @@
     }
 
     /* (non-Javadoc)
-     * @see org.servicemix.common.Endpoint#getRole()
-     * @org.apache.xbean.XBean hide="true"
+     * @see org.servicemix.common.endpoints.SimpleEndpoint#start()
      */
-    public Role getRole() {
-        return Role.PROVIDER;
+    public void start() throws Exception {
+        super.start();
+        injectPojo(getContext(), getContainer());
     }
 
     /* (non-Javadoc)
-     * @see org.servicemix.common.Endpoint#activate()
+     * @see org.servicemix.common.endpoints.SimpleEndpoint#stop()
      */
-    public void activate() throws Exception {
-        logger = this.serviceUnit.getComponent().getLogger();
-        ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
-        activated = ctx.activateEndpoint(service, endpoint);
-        injectPojo(new EndpointComponentContext(this), getContainer());
-        processor.start();
-    }
-
-    /* (non-Javadoc)
-     * @see org.servicemix.common.Endpoint#deactivate()
-     */
-    public void deactivate() throws Exception {
-        ServiceEndpoint ep = activated;
-        activated = null;
-        processor.stop();
-        ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
-        ctx.deactivateEndpoint(ep);
+    public void stop() throws Exception {
         injectPojo(null, null);
+        super.stop();
     }
 
     protected void injectPojo(ComponentContext context, JBIContainer container) {
@@ -447,6 +455,93 @@
         return factory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray()));
     }
     
+    public void process(MessageExchange exchange) throws Exception {
+        if (exchange.getStatus() == ExchangeStatus.DONE) {
+            return;
+        } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
+            return;
+        }
+
+        // TODO: clean this code
+        XFire xfire = getXFire();
+        Service service = getXFireService();
+        Transport t = xfire.getTransportManager().getTransport(JbiTransport.JBI_BINDING);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        Channel c = t.createChannel();
+        MessageContext ctx = new MessageContext();
+        ctx.setXFire(xfire);
+        ctx.setService(service);
+        ctx.setProperty(Channel.BACKCHANNEL_URI, out);
+        ctx.setExchange(new org.codehaus.xfire.exchange.MessageExchange(ctx));
+        InMessage msg = new InMessage();
+        ctx.getExchange().setInMessage(msg);
+        if (exchange.getOperation() != null) {
+            OperationInfo op = service.getServiceInfo().getOperation(exchange.getOperation().getLocalPart());
+            if (op != null) {
+                ctx.getExchange().setOperation(op);
+            }
+        }
+        ctx.setCurrentMessage(msg);
+        NormalizedMessage in = exchange.getMessage("in");
+        msg.setXMLStreamReader(transformer.toXMLStreamReader(in.getContent()));
+        if (in.getAttachmentNames() != null && in.getAttachmentNames().size() > 0) {
+            JavaMailAttachments attachments = new JavaMailAttachments();
+            for (Iterator it = in.getAttachmentNames().iterator(); it.hasNext();) {
+                String name = (String) it.next();
+                DataHandler dh = in.getAttachment(name);
+                attachments.addPart(new SimpleAttachment(name, dh));
+            }
+            msg.setAttachments(attachments);
+        }
+        JBIContext.setMessageExchange(exchange);
+        try {
+            c.receive(ctx, msg);
+        } finally {
+            EndpointDeliveryChannel.setEndpoint(null);
+        }
+        c.close();
+        
+        // Set response or DONE status
+        if (exchange instanceof InOut || exchange instanceof InOptionalOut) {
+            if (ctx.getExchange().hasFaultMessage() && ctx.getExchange().getFaultMessage().getBody() != null) {
+                String charSet = ctx.getExchange().getFaultMessage().getEncoding();
+                Fault fault = exchange.getFault();
+                if (fault == null) {
+                    fault = exchange.createFault();
+                    exchange.setFault(fault);
+                }
+                fault.setContent(new StringSource(out.toString(charSet)));
+                XFireFault xFault = (XFireFault) ctx.getExchange().getFaultMessage().getBody();
+                fault.setProperty(SOAP_FAULT_CODE, xFault.getFaultCode());
+                fault.setProperty(SOAP_FAULT_REASON, xFault.getReason());
+                fault.setProperty(SOAP_FAULT_ROLE, xFault.getRole());
+                fault.setProperty(SOAP_FAULT_SUBCODE, xFault.getSubCode());
+            } else {
+                String charSet = ctx.getOutMessage().getEncoding();
+                NormalizedMessage outMsg = exchange.getMessage("out");
+                if (outMsg == null) {
+                    outMsg = exchange.createMessage();
+                    exchange.setMessage(outMsg, "out");
+                }
+                Attachments attachments = ctx.getCurrentMessage().getAttachments();
+                if (attachments != null) {
+                    for (Iterator it = attachments.getParts(); it.hasNext();) {
+                        Attachment att = (Attachment) it.next();
+                        outMsg.addAttachment(att.getId(), att.getDataHandler());
+                    }
+                }
+                outMsg.setContent(new StringSource(out.toString(charSet)));
+            }
+            if (exchange.isTransacted() && Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC))) {
+                sendSync(exchange);
+            } else {
+                send(exchange);
+            }
+        } else {
+            done(exchange);
+        }
+    }
+
     public XFire getXFire() {
         Jsr181Component component = (Jsr181Component) this.serviceUnit.getComponent();
         return component.getXFire();
@@ -474,10 +569,6 @@
 
     public void setTypeMapping(String typeMapping) {
         this.typeMapping = typeMapping;
-    }
-
-    public ExchangeProcessor getProcessor() {
-        return processor;
     }
 
     public String getServiceInterface() {

Modified: servicemix/smx3/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerXBeanDeployer.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerXBeanDeployer.java?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerXBeanDeployer.java (original)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerXBeanDeployer.java Tue Mar 25 15:55:37 2008
@@ -17,14 +17,16 @@
 package org.apache.servicemix.lwcontainer;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.servicemix.common.BaseComponent;
+import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.xbean.AbstractXBeanDeployer;
 import org.apache.servicemix.jbi.container.ActivationSpec;
 import org.apache.servicemix.jbi.container.SpringServiceUnitContainer;
-import org.apache.xbean.kernel.Kernel;
-import org.apache.xbean.kernel.StringServiceName;
+import org.springframework.context.support.AbstractXmlApplicationContext;
 
 public class LwContainerXBeanDeployer extends AbstractXBeanDeployer {
 
@@ -36,21 +38,23 @@
         return "servicemix";
     }
 
-    protected List getServices(Kernel kernel) {
+    @Override
+    protected Collection<Endpoint> getServices(AbstractXmlApplicationContext applicationContext) throws Exception {
         try {
-            Object jbi = kernel.getService(new StringServiceName("jbi"));
-            SpringServiceUnitContainer suContainer = (SpringServiceUnitContainer) jbi; 
-            ActivationSpec[] specs = suContainer.getActivationSpecs();
-            List services = new ArrayList();
-            if (specs != null) {
-                for (int i = 0; i < specs.length; i++) {
-                    services.add(new LwContainerEndpoint(specs[i]));
+            List<Endpoint> services = new ArrayList<Endpoint>();
+            Map<String, SpringServiceUnitContainer> containers = applicationContext.getBeansOfType(SpringServiceUnitContainer.class);
+            for (SpringServiceUnitContainer suContainer : containers.values()) { 
+                ActivationSpec[] specs = suContainer.getActivationSpecs();
+                if (specs != null) {
+                    for (int i = 0; i < specs.length; i++) {
+                        services.add(new LwContainerEndpoint(specs[i]));
+                    }
                 }
-            }
-            if (suContainer.getComponents() != null || suContainer.getEndpoints() != null
-                    || suContainer.getListeners() != null || suContainer.getServices() != null) {
-                services.add(new LwContainerExtra(suContainer.getComponents(), suContainer.getEndpoints(),
+                if (suContainer.getComponents() != null || suContainer.getEndpoints() != null
+                        || suContainer.getListeners() != null || suContainer.getServices() != null) {
+                    services.add(new LwContainerExtra(suContainer.getComponents(), suContainer.getEndpoints(),
                                                   suContainer.getListeners(), suContainer.getServices()));
+                }
             }
             return services;
         } catch (Exception e) {

Modified: servicemix/smx3/trunk/distributions/apache-servicemix/src/main/assembly/bin.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/distributions/apache-servicemix/src/main/assembly/bin.xml?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/distributions/apache-servicemix/src/main/assembly/bin.xml (original)
+++ servicemix/smx3/trunk/distributions/apache-servicemix/src/main/assembly/bin.xml Tue Mar 25 15:55:37 2008
@@ -109,8 +109,6 @@
         <include>org.apache.servicemix:servicemix-audit</include>
         <include>org.apache.xbean:xbean-spring</include>
         <include>org.apache.xbean:xbean-classloader</include>
-        <include>org.apache.xbean:xbean-server</include>
-        <include>org.apache.xbean:xbean-kernel</include>
         <include>wsdl4j:wsdl4j</include>
         <include>org.apache.woden:woden</include>
         <include>org.springframework:spring-core</include>

Modified: servicemix/smx3/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/pom.xml?rev=641065&r1=641064&r2=641065&view=diff
==============================================================================
--- servicemix/smx3/trunk/pom.xml (original)
+++ servicemix/smx3/trunk/pom.xml Tue Mar 25 15:55:37 2008
@@ -1635,22 +1635,6 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.xbean</groupId>
-                <artifactId>xbean-kernel</artifactId>
-                <version>${xbean-version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.xbean</groupId>
-                <artifactId>xbean-server</artifactId>
-                <version>${xbean-version}</version>
-                <exclusions>
-                  <exclusion>
-                    <groupId>org.springframework</groupId>
-                    <artifactId>spring</artifactId>
-                  </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.xbean</groupId>
                 <artifactId>xbean-spring</artifactId>
                 <version>${xbean-version}</version>
                 <exclusions>



Mime
View raw message