Author: gnodet
Date: Mon Oct 16 06:19:24 2006
New Revision: 464478

URL: http://svn.apache.org/viewvc?view=rev&rev=464478
Log:
Add an external endpoint implementation.
Add classes allowing to specify a parent factory for xbean deployment, and 
extend the SU analyzer to allow adding post processors (needed for SM-708).
Additional minor fixes.

Added:
    
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ExternalEndpoint.java
    
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ParentBeanFactoryPostProcessor.java
    
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/SimpleBeanFactory.java
Modified:
    
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AbstractDeployer.java
    
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ManagementSupport.java
    
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/PollingEndpoint.java
    
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ProviderEndpoint.java
    
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
    
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanServiceUnitAnalyzer.java
    
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/BaseXBeanDeployer.java

Modified: 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AbstractDeployer.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AbstractDeployer.java?view=diff&rev=464478&r1=464477&r2=464478
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AbstractDeployer.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AbstractDeployer.java
 Mon Oct 16 06:19:24 2006
@@ -40,14 +40,7 @@
     }
     
     protected DeploymentException failure(String task, String info, Throwable 
e) {
-        ManagementSupport.Message msg = new ManagementSupport.Message();
-        msg.setComponent(component.getComponentName());
-        msg.setTask(task);
-        msg.setResult("FAILED");
-        msg.setType("ERROR");
-        msg.setMessage(info);
-        msg.setException(e);
-        return new 
DeploymentException(ManagementSupport.createComponentMessage(msg));
+        return ManagementSupport.failure(task, component.getComponentName(), 
info, e);
     }
 
     public void undeploy(ServiceUnit su) throws DeploymentException {

Added: 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ExternalEndpoint.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ExternalEndpoint.java?view=auto&rev=464478
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ExternalEndpoint.java
 (added)
+++ 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ExternalEndpoint.java
 Mon Oct 16 06:19:24 2006
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.common;
+
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+public class ExternalEndpoint implements ServiceEndpoint {
+
+    private String eprUri;
+    private String eprName;
+    private String uri;
+    private String endpointName;
+    private QName serviceName;
+    private QName[] interfaces = null;
+    
+    public ExternalEndpoint(String eprUri, String eprName, String uri, 
+                            String epName, QName serviceName, QName[] 
interfaces) {
+        this.eprUri = eprUri;
+        this.eprName = eprName;
+        this.uri = uri;
+        this.endpointName = epName;
+        this.serviceName = serviceName;
+        this.interfaces = interfaces;
+    }
+
+    public ExternalEndpoint(String eprUri, String eprName, String uri, 
+                            String epName, QName serviceName, QName 
interfaceName) {
+        this.eprUri = eprUri;
+        this.eprName = eprName;
+        this.uri = uri;
+        this.endpointName = epName;
+        this.serviceName = serviceName;
+        if (interfaceName != null) {
+            this.interfaces = new QName[] { interfaceName };
+        }
+    }
+
+    public DocumentFragment getAsReference(QName operationName) {
+        try {
+            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            dbf.setNamespaceAware(true);
+            Document doc = dbf.newDocumentBuilder().newDocument();
+            DocumentFragment df = doc.createDocumentFragment();
+            Element e = doc.createElementNS(eprUri, eprName);
+            Text t = doc.createTextNode(uri);
+            e.appendChild(t);
+            df.appendChild(e);
+            return df;
+        } catch (Exception e) {
+            throw new RuntimeException("Could not create reference", e);
+        }
+    }
+
+    public String getEndpointName() {
+        return endpointName;
+    }
+
+    public QName[] getInterfaces() {
+        return interfaces;
+    }
+
+    public QName getServiceName() {
+        return serviceName;
+    }
+
+}

Modified: 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ManagementSupport.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ManagementSupport.java?view=diff&rev=464478&r1=464477&r2=464478
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ManagementSupport.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ManagementSupport.java
 Mon Oct 16 06:19:24 2006
@@ -22,6 +22,8 @@
 import java.io.PrintWriter;
 import java.io.StringWriter;
 
+import javax.jbi.management.DeploymentException;
+
 /**
  * ManagementMessageHelper is a class that ease the building of management 
messages. 
  */
@@ -29,53 +31,22 @@
     
     private static final Log logger = 
LogFactory.getLog(ManagementSupport.class);
 
-    public static class Message {
-        private String task;
-        private String component;
-        private String result;
-        private Throwable exception;
-        private String type;
-        private String message;
-        
-        public String getComponent() {
-            return component;
-        }
-        public void setComponent(String component) {
-            this.component = component;
-        }
-        public Throwable getException() {
-            return exception;
-        }
-        public void setException(Throwable exception) {
-            this.exception = exception;
-        }
-        public String getResult() {
-            return result;
-        }
-        public void setResult(String result) {
-            this.result = result;
-        }
-        public String getTask() {
-            return task;
-        }
-        public void setTask(String task) {
-            this.task = task;
-        }
-        public String getType() {
-            return type;
-        }
-        public void setType(String type) {
-            this.type = type;
-        }
-        public String getMessage() {
-            return message;
-        }
-        public void setMessage(String message) {
-            this.message = message;
+    public static DeploymentException failure(String task, String component, 
String info, Throwable e) {
+        Message msg = new Message();
+        msg.setComponent(component);
+        msg.setTask(task);
+        msg.setResult("FAILED");
+        msg.setType("ERROR");
+        if (info != null) {
+            msg.setMessage(info);
+        } else if (e != null) {
+            msg.setMessage(e.toString());
         }
+        msg.setException(e);
+        return new DeploymentException(createComponentMessage(msg));
     }
-    
-    public static String createComponentMessage(Message msg) {
+
+     public static String createComponentMessage(Message msg) {
         try {
             StringBuffer sw = new StringBuffer();
             // component-task-result
@@ -167,4 +138,50 @@
         }
     }
     
+     public static class Message {
+         private String task;
+         private String component;
+         private String result;
+         private Throwable exception;
+         private String type;
+         private String message;
+         
+         public String getComponent() {
+             return component;
+         }
+         public void setComponent(String component) {
+             this.component = component;
+         }
+         public Throwable getException() {
+             return exception;
+         }
+         public void setException(Throwable exception) {
+             this.exception = exception;
+         }
+         public String getResult() {
+             return result;
+         }
+         public void setResult(String result) {
+             this.result = result;
+         }
+         public String getTask() {
+             return task;
+         }
+         public void setTask(String task) {
+             this.task = task;
+         }
+         public String getType() {
+             return type;
+         }
+         public void setType(String type) {
+             this.type = type;
+         }
+         public String getMessage() {
+             return message;
+         }
+         public void setMessage(String message) {
+             this.message = message;
+         }
+     }
+     
 }

Modified: 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/PollingEndpoint.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/PollingEndpoint.java?view=diff&rev=464478&r1=464477&r2=464478
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/PollingEndpoint.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/PollingEndpoint.java
 Mon Oct 16 06:19:24 2006
@@ -23,8 +23,6 @@
 import javax.jbi.messaging.DeliveryChannel;
 import javax.jbi.messaging.MessagingException;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.components.varscheduler.ScheduleIterator;
 import org.apache.servicemix.components.varscheduler.Scheduler;
 import org.apache.servicemix.components.varscheduler.SchedulerTask;
@@ -37,7 +35,7 @@
  * @version $Revision$
  */
 public abstract class PollingEndpoint extends ProviderEndpoint {
-    private static final Log log = LogFactory.getLog(PollingEndpoint.class);
+    
     private Executor executor;
     private Scheduler scheduler;
     private Date firstTime;
@@ -161,13 +159,13 @@
                 });
             }
             catch (Throwable e) {
-                log.error("Failed to schedule work: " + e, e);
+                logger.error("Failed to schedule work: " + e, e);
             }
         }
     }
 
     protected void handlePollException(Exception e) {
-        log.error("Caught exception while polling: " + e, e);
+        logger.error("Caught exception while polling: " + e, e);
     }
 
 

Modified: 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ProviderEndpoint.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ProviderEndpoint.java?view=diff&rev=464478&r1=464477&r2=464478
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ProviderEndpoint.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ProviderEndpoint.java
 Mon Oct 16 06:19:24 2006
@@ -81,13 +81,7 @@
     }
 
     protected void send(MessageExchange me) throws MessagingException {
-        if (me.getRole() == MessageExchange.Role.CONSUMER &&
-            me.getStatus() == ExchangeStatus.ACTIVE) {
-            BaseLifeCycle lf = (BaseLifeCycle) 
getServiceUnit().getComponent().getLifeCycle();
-            lf.sendConsumerExchange(me, (Endpoint) this);
-        } else {
-            channel.send(me);
-        }
+        channel.send(me);
     }
     
     protected void done(MessageExchange me) throws MessagingException {

Modified: 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java?view=diff&rev=464478&r1=464477&r2=464478
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
 Mon Oct 16 06:19:24 2006
@@ -120,6 +120,7 @@
     }
     
     protected boolean validate(Endpoint endpoint) throws DeploymentException {
+        endpoint.validate();
         return true;
     }
     

Modified: 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanServiceUnitAnalyzer.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanServiceUnitAnalyzer.java?view=diff&rev=464478&r1=464477&r2=464478
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanServiceUnitAnalyzer.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanServiceUnitAnalyzer.java
 Mon Oct 16 06:19:24 2006
@@ -18,6 +18,8 @@
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.jbi.messaging.MessageExchange;
@@ -26,6 +28,7 @@
 import org.apache.servicemix.common.packaging.Provides;
 import org.apache.servicemix.common.packaging.ServiceUnitAnalyzer;
 import org.apache.xbean.spring.context.FileSystemXmlApplicationContext;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 
 public abstract class AbstractXBeanServiceUnitAnalyzer implements
                ServiceUnitAnalyzer {
@@ -75,10 +78,14 @@
         * @see 
org.apache.servicemix.common.packaging.ServiceUnitAnalyzer#init(java.io.File)
         */
        public void init(File explodedServiceUnitRoot) {
-               
                FileSystemXmlApplicationContext context = new 
FileSystemXmlApplicationContext(
                   "file:///" + explodedServiceUnitRoot.getAbsolutePath() + "/"
                                                + getXBeanFile());
+        List beanFactoryPostProcessors = 
getBeanFactoryPostProcessors(explodedServiceUnitRoot.getAbsolutePath());
+        for (Iterator iter = beanFactoryPostProcessors.iterator(); 
iter.hasNext();) {
+            BeanFactoryPostProcessor processor = (BeanFactoryPostProcessor) 
iter.next();
+            context.addBeanFactoryPostProcessor(processor);
+        }
                 
                for (int i = 0; i < context.getBeanDefinitionNames().length; 
i++) {
                        Object bean = 
context.getBean(context.getBeanDefinitionNames()[i]);
@@ -92,6 +99,10 @@
                }
        }
 
-       protected abstract boolean isValidEndpoint(Object bean);
+       protected List getBeanFactoryPostProcessors(String absolutePath) {
+        return Collections.EMPTY_LIST;
+    }
+
+    protected abstract boolean isValidEndpoint(Object bean);
 
 }

Modified: 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/BaseXBeanDeployer.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/BaseXBeanDeployer.java?view=diff&rev=464478&r1=464477&r2=464478
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/BaseXBeanDeployer.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/BaseXBeanDeployer.java
 Mon Oct 16 06:19:24 2006
@@ -21,6 +21,12 @@
 
 import javax.jbi.management.DeploymentException;
 
+/**
+ * A useful XBean deployer which check that the endpoints inherit one of
+ * the given allowed endpoint classes.
+ * 
+ * @author gnodet
+ */
 public class BaseXBeanDeployer extends AbstractXBeanDeployer {
 
     private final Class[] endpointClasses;
@@ -44,8 +50,7 @@
     protected boolean validate(Endpoint endpoint) throws DeploymentException {
         for (int i = 0; i < endpointClasses.length; i++) {
             if (endpointClasses[i].isInstance(endpoint)) {
-                endpoint.validate();
-                return true;
+                return super.validate(endpoint);
             }
         }
         return false;

Added: 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ParentBeanFactoryPostProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ParentBeanFactoryPostProcessor.java?view=auto&rev=464478
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ParentBeanFactoryPostProcessor.java
 (added)
+++ 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ParentBeanFactoryPostProcessor.java
 Mon Oct 16 06:19:24 2006
@@ -0,0 +1,45 @@
+/*
+ * 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.common.xbean;
+
+import java.util.Map;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import 
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+/**
+ * A BeanFactoryPostProcessor which creates a BeanFactory from the given beans
+ * and sets it as the parent BeanFactory.
+ * 
+ * @author gnodet
+ */
+public class ParentBeanFactoryPostProcessor implements 
BeanFactoryPostProcessor {
+
+    private final Map beans;
+    
+    public ParentBeanFactoryPostProcessor(Map beans) {
+        this.beans = beans;
+    }
+    
+    public void postProcessBeanFactory(ConfigurableListableBeanFactory 
beanFactory) throws BeansException {
+        BeanFactory parent = new SimpleBeanFactory(beans);
+        beanFactory.setParentBeanFactory(parent);
+    }
+
+}

Added: 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/SimpleBeanFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/SimpleBeanFactory.java?view=auto&rev=464478
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/SimpleBeanFactory.java
 (added)
+++ 
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/SimpleBeanFactory.java
 Mon Oct 16 06:19:24 2006
@@ -0,0 +1,76 @@
+/*
+ * 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.common.xbean;
+
+import java.util.Map;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+
+/**
+ * A simple BeanFactory containing a set of predefined beans which can be used
+ * as a parent for another BeanFactory.
+ *  
+ * @author gnodet
+ */
+public class SimpleBeanFactory implements BeanFactory {
+    
+    private final Map beans;
+    
+    public SimpleBeanFactory(Map beans) {
+        this.beans = beans;
+    }
+    public boolean containsBean(String name) {
+        return beans.containsKey(name);
+    }
+    public String[] getAliases(String name) throws 
NoSuchBeanDefinitionException {
+        Object bean = beans.get(name);
+        if (bean == null) {
+            throw new NoSuchBeanDefinitionException(name);
+        }
+        return new String[0];
+    }
+    public Object getBean(String name) throws BeansException {
+        return getBean(name, null);
+    }
+    public Object getBean(String name, Class requiredType) throws 
BeansException {
+        Object bean = beans.get(name);
+        if (bean == null) {
+            throw new NoSuchBeanDefinitionException(name);
+        }
+        if (requiredType != null && !requiredType.isInstance(bean)) {
+            throw new BeanNotOfRequiredTypeException(name, requiredType, 
bean.getClass());
+        }
+        return bean;
+    }
+    public Class getType(String name) throws NoSuchBeanDefinitionException {
+        Object bean = beans.get(name);
+        if (bean == null) {
+            throw new NoSuchBeanDefinitionException(name);
+        }
+        return bean.getClass();
+    }
+    public boolean isSingleton(String name) throws 
NoSuchBeanDefinitionException {
+        Object bean = beans.get(name);
+        if (bean == null) {
+            throw new NoSuchBeanDefinitionException(name);
+        }
+        return true;
+    }
+}
\ No newline at end of file


Reply via email to