[jboss-svn-commits] JBL Code SVN: r20733 - in labs/jbossesb/workspace/jimma/product/rosetta: tests/src/org/jboss/soa/esb/listeners/config and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jun 24 10:21:16 EDT 2008


Author: kevin.conner at jboss.com
Date: 2008-06-24 10:21:16 -0400 (Tue, 24 Jun 2008)
New Revision: 20733

Modified:
   labs/jbossesb/workspace/jimma/product/rosetta/src/org/jboss/soa/esb/listeners/config/Configuration.java
   labs/jbossesb/workspace/jimma/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java
   labs/jbossesb/workspace/jimma/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/ServicePublisherUnitTest.java
Log:
Undone formatting changes

Modified: labs/jbossesb/workspace/jimma/product/rosetta/src/org/jboss/soa/esb/listeners/config/Configuration.java
===================================================================
--- labs/jbossesb/workspace/jimma/product/rosetta/src/org/jboss/soa/esb/listeners/config/Configuration.java	2008-06-24 14:13:11 UTC (rev 20732)
+++ labs/jbossesb/workspace/jimma/product/rosetta/src/org/jboss/soa/esb/listeners/config/Configuration.java	2008-06-24 14:21:16 UTC (rev 20733)
@@ -1,24 +1,24 @@
 /*
- * 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.
- */
+* 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.ByteArrayInputStream;
@@ -53,98 +53,86 @@
 
 /**
  * comment
- * 
+ *
  * @author <a href="kurt.stam at jboss.com">Kurt Stam</a>
  * @author <a href="bill at jboss.com">Bill Burke</a>
  * @version $Revision: 1.1 $
  */
-public class Configuration {
-	private static final String JBOSSESB_XSD = "/jbossesb-1.0.1.xsd";
+public class Configuration
+{
+   private static final String JBOSSESB_XSD = "/jbossesb-1.0.1.xsd";
 	private static boolean genratedWSWar = false;
 
-	public static String getStringFromStream(InputStream is) throws Exception {
-		byte[] bytes = StreamUtils.readStream(is);
-		return new String(bytes, "UTF-8");
-	}
+   public static String getStringFromStream(InputStream is) throws Exception
+   {
+      byte[] bytes = StreamUtils.readStream(is);
+      return new String(bytes, "UTF-8");
+   }
 
-	public static ManagedLifecycleController create(URL jbossEsbXml) {
-		String configXml = null;
-		try {
-			configXml = getStringFromStream(jbossEsbXml.openStream());
-			return create(configXml);
-		} catch (Exception e) {
-			throw new RuntimeException("Failed to load jbossesb.xml file: "
-					+ jbossEsbXml, e);
-		}
-	}
+   public static ManagedLifecycleController create(URL jbossEsbXml)
+   {
+      String configXml = null;
+      try
+      {
+         configXml = getStringFromStream(jbossEsbXml.openStream());
+         return create(configXml);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Failed to load jbossesb.xml file: " + jbossEsbXml, e);
+      }
+   }
 
-	public static ManagedLifecycleController create(String configXml) {
-		return create(configXml, null, null);
-	}
+   public static ManagedLifecycleController create(String configXml) {
+	   return create (configXml, null, null);
+   }
+   
+   public static ManagedLifecycleController create(String configXml, DeploymentInfo di, ObjectName serviceName)
+   {
+      InputStream validationInputStream = ClassUtil.getResourceAsStream(JBOSSESB_XSD, Configuration.class);
+      //if this fails try using the
+      if (validationInputStream == null)
+      {
+         throw new IllegalStateException("ESB validation file [" + JBOSSESB_XSD + "] not found.");
+      }
+      StreamSource validationInputSource = new StreamSource(validationInputStream);
 
-	public static ManagedLifecycleController create(String configXml,
-			DeploymentInfo di, ObjectName serviceName) {
-		InputStream validationInputStream = ClassUtil.getResourceAsStream(
-				JBOSSESB_XSD, Configuration.class);
-		// if this fails try using the
-		if (validationInputStream == null) {
-			throw new IllegalStateException("ESB validation file ["
-					+ JBOSSESB_XSD + "] not found.");
-		}
-		StreamSource validationInputSource = new StreamSource(
-				validationInputStream);
+      try
+      {
+         InputSource xmlInputSource = new InputSource(new StringReader(configXml));
+         XmlValidator validator = new XmlValidatorImpl();
+         if (validator.validate(xmlInputSource, validationInputSource))
+         {
+            ByteArrayOutputStream listenerXml = new ByteArrayOutputStream();
+            ByteArrayOutputStream gatewayXml = new ByteArrayOutputStream();
+            Generator generator = new Generator(new ByteArrayInputStream(configXml.getBytes()), listenerXml, gatewayXml);
+            generator.generate();
+            byte[] listenerBytes = listenerXml.toByteArray();
+            //System.out.println("*************** listenerBytes: " + new String(listenerBytes));
+            ByteArrayInputStream listenerIs = new ByteArrayInputStream(listenerBytes);
+            ConfigTree listenerConfig = ConfigTree.fromInputStream(listenerIs);
+            if (serviceName != null) {
+            	listenerConfig.setAttribute(ListenerTagNames.DEPLOYMENT_NAME_TAG, 
+            		serviceName.getKeyProperty(ListenerTagNames.DEPLOYMENT_NAME_TAG));
+            }
 
-		try {
-			InputSource xmlInputSource = new InputSource(new StringReader(
-					configXml));
-			XmlValidator validator = new XmlValidatorImpl();
-			if (validator.validate(xmlInputSource, validationInputSource)) {
-				ByteArrayOutputStream listenerXml = new ByteArrayOutputStream();
-				ByteArrayOutputStream gatewayXml = new ByteArrayOutputStream();
-				Generator generator = new Generator(new ByteArrayInputStream(
-						configXml.getBytes()), listenerXml, gatewayXml);
-				generator.generate();
-
-				byte[] listenerBytes = listenerXml.toByteArray();
-				// System.out.println("*************** listenerBytes: " + new String(listenerBytes));
-				ByteArrayInputStream listenerIs = new ByteArrayInputStream(
-						listenerBytes);
-				ConfigTree listenerConfig = ConfigTree
-						.fromInputStream(listenerIs);
-
-				if (serviceName != null) {
-					listenerConfig
-							.setAttribute(
-									ListenerTagNames.DEPLOYMENT_NAME_TAG,
-									serviceName
-											.getKeyProperty(ListenerTagNames.DEPLOYMENT_NAME_TAG));
-				}
-
 				File esbFile = new File(di.url.getFile());
 
-				List<ManagedLifecycle> instances = LifecycleUtil
-						.getListeners(listenerConfig);
+            List<ManagedLifecycle> instances = LifecycleUtil.getListeners(listenerConfig);
 
-				byte[] gatewayBytes = gatewayXml.toByteArray();
-				// System.out.println("*************** gatewayBytes: " + new String(gatewayBytes));
-				ByteArrayInputStream gatewayIs = new ByteArrayInputStream(
-						gatewayBytes);
-				ConfigTree gatewayConfig = ConfigTree
-						.fromInputStream(gatewayIs);
+            byte[] gatewayBytes = gatewayXml.toByteArray();
+            //System.out.println("*************** gatewayBytes: " + new String(gatewayBytes));
+            ByteArrayInputStream gatewayIs = new ByteArrayInputStream(gatewayBytes);
+            ConfigTree gatewayConfig = ConfigTree.fromInputStream(gatewayIs);
+            instances.addAll(LifecycleUtil.getGateways(gatewayConfig));
 
-				instances.addAll(LifecycleUtil.getGateways(gatewayConfig));
+             ManagedLifecycleController controller = new ManagedLifecycleController(instances);
+             ScheduleProvider scheduleProvider = ScheduleProviderFactory.createInstance(instances, generator.getModel().getScheduleProvider());
+             controller.setScheduleProvider(scheduleProvider);
 
-				ManagedLifecycleController controller = new ManagedLifecycleController(
-						instances);
-				ScheduleProvider scheduleProvider = ScheduleProviderFactory
-						.createInstance(instances, generator.getModel()
-								.getScheduleProvider());
-				controller.setScheduleProvider(scheduleProvider);
+             // In parallel, create a map of the contract publication info...
+             ServicePublisher.addServicePublishers(controller, generator.getModel());
 
-				// In parallel, create a map of the contract publication info...
-				ServicePublisher.addServicePublishers(controller, generator
-						.getModel());
-
 				List<ServicePublisher> servicePublihsers = ServicePublisher
 						.getServicePublisher(controller);
 
@@ -173,16 +161,19 @@
 						esbServicePublisher.publish(endpoint, esbFile);
 					}
 				}
-				return controller;
-			} else {
-				throw new IllegalStateException(
-						"ESB file had validation errors.");
+            return controller;
+         }
+         else
+         {
+            throw new IllegalStateException("ESB file had validation errors.");
 
-			}
-		} catch (Exception e) {
-			throw new RuntimeException(e);
-		}
-	}
+         }
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
 
 	private static boolean hasPublishedWSWar(File esbFile,
 			ServicePublisher publisher) {

Modified: labs/jbossesb/workspace/jimma/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java
===================================================================
--- labs/jbossesb/workspace/jimma/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java	2008-06-24 14:13:11 UTC (rev 20732)
+++ labs/jbossesb/workspace/jimma/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java	2008-06-24 14:21:16 UTC (rev 20733)
@@ -1,24 +1,24 @@
 /*
- * 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.
- */
+* 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.File;
@@ -63,378 +63,430 @@
 
 /**
  * comment
- * 
+ *
  * @author <a href="bill at jboss.com">Bill Burke</a>
  * @version $Revision: 1.1 $
  */
-public class JBoss4ESBDeployer extends SubDeployerSupport implements
-		SubDeployer, JBoss4ESBDeployerMBean {
-	private final static Logger log = Logger.getLogger(JBoss4ESBDeployer.class);
+public class JBoss4ESBDeployer extends SubDeployerSupport
+        implements SubDeployer, JBoss4ESBDeployerMBean
+{
+   private final static Logger log = Logger.getLogger(JBoss4ESBDeployer.class);
 
-	private ServiceControllerMBean serviceController;
-	private Properties actionArtifactProperties;
+   private ServiceControllerMBean serviceController;
+   private Properties actionArtifactProperties;
 	private static boolean redployed = false;
-	private static final String PREFIX_CANONICAL_NAME = "jboss.esb:deployment=";
-	private static final String ESB_ARTIFACT_NAME = "jbossesb.esb";
+   private static final String PREFIX_CANONICAL_NAME = "jboss.esb:deployment=" ;
+   private static final String ESB_ARTIFACT_NAME = "jbossesb.esb" ;
+   
+   /**
+    * Default CTOR used to set default values to the Suffixes and RelativeOrder
+    * attributes. Those are read at subdeployer registration time by the MainDeployer
+    * to alter its SuffixOrder.
+    */
+   public JBoss4ESBDeployer()
+   {
+      setSuffixes(new String[]{".esb"});
+      setRelativeOrder(1000); // before old EJB 2.1 deployer
+   }
 
-	/**
-	 * Default CTOR used to set default values to the Suffixes and RelativeOrder
-	 * attributes. Those are read at subdeployer registration time by the
-	 * MainDeployer to alter its SuffixOrder.
-	 */
-	public JBoss4ESBDeployer() {
-		setSuffixes(new String[] { ".esb" });
-		setRelativeOrder(1000); // before old EJB 2.1 deployer
-	}
+   public static boolean hasFile(DeploymentInfo di, String filePath)
+   {
+      String urlStr = di.url.getFile();
+      try
+      {
+         URL dd = di.localCl.findResource(filePath);
+         if (dd != null)
+         {
 
-	public static boolean hasFile(DeploymentInfo di, String filePath) {
-		String urlStr = di.url.getFile();
-		try {
-			URL dd = di.localCl.findResource(filePath);
-			if (dd != null) {
+            // If the DD url is not a subset of the urlStr then this is coming
+            // from a jar referenced by the deployment jar manifest and the
+            // this deployment jar it should not be treated as persistence
+            if (di.localUrl != null)
+            {
+               urlStr = di.localUrl.toString();
+            }
 
-				// If the DD url is not a subset of the urlStr then this is
-				// coming
-				// from a jar referenced by the deployment jar manifest and the
-				// this deployment jar it should not be treated as persistence
-				if (di.localUrl != null) {
-					urlStr = di.localUrl.toString();
-				}
+            String ddStr = dd.toString();
+            if (ddStr.indexOf(urlStr) >= 0)
+            {
+               return true;
+            }
+         }
+      }
+      catch (Exception ignore)
+      {
+      }
+      return false;
+   }
 
-				String ddStr = dd.toString();
-				if (ddStr.indexOf(urlStr) >= 0) {
-					return true;
-				}
-			}
-		} catch (Exception ignore) {
-		}
-		return false;
-	}
+   /**
+    * Returns true if this deployer can deploy the given DeploymentInfo.
+    *
+    * @return True if this deployer can deploy the given DeploymentInfo.
+    * @jmx:managed-operation
+    */
+   public boolean accepts(DeploymentInfo di)
+   {
+      String urlStr = di.url.toString();
+      return urlStr.endsWith(".esb") || urlStr.endsWith(".esb/") ||
+              urlStr.endsWith("-esb.xml");
+   }
 
-	/**
-	 * Returns true if this deployer can deploy the given DeploymentInfo.
-	 * 
-	 * @return True if this deployer can deploy the given DeploymentInfo.
-	 * @jmx:managed-operation
-	 */
-	public boolean accepts(DeploymentInfo di) {
-		String urlStr = di.url.toString();
-		return urlStr.endsWith(".esb") || urlStr.endsWith(".esb/")
-				|| urlStr.endsWith("-esb.xml");
-	}
+   /**
+    * Get a reference to the ServiceController
+    */
+   protected void startService() throws Exception
+   {
+      final InputStream actionArtifactIS = ClassUtil.getResourceAsStream("/actionArtifactMap.properties", getClass()) ;
+      if (actionArtifactIS == null)
+      {
+         log.debug("No action artifact mapping") ;
+      }
+      else
+      {
+         log.debug("Loading action artifact mapping") ;
+         final Properties properties = new Properties() ;
+         properties.load(actionArtifactIS) ;
+         actionArtifactProperties = properties ;
+      }
+      
+      serviceController = (ServiceControllerMBean)
+              MBeanProxyExt.create(ServiceControllerMBean.class,
+                      ServiceControllerMBean.OBJECT_NAME, server);
 
-	/**
-	 * Get a reference to the ServiceController
-	 */
-	protected void startService() throws Exception {
-		final InputStream actionArtifactIS = ClassUtil.getResourceAsStream(
-				"/actionArtifactMap.properties", getClass());
-		if (actionArtifactIS == null) {
-			log.debug("No action artifact mapping");
-		} else {
-			log.debug("Loading action artifact mapping");
-			final Properties properties = new Properties();
-			properties.load(actionArtifactIS);
-			actionArtifactProperties = properties;
-		}
+      mainDeployer.addDeployer(this);
+      LifecycleResourceManager.deactivateHook() ;
+   }
+   
+   @Override
+   protected void stopService() throws Exception
+   {
+      LifecycleResourceManager.getSingleton().cleanupAllResources() ;
+      super.stopService();
+   }
 
-		serviceController = (ServiceControllerMBean) MBeanProxyExt.create(
-				ServiceControllerMBean.class,
-				ServiceControllerMBean.OBJECT_NAME, server);
 
-		mainDeployer.addDeployer(this);
-		LifecycleResourceManager.deactivateHook();
-	}
+   protected URL getDocumentUrl(DeploymentInfo di)
+   {
+      String urlStr = di.url.toString();
+      if (urlStr.endsWith(".esb") || urlStr.endsWith(".esb/"))
+      {
+         return di.localCl.getResource("META-INF/jboss-esb.xml");
+      }
+      return di.url;
+   }
 
-	@Override
-	protected void stopService() throws Exception {
-		LifecycleResourceManager.getSingleton().cleanupAllResources();
-		super.stopService();
-	}
+   public void init(DeploymentInfo di) throws DeploymentException
+   {
+      try
+      {
+         if (di.url.getProtocol().equalsIgnoreCase("file"))
+         {
+            File file = new File(di.url.getFile());
 
-	protected URL getDocumentUrl(DeploymentInfo di) {
-		String urlStr = di.url.toString();
-		if (urlStr.endsWith(".esb") || urlStr.endsWith(".esb/")) {
-			return di.localCl.getResource("META-INF/jboss-esb.xml");
-		}
-		return di.url;
-	}
+            if (!file.isDirectory())
+            {
+               // If not directory we watch the package
+               di.watch = di.url;
+            }
+            else
+            {
+               // If directory we watch the xml files
+               di.watch = new URL(di.url, "META-INF/jboss-esb.xml");
+            }
+         }
+         else
+         {
+            // We watch the top only, no directory support
+            di.watch = di.url;
+         }
 
-	public void init(DeploymentInfo di) throws DeploymentException {
-		try {
-			if (di.url.getProtocol().equalsIgnoreCase("file")) {
-				File file = new File(di.url.getFile());
+         XmlFileLoader xfl = new XmlFileLoader();
+         InputStream in = di.localCl.getResourceAsStream("META-INF/deployment.xml");
+         if (in != null)
+         {
+            try
+            {
+               Element jboss = xfl.getDocument(in, "META-INF/deployment.xml").getDocumentElement();
+               // Check for a ejb level class loading config
+               Element loader = MetaData.getOptionalChild(jboss, "loader-repository");
+               if (loader != null)
+               {
+                  LoaderRepositoryFactory.LoaderRepositoryConfig config =
+                          LoaderRepositoryFactory.parseRepositoryConfig(loader);
+                  di.setRepositoryInfo(config);
+               }
 
-				if (!file.isDirectory()) {
-					// If not directory we watch the package
-					di.watch = di.url;
-				} else {
-					// If directory we watch the xml files
-					di.watch = new URL(di.url, "META-INF/jboss-esb.xml");
-				}
-			} else {
-				// We watch the top only, no directory support
-				di.watch = di.url;
-			}
+            }
+            finally
+            {
+               in.close();
+            }
+         }
+      }
+      catch (Exception e)
+      {
+         if (e instanceof DeploymentException)
+         {
+            throw(DeploymentException) e;
+         }
+         throw new DeploymentException("failed to initialize", e);
+      }
 
-			XmlFileLoader xfl = new XmlFileLoader();
-			InputStream in = di.localCl
-					.getResourceAsStream("META-INF/deployment.xml");
-			if (in != null) {
-				try {
-					Element jboss = xfl.getDocument(in,
-							"META-INF/deployment.xml").getDocumentElement();
-					// Check for a ejb level class loading config
-					Element loader = MetaData.getOptionalChild(jboss,
-							"loader-repository");
-					if (loader != null) {
-						LoaderRepositoryFactory.LoaderRepositoryConfig config = LoaderRepositoryFactory
-								.parseRepositoryConfig(loader);
-						di.setRepositoryInfo(config);
-					}
+      // invoke super-class initialization
+      super.init(di);
+   }
 
-				} finally {
-					in.close();
-				}
-			}
-		} catch (Exception e) {
-			if (e instanceof DeploymentException) {
-				throw (DeploymentException) e;
-			}
-			throw new DeploymentException("failed to initialize", e);
-		}
+   public synchronized void create(DeploymentInfo di) throws DeploymentException
+   {
+      log.info("create esb service, " + di.shortName);
+      URL document = getDocumentUrl(di);
+      
+      if (document == null)
+      {
+         throw new DeploymentException("Unable to find document url of META-INF/jboss-esb.xml in: "
+                 + di.url);
+      }
+      try
+      {
+         Set<ObjectName> deps = new HashSet<ObjectName>();
+         InputStream in = di.localCl.getResourceAsStream("META-INF/deployment.xml");
+         if (in != null)
+         {
+            try
+            {
+               XmlFileLoader xfl = new XmlFileLoader();
+               Element jboss = xfl.getDocument(in, "META-INF/deployment.xml").getDocumentElement();
+               // Check for a ejb level class loading config
+               Iterator depends = MetaData.getChildrenByTagName(jboss, "depends");
+               if (depends != null)
+               {
+                  while (depends.hasNext())
+                  {
+                     Element depend = (Element)depends.next();
+                     ObjectName depOn = new ObjectName(MetaData.getElementContent(depend));
+                     deps.add(depOn);
+                  }
+               }
+               Iterator esbDepends = MetaData.getChildrenByTagName(jboss, "esb-depends");
+               if ((esbDepends != null) && esbDepends.hasNext())
+               {
+                  final Map<String, DeploymentInfo> subDeploymentLocationMap ;
+                  if (di.subDeployments.size() > 0)
+                  {
+                     subDeploymentLocationMap = new HashMap<String, DeploymentInfo>() ;
+                     final Set<DeploymentInfo> subDeployments = (Set<DeploymentInfo>)di.subDeployments ;
+                     for(DeploymentInfo subDI : subDeployments)
+                     {
+                        final String urlPath = subDI.url.getPath() ;
+                        final String deployablePath = (urlPath.endsWith("/") ? urlPath.substring(0, urlPath.length()-1) : urlPath) ;
+                        final int lastSeparator = deployablePath.lastIndexOf('/') ;
+                        final String deployable = (lastSeparator >= 0 ? deployablePath.substring(lastSeparator+1) : deployablePath) ;
+                        if (subDeploymentLocationMap.put(deployable, subDI) != null)
+                        {
+                           throw new DeploymentException("Duplicate subDeployment name: " + deployable) ;
+                        }
+                     }
+                  }
+                  else
+                  {
+                     throw new DeploymentException("No subdeployments to match esb-depends") ;
+                  }
+                  
+                  do
+                  {
+                     Element depend = (Element)esbDepends.next();
+                     final String deployable = MetaData.getElementContent(depend) ;
+                     final DeploymentInfo subDI = subDeploymentLocationMap.get(deployable) ;
+                     if ((subDI != null) && subDI.context.containsKey(AbstractWebContainer.WEB_MODULE))
+                     {
+                        final ObjectName jmxName = (ObjectName) subDI.context.get(AbstractWebContainer.WEB_MODULE) ;
+                        deps.add(jmxName) ;
+                     }
+                     else
+                     {
+                         throw new DeploymentException("Could not locate WAR subdeployment matching: " + deployable) ;
+                     }
+                  }
+                  while (esbDepends.hasNext()) ;
+               }
+            }
+            finally
+            {
+               in.close();
+            }
+         }
 
-		// invoke super-class initialization
-		super.init(di);
-	}
+         final InputStream inputStream = document.openStream();
+         final String jbossEsbXml ;
+         try
+         {
+             final StringWriter sw = new StringWriter() ;
+             XMLHelper.replaceSystemProperties(XMLHelper.getXMLStreamReader(inputStream),
+                 XMLHelper.getXMLStreamWriter(sw)) ;
+             jbossEsbXml = sw.toString();
+         }
+         finally
+         {
+             inputStream.close();
+         }
+         
+         addActionDependencies(di.shortName, jbossEsbXml, deps) ;
+         
+         JBoss4ESBDeployment deployment = new JBoss4ESBDeployment(jbossEsbXml, di);
+         deployment.setClassloader(di.ucl);
+         String name = PREFIX_CANONICAL_NAME + di.shortName;
+         ObjectName on = ObjectNameConverter.convert(name);
+         // Check that the name is not registered
+         if (server.isRegistered(on) == true)
+         {
+            log.debug("The ESBModule name: " + name
+                      + "is already registered, adding uid=" + System.identityHashCode(deployment));
+            name = name + ",uid=" + System.identityHashCode(deployment);
+            on = ObjectNameConverter.convert(name);
+         }
+         server.registerMBean(deployment, on);
+         di.deployedObject = on;
+         log.debug("Deploying: " + di.url);
+         // Invoke the create life cycle method
+         serviceController.create(di.deployedObject, deps);
+      }
+      catch (Exception e)
+      {
+         throw new DeploymentException("Error during create of ESB Module: "
+                 + di.url, e);
+      }
+      super.create(di);
+   }
 
-	public synchronized void create(DeploymentInfo di)
-			throws DeploymentException {
-		log.info("create esb service, " + di.shortName);
-		URL document = getDocumentUrl(di);
+   private void addActionDependencies(final String deploymentName,
+      final String configuration, final Set<ObjectName> deps)
+      throws XPathExpressionException, DeploymentException, MalformedObjectNameException
+   {
+      final XmlFileLoader xfl = new XmlFileLoader() ;
+      final StringReader sr = new StringReader(configuration) ;
+      final InputSource is = new InputSource(sr) ;
+      final Element rootElement = xfl.getDocument(is, "META-INF/jboss-esb.xml").getDocumentElement() ;
 
-		if (document == null) {
-			throw new DeploymentException(
-					"Unable to find document url of META-INF/jboss-esb.xml in: "
-							+ di.url);
-		}
-		try {
-			Set<ObjectName> deps = new HashSet<ObjectName>();
-			InputStream in = di.localCl
-					.getResourceAsStream("META-INF/deployment.xml");
-			if (in != null) {
-				try {
-					XmlFileLoader xfl = new XmlFileLoader();
-					Element jboss = xfl.getDocument(in,
-							"META-INF/deployment.xml").getDocumentElement();
-					// Check for a ejb level class loading config
-					Iterator depends = MetaData.getChildrenByTagName(jboss,
-							"depends");
-					if (depends != null) {
-						while (depends.hasNext()) {
-							Element depend = (Element) depends.next();
-							ObjectName depOn = new ObjectName(MetaData
-									.getElementContent(depend));
-							deps.add(depOn);
-						}
-					}
-					Iterator esbDepends = MetaData.getChildrenByTagName(jboss,
-							"esb-depends");
-					if ((esbDepends != null) && esbDepends.hasNext()) {
-						final Map<String, DeploymentInfo> subDeploymentLocationMap;
-						if (di.subDeployments.size() > 0) {
-							subDeploymentLocationMap = new HashMap<String, DeploymentInfo>();
-							final Set<DeploymentInfo> subDeployments = (Set<DeploymentInfo>) di.subDeployments;
-							for (DeploymentInfo subDI : subDeployments) {
-								final String urlPath = subDI.url.getPath();
-								final String deployablePath = (urlPath
-										.endsWith("/") ? urlPath.substring(0,
-										urlPath.length() - 1) : urlPath);
-								final int lastSeparator = deployablePath
-										.lastIndexOf('/');
-								final String deployable = (lastSeparator >= 0 ? deployablePath
-										.substring(lastSeparator + 1)
-										: deployablePath);
-								if (subDeploymentLocationMap.put(deployable,
-										subDI) != null) {
-									throw new DeploymentException(
-											"Duplicate subDeployment name: "
-													+ deployable);
-								}
-							}
-						} else {
-							throw new DeploymentException(
-									"No subdeployments to match esb-depends");
-						}
+      final Set<String> artifacts = new HashSet<String>() ;
+      artifacts.add(ESB_ARTIFACT_NAME) ;
 
-						do {
-							Element depend = (Element) esbDepends.next();
-							final String deployable = MetaData
-									.getElementContent(depend);
-							final DeploymentInfo subDI = subDeploymentLocationMap
-									.get(deployable);
-							if ((subDI != null)
-									&& subDI.context
-											.containsKey(AbstractWebContainer.WEB_MODULE)) {
-								final ObjectName jmxName = (ObjectName) subDI.context
-										.get(AbstractWebContainer.WEB_MODULE);
-								deps.add(jmxName);
-							} else {
-								throw new DeploymentException(
-										"Could not locate WAR subdeployment matching: "
-												+ deployable);
-							}
-						} while (esbDepends.hasNext());
-					}
-				} finally {
-					in.close();
-				}
-			}
+      final String namespaceURI = "http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd" ;
+      
+      final XPath xpathEvaluater = XPathFactory.newInstance().newXPath();
+      final XPathNamespaceContext namespaceContext = new XPathNamespaceContext() ;
+      namespaceContext.setMapping("jbesb", namespaceURI) ;
+      xpathEvaluater.setNamespaceContext(namespaceContext) ;
 
-			final InputStream inputStream = document.openStream();
-			final String jbossEsbXml;
-			try {
-				final StringWriter sw = new StringWriter();
-				XMLHelper.replaceSystemProperties(XMLHelper
-						.getXMLStreamReader(inputStream), XMLHelper
-						.getXMLStreamWriter(sw));
-				jbossEsbXml = sw.toString();
-			} finally {
-				inputStream.close();
-			}
+      final NodeList actionList = (NodeList) xpathEvaluater.evaluate("/jbesb:jbossesb/jbesb:services/jbesb:service/jbesb:actions/jbesb:action",
+              rootElement, XPathConstants.NODESET) ; 
+      final int numActions = actionList.getLength() ;
+      if (numActions > 0)
+      {
+          final Set<String> actionClasses = new HashSet<String>() ;
+          for(int count = 0 ; count < numActions ; count++)
+          {
+              final Node actionNode = actionList.item(count) ;
+              if (!(actionNode instanceof Element))
+              {
+                  log.warn("Action node is not an element: " + actionNode) ;
+              }
+              else
+              {
+                  final Element actionElement = (Element)actionNode ;
+                  final String actionClass = actionElement.getAttribute("class") ;
+                  actionClasses.add(actionClass) ;
+              }
+          }
+          
+          final int numActionClasses = actionClasses.size() ;
+          if (numActionClasses > 0)
+          {
+              for(final String actionClass: actionClasses)
+              {
+                  final String artifact = (String)actionArtifactProperties.get(actionClass) ;
+                  if (artifact != null)
+                  {
+                      artifacts.add(artifact) ;
+                  }
+              }
+          }
+      }
+      
+      for(final String artifact: artifacts)
+      {
+          if (!deploymentName.equals(artifact))
+          {
+              final String canonicalName = PREFIX_CANONICAL_NAME + artifact ;
+              final ObjectName on = ObjectNameConverter.convert(canonicalName) ;
+              deps.add(on) ;
+          }
+      }
+   }
 
-			addActionDependencies(di.shortName, jbossEsbXml, deps);
-
-			JBoss4ESBDeployment deployment = new JBoss4ESBDeployment(
-					jbossEsbXml, di);
-			deployment.setClassloader(di.ucl);
-			String name = PREFIX_CANONICAL_NAME + di.shortName;
-			ObjectName on = ObjectNameConverter.convert(name);
-			// Check that the name is not registered
-			if (server.isRegistered(on) == true) {
-				log.debug("The ESBModule name: " + name
-						+ "is already registered, adding uid="
-						+ System.identityHashCode(deployment));
-				name = name + ",uid=" + System.identityHashCode(deployment);
-				on = ObjectNameConverter.convert(name);
-			}
-			server.registerMBean(deployment, on);
-			di.deployedObject = on;
-			log.debug("Deploying: " + di.url);
-			// Invoke the create life cycle method
-			serviceController.create(di.deployedObject, deps);
-		} catch (Exception e) {
-			throw new DeploymentException("Error during create of ESB Module: "
-					+ di.url, e);
-		}
-		super.create(di);
-	}
-
-	private void addActionDependencies(final String deploymentName,
-			final String configuration, final Set<ObjectName> deps)
-			throws XPathExpressionException, DeploymentException,
-			MalformedObjectNameException {
-		final XmlFileLoader xfl = new XmlFileLoader();
-		final StringReader sr = new StringReader(configuration);
-		final InputSource is = new InputSource(sr);
-		final Element rootElement = xfl.getDocument(is,
-				"META-INF/jboss-esb.xml").getDocumentElement();
-
-		final Set<String> artifacts = new HashSet<String>();
-		artifacts.add(ESB_ARTIFACT_NAME);
-
-		final String namespaceURI = "http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd";
-
-		final XPath xpathEvaluater = XPathFactory.newInstance().newXPath();
-		final XPathNamespaceContext namespaceContext = new XPathNamespaceContext();
-		namespaceContext.setMapping("jbesb", namespaceURI);
-		xpathEvaluater.setNamespaceContext(namespaceContext);
-
-		final NodeList actionList = (NodeList) xpathEvaluater
-				.evaluate(
-						"/jbesb:jbossesb/jbesb:services/jbesb:service/jbesb:actions/jbesb:action",
-						rootElement, XPathConstants.NODESET);
-		final int numActions = actionList.getLength();
-		if (numActions > 0) {
-			final Set<String> actionClasses = new HashSet<String>();
-			for (int count = 0; count < numActions; count++) {
-				final Node actionNode = actionList.item(count);
-				if (!(actionNode instanceof Element)) {
-					log.warn("Action node is not an element: " + actionNode);
-				} else {
-					final Element actionElement = (Element) actionNode;
-					final String actionClass = actionElement
-							.getAttribute("class");
-					actionClasses.add(actionClass);
-				}
-			}
-
-			final int numActionClasses = actionClasses.size();
-			if (numActionClasses > 0) {
-				for (final String actionClass : actionClasses) {
-					final String artifact = (String) actionArtifactProperties
-							.get(actionClass);
-					if (artifact != null) {
-						artifacts.add(artifact);
-					}
-				}
-			}
-		}
-
-		for (final String artifact : artifacts) {
-			if (!deploymentName.equals(artifact)) {
-				final String canonicalName = PREFIX_CANONICAL_NAME + artifact;
-				final ObjectName on = ObjectNameConverter
-						.convert(canonicalName);
-				deps.add(on);
-			}
-		}
-	}
-
-	public synchronized void start(DeploymentInfo di)
-			throws DeploymentException {
-		try {
-			serviceController.start(di.deployedObject);
+   public synchronized void start(DeploymentInfo di)
+           throws DeploymentException
+   {
+      try
+      {
+         serviceController.start(di.deployedObject);
 			if (Configuration.genratedWSWar() && !redployed) {
 				log.debug("Redployed " + di.shortName);
 				redployed = true;
 				mainDeployer.redeploy(di);
 			}
-		} catch (Exception e) {
-			try {
-				stop(di);
-				destroy(di);
-			} catch (DeploymentException ignore) {
-			}
-			throw new DeploymentException("Error during start of ESB Module: "
-					+ di.url, e);
-		}
+      }
+      catch (Exception e)
+      {
+         try
+         {
+            stop(di);
+            destroy(di);
+         }
+         catch (DeploymentException ignore)
+         {
+         }
+         throw new DeploymentException("Error during start of ESB Module: "
+                 + di.url, e);
+      }
 
-		super.start(di);
-	}
+      super.start(di);
+   }
 
-	public void stop(DeploymentInfo di) throws DeploymentException {
-		if (di.deployedObject != null) {
-			try {
-				serviceController.stop(di.deployedObject);
-			} catch (Exception e) {
-				throw new DeploymentException(
-						"Error during stop of ESB Module: " + di.url, e);
-			}
-		}
-		super.stop(di);
-	}
+   public void stop(DeploymentInfo di)
+           throws DeploymentException
+   {
+      if (di.deployedObject != null)
+      {
+         try
+         {
+            serviceController.stop(di.deployedObject);
+         }
+         catch (Exception e)
+         {
+            throw new DeploymentException("Error during stop of ESB Module: "
+                    + di.url, e);
+         }
+      }
+      super.stop(di);
+   }
 
-	public void destroy(DeploymentInfo di) throws DeploymentException {
-		if (di.deployedObject != null) {
-			try {
-				serviceController.destroy(di.deployedObject);
-				server.unregisterMBean(di.deployedObject);
-			} catch (Exception e) {
-				throw new DeploymentException(
-						"Error during stop of ESB Module: " + di.url, e);
-			}
-		}
-		super.destroy(di);
-	}
+   public void destroy(DeploymentInfo di)
+           throws DeploymentException
+   {
+      if (di.deployedObject != null)
+      {
+         try
+         {
+            serviceController.destroy(di.deployedObject);
+            server.unregisterMBean(di.deployedObject);
+         }
+         catch (Exception e)
+         {
+            throw new DeploymentException("Error during stop of ESB Module: "
+                    + di.url, e);
+         }
+      }
+      super.destroy(di);
+   }
 }

Modified: labs/jbossesb/workspace/jimma/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/ServicePublisherUnitTest.java
===================================================================
--- labs/jbossesb/workspace/jimma/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/ServicePublisherUnitTest.java	2008-06-24 14:13:11 UTC (rev 20732)
+++ labs/jbossesb/workspace/jimma/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/ServicePublisherUnitTest.java	2008-06-24 14:21:16 UTC (rev 20733)
@@ -1,12 +1,10 @@
 package org.jboss.soa.esb.listeners.config;
 
-import java.io.File;
 import java.io.IOException;
 import java.util.List;
 
 import junit.framework.TestCase;
 
-import org.apache.commons.io.FileUtils;
 import org.jboss.internal.soa.esb.publish.ServiceContractPublisher;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.addressing.EPR;
@@ -20,70 +18,41 @@
  */
 public class ServicePublisherUnitTest extends TestCase {
 
-	public void test() throws ConfigurationException, IOException {
-		Generator generator;
-		ManagedLifecycleController controller1 = new ManagedLifecycleController(
-				null); // TODO:
-		// Introduce
-		// an
-		// interface
-		// and
-		// Mock
-		// for
-		// ManagedLifecycleController
-		ManagedLifecycleController controller2 = new ManagedLifecycleController(
-				null); // TODO:
-		// Introduce
-		// an
-		// interface
-		// and
-		// Mock
-		// for
-		// ManagedLifecycleController
+    public void test() throws ConfigurationException, IOException {
+        Generator generator;
+        ManagedLifecycleController controller1 = new ManagedLifecycleController(null); // TODO: Introduce an interface and Mock for ManagedLifecycleController
+        ManagedLifecycleController controller2 = new ManagedLifecycleController(null); // TODO: Introduce an interface and Mock for ManagedLifecycleController
 
-		generator = new Generator(getClass().getResourceAsStream(
-				"jbossesb_config_04.xml"));
-		ServicePublisher
-				.addServicePublishers(controller1, generator.getModel());
-		List<ServicePublisher> publishers = ServicePublisher
-				.getServicePublishers();
-		assertEquals(2, publishers.size());
-		assertEquals("A1", publishers.get(0).getCategory()
-				+ publishers.get(0).getServiceName());
-		assertEquals(null, publishers.get(0).getContractPublisher());
-		assertEquals("B2", publishers.get(1).getCategory()
-				+ publishers.get(1).getServiceName());
-		assertEquals(null, publishers.get(1).getContractPublisher());
+        generator = new Generator(getClass().getResourceAsStream("jbossesb_config_04.xml"));
+        ServicePublisher.addServicePublishers(controller1, generator.getModel());
+        List<ServicePublisher> publishers = ServicePublisher.getServicePublishers();
+        assertEquals(2, publishers.size());
+        assertEquals("A1", publishers.get(0).getCategory() + publishers.get(0).getServiceName());
+        assertEquals(null, publishers.get(0).getContractPublisher());
+        assertEquals("B2", publishers.get(1).getCategory() + publishers.get(1).getServiceName());
+        assertEquals(null, publishers.get(1).getContractPublisher());
 
-		generator = new Generator(getClass().getResourceAsStream(
-				"jbossesb_config_05.xml"));
-		ServicePublisher
-				.addServicePublishers(controller2, generator.getModel());
-		publishers = ServicePublisher.getServicePublishers();
-		assertEquals(4, publishers.size());
-		assertEquals("A1", publishers.get(0).getCategory()
-				+ publishers.get(0).getServiceName());
-		assertEquals(null, publishers.get(0).getContractPublisher());
-		assertEquals("B2", publishers.get(1).getCategory()
-				+ publishers.get(1).getServiceName());
-		assertEquals(null, publishers.get(1).getContractPublisher());
-		assertEquals("C3", publishers.get(2).getCategory()
-				+ publishers.get(2).getServiceName());
-		assertEquals(null, publishers.get(2).getContractPublisher());
-		assertEquals("D4", publishers.get(3).getCategory()
-				+ publishers.get(3).getServiceName());
-		assertTrue(publishers.get(3).getContractPublisher() instanceof MockContractPublisher);
+        generator = new Generator(getClass().getResourceAsStream("jbossesb_config_05.xml"));
+        ServicePublisher.addServicePublishers(controller2, generator.getModel());
+        publishers = ServicePublisher.getServicePublishers();
+        assertEquals(4, publishers.size());
+        assertEquals("A1", publishers.get(0).getCategory() + publishers.get(0).getServiceName());
+        assertEquals(null, publishers.get(0).getContractPublisher());
+        assertEquals("B2", publishers.get(1).getCategory() + publishers.get(1).getServiceName());
+        assertEquals(null, publishers.get(1).getContractPublisher());
+        assertEquals("C3", publishers.get(2).getCategory() + publishers.get(2).getServiceName());
+        assertEquals(null, publishers.get(2).getContractPublisher());
+        assertEquals("D4", publishers.get(3).getCategory() + publishers.get(3).getServiceName());
+        assertTrue(publishers.get(3).getContractPublisher() instanceof MockContractPublisher);
 
-		ServicePublisher.removeServicePublishers(controller1);
-		publishers = ServicePublisher.getServicePublishers();
-		assertEquals(2, publishers.size());
-		assertEquals("C3", publishers.get(0).getCategory()
-				+ publishers.get(0).getServiceName());
-		assertEquals(null, publishers.get(0).getContractPublisher());
-		assertEquals("D4", publishers.get(1).getCategory()
-				+ publishers.get(1).getServiceName());
-		assertTrue(publishers.get(1).getContractPublisher() instanceof MockContractPublisher);
-	}
+        ServicePublisher.removeServicePublishers(controller1);
+        publishers = ServicePublisher.getServicePublishers();
+        assertEquals(2, publishers.size());
+        assertEquals("C3", publishers.get(0).getCategory() + publishers.get(0).getServiceName());
+        assertEquals(null, publishers.get(0).getContractPublisher());
+        assertEquals("D4", publishers.get(1).getCategory() + publishers.get(1).getServiceName());
+        assertTrue(publishers.get(1).getContractPublisher() instanceof MockContractPublisher);
+    }
 
 	public void testEsbServicePublisher() throws ConfigurationException,
 			IOException {
@@ -106,9 +75,6 @@
 			EPR epr = registry.findEPR(publishers.get(2).getCategory(),
 					publishers.get(2).getServiceName());
 			assertNotNull(publishers.get(2).getContractPublisher().getContractInfo(epr).getData());
-            //File file = new File("/home/jimma/project/jbossesb/workspace/jimma/product/tmp.wsdl");
-            //file.createNewFile();
-			//FileUtils.writeStringToFile(file, publishers.get(2).getContractPublisher().getContractInfo(epr).getData());
 			configUtil.stopController();
 
 		} catch (Exception e) {




More information about the jboss-svn-commits mailing list