[jboss-svn-commits] JBL Code SVN: r26950 - in labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners: gateway and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jun 12 08:47:59 EDT 2009


Author: tfennelly
Date: 2009-06-12 08:47:59 -0400 (Fri, 12 Jun 2009)
New Revision: 26950

Added:
   labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/DeploymentResourceLocator.java
Modified:
   labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/BusDeploymentFactory.java
   labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java
   labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayDeploymentFactory.java
Log:
Trying to work around Kev's issues with loading of the BusDeploymentFactory instance.

Modified: labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/BusDeploymentFactory.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/BusDeploymentFactory.java	2009-06-12 12:42:00 UTC (rev 26949)
+++ labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/BusDeploymentFactory.java	2009-06-12 12:47:59 UTC (rev 26950)
@@ -22,6 +22,8 @@
 import org.jboss.soa.esb.util.DeploymentArchive;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.listeners.gateway.HttpGatewayDeploymentFactory;
+import org.jboss.logging.Logger;
 
 import java.util.List;
 
@@ -31,6 +33,8 @@
  */
 public interface BusDeploymentFactory {
 
+
+
     /**
      * Set the name of the bus configuration associated with the deployment.
      * @param busName The bus name.
@@ -44,9 +48,36 @@
     public void setListeners(List<ConfigTree> listeners);
 
     /**
+     * Set the {@link DeploymentResourceLocator} for the deployment. 
+     * @param resourceLocator Deployment resource locator.
+     */
+    public void setDeploymentResourceLocator(DeploymentResourceLocator resourceLocator);
+
+    /**
      * Get the deployment archives to be deployed.
      * @return The deployment archives.
      * @throws ConfigurationException Failed to create the Deployment Archives. 
      */
     public List<DeploymentArchive> getDeploymentArchives() throws ConfigurationException;
+
+    /**
+     * Factory builder.
+     */
+    public static class FactoryBuilder {
+
+        private final static Logger logger = Logger.getLogger(FactoryBuilder.class);
+
+        public static BusDeploymentFactory createInstance(String gatewayClass) {
+
+            // Intentionally not allowing specification of the implementation.  Was deemed
+            // too risky.  Must be an internally defined implementation.
+            if(HttpGatewayDeploymentFactory.class.getName().equals(gatewayClass)) {
+                return new HttpGatewayDeploymentFactory();
+            }
+            
+            logger.debug("Not creating a BusDeploymentFactory instance for '" + gatewayClass + "'.  Not an internally defined BusDeploymentFactory implementation.");
+
+            return null;
+        }
+    }
 }

Added: labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/DeploymentResourceLocator.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/DeploymentResourceLocator.java	                        (rev 0)
+++ labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/DeploymentResourceLocator.java	2009-06-12 12:47:59 UTC (rev 26950)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.config;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * Deployment resource locator.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface DeploymentResourceLocator {
+
+    /**
+     * Get the resource under the specified path.
+     * @param resourcePath Path to the resource in the deployment.
+     * @return The resource stream, or null if the resource does not exist.
+     */
+    InputStream getResource(String resourcePath);
+}

Modified: labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java	2009-06-12 12:42:00 UTC (rev 26949)
+++ labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java	2009-06-12 12:47:59 UTC (rev 26950)
@@ -29,6 +29,7 @@
 import org.jboss.internal.soa.esb.util.StreamUtils;
 import org.jboss.internal.soa.esb.util.XMLHelper;
 import org.jboss.internal.soa.esb.webservice.*;
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.MetaData;
 import org.jboss.metadata.XmlFileLoader;
@@ -612,35 +613,17 @@
             String busIdRef = listenerGroup.getKey();
             List<ConfigTree> listeners = listenerGroup.getValue();
 
-            String gatewayClassName = listeners.get(0).getAttribute(ListenerTagNames.GATEWAY_CLASS_TAG);
+            String gatewayClass = listeners.get(0).getAttribute(ListenerTagNames.GATEWAY_CLASS_TAG);
+            if(gatewayClass != null) {
+                BusDeploymentFactory deploymentFactory = BusDeploymentFactory.FactoryBuilder.createInstance(gatewayClass);
 
-            Class gatewayClass;
-            ClassLoader originalTCCL = Thread.currentThread().getContextClassLoader();
+                if(deploymentFactory != null) {
+                    deploymentFactory.setBusName(busIdRef);
+                    deploymentFactory.setListeners(listeners);
+                    deploymentFactory.setDeploymentResourceLocator(new ClasspathDeploymentResourceLocator(di.localCl));
 
-            Thread.currentThread().setContextClassLoader(di.localCl) ;
-            try {
-                try {
-                    gatewayClass = ClassUtil.forName(gatewayClassName, getClass());
-                } catch (ClassNotFoundException e) {
-                    throw new ConfigurationException("Gateway Class '" + gatewayClassName + "' not found on classpath.");
+                    deploymentArchives.addAll(deploymentFactory.getDeploymentArchives());
                 }
-
-                if(BusDeploymentFactory.class.isAssignableFrom(gatewayClass)) {
-                    try {
-                        BusDeploymentFactory deploymentFactory = (BusDeploymentFactory) gatewayClass.newInstance();
-
-                        deploymentFactory.setBusName(busIdRef);
-                        deploymentFactory.setListeners(listeners);
-
-                        deploymentArchives.addAll(deploymentFactory.getDeploymentArchives());
-                    } catch (InstantiationException e) {
-                        throw new ConfigurationException("Unable to create instance of BusDeploymentFactory '" + gatewayClassName + "'.", e);
-                    } catch (IllegalAccessException e) {
-                        throw new ConfigurationException("Unable to create instance of BusDeploymentFactory '" + gatewayClassName + "'.", e);
-                    }
-                }
-            } finally {
-                Thread.currentThread().setContextClassLoader(originalTCCL) ;
             }
         }
 
@@ -1003,4 +986,18 @@
             throw new DeploymentException(e.getMessage(), e);
         }
     }
+
+    private static class ClasspathDeploymentResourceLocator implements DeploymentResourceLocator {
+        private ClassLoader classloader;
+
+        private ClasspathDeploymentResourceLocator(ClassLoader classloader) {
+            AssertArgument.isNotNull(classloader, "classloader");
+            this.classloader = classloader;
+        }
+
+        public InputStream getResource(String resourcePath) {
+            AssertArgument.isNotNullAndNotEmpty(resourcePath, "resourcePath");
+            return classloader.getResourceAsStream(resourcePath);
+        }
+    }
 }

Modified: labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayDeploymentFactory.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayDeploymentFactory.java	2009-06-12 12:42:00 UTC (rev 26949)
+++ labs/jbossesb/workspace/tfennelly/httpgateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayDeploymentFactory.java	2009-06-12 12:47:59 UTC (rev 26950)
@@ -20,12 +20,12 @@
 package org.jboss.soa.esb.listeners.gateway;
 
 import org.jboss.soa.esb.listeners.config.BusDeploymentFactory;
+import org.jboss.soa.esb.listeners.config.DeploymentResourceLocator;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.helpers.KeyValuePair;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.dom.YADOMUtil;
 import org.jboss.soa.esb.util.DeploymentArchive;
-import org.jboss.soa.esb.util.ClassUtil;
 import org.jboss.soa.esb.util.FreeMarkerTemplate;
 import org.jboss.internal.soa.esb.util.StreamUtils;
 import org.jboss.internal.soa.esb.assertion.AssertArgument;
@@ -51,6 +51,7 @@
 
     private String busName;
     private List<ConfigTree> listeners;
+    private DeploymentResourceLocator resourceLocator;
 
     public void setBusName(String busName) {
         AssertArgument.isNotNullAndNotEmpty(busName, "busName");
@@ -62,6 +63,11 @@
         this.listeners = listeners;
     }
 
+    public void setDeploymentResourceLocator(DeploymentResourceLocator resourceLocator) {
+        AssertArgument.isNotNull(resourceLocator, "resourceLocator");
+        this.resourceLocator = resourceLocator;
+    }
+
     public List<DeploymentArchive> getDeploymentArchives() throws ConfigurationException {
         List<ListenerConfig> listenerConfigModels = new ArrayList<ListenerConfig>();
         Set listenerNameSet = new HashSet<String>();
@@ -131,7 +137,7 @@
         String fileName = listeners.get(0).getAttribute(specifierAttribute);
 
         if(fileName != null) {
-            InputStream inputStream = ClassUtil.getResourceAsStream(fileName, HttpGatewayDeploymentFactory.class);
+            InputStream inputStream = resourceLocator.getResource(fileName);
             if(inputStream != null) {
                 try {
                     return StreamUtils.readStreamString(inputStream, "UTF-8");




More information about the jboss-svn-commits mailing list