[jboss-svn-commits] JBL Code SVN: r11917 - in labs/jbossesb/workspace/rearch2/core: etc/schemas/xml/common and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu May 17 17:14:11 EDT 2007


Author: mark.little at jboss.com
Date: 2007-05-17 17:14:11 -0400 (Thu, 17 May 2007)
New Revision: 11917

Added:
   labs/jbossesb/workspace/rearch2/core/etc/schemas/test/resources/hierarchy.xml
   labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/ContractManager.java
   labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/DummyDispatcher.java
   labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/DummyDispatcherPlugin.java
Removed:
   labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/Contract.java
Modified:
   labs/jbossesb/workspace/rearch2/core/etc/schemas/xml/common/dispatcher.xsd
   labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/internal/soa/esb/infrastructure/DispatcherManager.java
   labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/Dispatcher.java
   labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/DispatcherFactory.java
   labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/plugin/DispatcherPlugin.java
   labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullReceiverDispatcher.java
   labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullReceiverDispatcherPlugin.java
   labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullSenderDispatcher.java
   labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullSenderDispatcherPlugin.java
   labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/tests/DispatcherUnitTest.java
Log:


Added: labs/jbossesb/workspace/rearch2/core/etc/schemas/test/resources/hierarchy.xml
===================================================================
--- labs/jbossesb/workspace/rearch2/core/etc/schemas/test/resources/hierarchy.xml	                        (rev 0)
+++ labs/jbossesb/workspace/rearch2/core/etc/schemas/test/resources/hierarchy.xml	2007-05-17 21:14:11 UTC (rev 11917)
@@ -0,0 +1,28 @@
+<disp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<hierarchy>
+	  	<dispatcher>
+	  		<identifier>
+	  			dispatcher:nullreceiver
+	  		</identifier>
+	  		<root>
+	  			true
+	  		</root>
+	  		<link>
+	  			dispatcher:nullsender
+	  		</link>
+	  	</dispatcher>
+	  	<dispatcher>
+	  		<identifier>
+	  			dispatcher:nullsender
+	  		</identifier>
+	  		<link>
+	  			dispatcher:dummy
+	  		</link>
+	  	</dispatcher>
+	  	<dispatcher>
+	  		<identifier>
+	  			dispatcher:dummy
+	  		</identifier>
+	  	</dispatcher>
+	</hierarchy>
+</disp>
\ No newline at end of file

Modified: labs/jbossesb/workspace/rearch2/core/etc/schemas/xml/common/dispatcher.xsd
===================================================================
--- labs/jbossesb/workspace/rearch2/core/etc/schemas/xml/common/dispatcher.xsd	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/etc/schemas/xml/common/dispatcher.xsd	2007-05-17 21:14:11 UTC (rev 11917)
@@ -7,18 +7,19 @@
 		</xs:sequence>
 	</xs:complexType>
 	
-	<xs:complexType name="instance">
+	<xs:complexType name="dispatcher">
 		<xs:sequence>
-			<xs:element maxOccurs="1" name="dispatcher" type="identifier"/>
+			<xs:element minOccurs="1" maxOccurs="1" name="identifier" type="identifier"/>
+			<xs:element minOccurs="0" maxOccurs="1" name="root" type="xs:boolean"/>
+			<xs:element maxOccurs="1" name="link" type="identifier"/>
 			<xs:element minOccurs="0" name="data" type="xs:anySimpleType"/>
 			<xs:element minOccurs="0" name="dependency" type="identifier"/>
 		</xs:sequence>
 	</xs:complexType>
 	
-	<xs:complexType name="type">
-		<xs:choice>
-			<xs:element minOccurs="0" maxOccurs="1" name="dispatcher-template" type="xs:anyURI"/>
-			<xs:element name="dispatcher-identifier" type="instance"/>
-		</xs:choice>
+	<xs:complexType name="hierarchy">
+		<xs:sequence>
+			<xs:element minOccurs="1" type="instance"/>
+		</xs:sequence>
 	</xs:complexType>
 </xs:schema>
\ No newline at end of file

Modified: labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/internal/soa/esb/infrastructure/DispatcherManager.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/internal/soa/esb/infrastructure/DispatcherManager.java	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/internal/soa/esb/infrastructure/DispatcherManager.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -2,7 +2,7 @@
 
 import java.net.URI;
 
-import org.jboss.soa.esb.infrastructure.Contract;
+import org.jboss.soa.esb.infrastructure.ContractManager;
 
 /*
  * JBoss, Home of Professional Open Source
@@ -52,7 +52,7 @@
 
 public class DispatcherManager
 {
-	public void addContract (Contract ct, URI identifier)
+	public void addContract (ContractManager ct, URI identifier)
 	{
 		
 	}

Deleted: labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/Contract.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/Contract.java	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/Contract.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -1,51 +0,0 @@
-package org.jboss.soa.esb.infrastructure;
-
-import java.net.URI;
-
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated 
- * by the @authors tag. All rights reserved. 
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors. 
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A 
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
- * MA  02110-1301, USA.
- * 
- * (C) 2005-2006,
- * @author mark.little at jboss.com
- */
-
-public class Contract
-{
-	// should be the data returned from the XML configuration file
-	public Contract (String fileName)
-	{
-		/*
-		 * Use fileName (xml file) and pull it apart to get info
-		 * on per-dispatcher basis.
-		 */
-	}
-	
-	/**
-	 * Return the configuration information for the dispatcher.
-	 * 
-	 * @param dispatcherName the dispatcher name
-	 * @return the configuration information
-	 */
-	public Object getConfiguration (URI dispatcherName)
-	{
-		if (dispatcherName == null)
-			throw new IllegalArgumentException();
-		
-		return null;
-	}
-	
-}

Copied: labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/ContractManager.java (from rev 11840, labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/Contract.java)
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/ContractManager.java	                        (rev 0)
+++ labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/ContractManager.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -0,0 +1,234 @@
+package org.jboss.soa.esb.infrastructure;
+
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+public class ContractManager
+{
+	public class Contract
+	{	
+		public Contract (URI thisDispatcher, URI linkedDispatcher)
+		{
+			_thisDispatcher = thisDispatcher;
+			_linkedDispatcher = linkedDispatcher;
+			_next = null;
+		}
+		
+		public URI getDispatcher ()
+		{
+			return _thisDispatcher;
+		}
+		
+		public URI getLinkedDispatcher ()
+		{
+			return _linkedDispatcher;
+		}
+
+		public Contract next ()
+		{
+			return _next;
+		}
+		
+		public String toString ()
+		{
+			return "< "+_thisDispatcher+", "+_linkedDispatcher+" >";
+		}
+		
+		private URI _thisDispatcher;
+		private URI _linkedDispatcher;
+		
+		private Contract _next;
+	}
+	
+	public static final String HIERARCHY_TAG = "hierarchy";
+	public static final String DISPATCHER_TAG = "dispatcher";
+	public static final String IDENTIFIER_TAG = "identifier";
+	public static final String LINK_TAG = "link";
+	
+	public ContractManager (String fileName) throws ConfigurationException
+	{
+		/*
+		 * Use fileName (xml file) and pull it apart to get info
+		 * on per-dispatcher basis.
+		 */
+		
+		try
+		{	
+			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+			
+			factory.setNamespaceAware(true);
+			
+			ClassLoader loader = Thread.currentThread().getContextClassLoader();
+			URL url = loader.getResource(fileName);
+			Document doc = null;
+			
+			if (url != null)
+				doc = factory.newDocumentBuilder().parse(url.toString());
+			else
+				doc = factory.newDocumentBuilder().parse(fileName);
+			
+			load(doc);
+		}
+		catch (ConfigurationException ex)
+		{
+			throw ex;
+		}
+		catch (Exception ex)
+		{
+			ex.printStackTrace();
+			
+			throw new ConfigurationException(ex);
+		}
+	}
+	
+	public ContractManager (URI uri) throws ConfigurationException
+	{
+		/*
+		 * Use fileName (xml file) and pull it apart to get info
+		 * on per-dispatcher basis.
+		 */
+		
+		try
+		{			
+			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+			
+			factory.setNamespaceAware(true);
+			
+			Document doc = factory.newDocumentBuilder().parse(uri.toString());
+			
+			load(doc);
+		}
+		catch (ConfigurationException ex)
+		{
+			throw ex;
+		}
+		catch (Exception ex)
+		{
+			ex.printStackTrace();
+			
+			throw new ConfigurationException(ex);
+		}
+	}
+	
+	public Contract getRootContract ()
+	{
+		return _rootContract;
+	}
+	
+	private final void load (Document doc) throws ConfigurationException
+	{
+		/*
+		 * Use fileName (xml file) and pull it apart to get info
+		 * on per-dispatcher basis.
+		 */
+		
+		Contract ptr = null;
+		
+		try
+		{
+			final Element rootElement = doc.getDocumentElement();
+			
+			final NodeList hierarchy = rootElement.getElementsByTagName(DISPATCHER_TAG);
+			
+			if ((hierarchy == null) || (hierarchy.getLength() == 0))
+				throw new ConfigurationException("No valid hierarchy information found.");
+			
+			for (int i = 0; i < hierarchy.getLength(); i++)
+			{
+				final Node entry = hierarchy.item(i);
+				final NodeList data = entry.getChildNodes();
+				URI id = null;
+				URI link = null;
+				
+				for (int j = 0; j < data.getLength(); j++)
+				{
+					final Node child = data.item(j);
+					
+					// TODO the other element types
+					
+					if (child.getNodeName().equals(IDENTIFIER_TAG))
+					{
+						id = new URI(child.getTextContent().trim());
+					}
+					
+					if (child.getNodeName().equals(LINK_TAG))
+					{
+						link = new URI(child.getTextContent().trim());
+					}
+				}
+				
+				/*
+				 * At this point we should have the entire hierarchy. Now
+				 * go through it and tie everything together.
+				 */
+				
+				/*
+				 * Go through the imported information and make sure we can create
+				 * the hierarchy. In most cases it will probably already be in the
+				 * configuration file in the right order. However, with the element
+				 * information present, we can ensure that is the case and throw
+				 * appropriate exceptions if not everything is present/resolvable.
+				 * 
+				 * In Arjuna2 we had to do this all in the ObjectName implementation,
+				 * without the benefit of XML!! Those were the days :-)!!
+				 */
+				
+				// TODO, just assume for now!
+				
+				if (id != null)
+				{
+					Contract tmpContract = new Contract(id, link);
+					
+					if (ptr == null)
+					{
+						_rootContract = tmpContract;
+					}
+					else
+					{
+						ptr._next = tmpContract;
+					}
+					
+					ptr = tmpContract;
+				}
+			}
+		}
+		catch (Exception ex)
+		{
+			ex.printStackTrace();
+			
+			throw new ConfigurationException(ex);
+		}
+	}
+	
+	private Contract _rootContract;
+	
+}

Modified: labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/Dispatcher.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/Dispatcher.java	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/Dispatcher.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -22,7 +22,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
  * MA  02110-1301, USA.
  * 
- * (C) 2005-2006,
+ * (C) 2005-2006, 2007
  * @author mark.little at jboss.com
  */
 
@@ -37,6 +37,14 @@
 {
 	public URI getIdentifier () throws URISyntaxException;
 	
+	/*
+	 * A dispatcher is configured at instantiation time using the
+	 * information provided by the static configuration file. However,
+	 * since each dispatcher is addressable as a serv ice, they can be
+	 * dynamically configured at runtime by sending them appropriate
+	 * messages.
+	 */
+	
     public Message dispatch (Message msg);
     
     /*

Modified: labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/DispatcherFactory.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/DispatcherFactory.java	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/DispatcherFactory.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -22,11 +22,14 @@
  */
 
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Properties;
 
+import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.infrastructure.ContractManager.Contract;
 import org.jboss.soa.esb.infrastructure.plugin.DispatcherPlugin;
 
 import com.arjuna.common.util.propertyservice.PropertyManager;
@@ -48,6 +51,7 @@
 {
 	public static final String DISPATCHER_CONFIGURATION = "?";
 	public static final String DISPATCHER_PLUGIN_NAME = "org.jboss.soa.esb.infrastructure.dispatcherPlugin.";
+	public static final String DISPATCHER_SCHEME = "dispatcher";
 	
 	public static DispatcherFactory getFactory ()
 	{
@@ -55,10 +59,10 @@
 	}
 	
 	/**
-	 * Obtain a Dispatcher (hierarchy) given a contract definition, which specifies the
+	 * Obtain a Dispatcher given a contract definition, which specifies the
 	 * ultimate requirements for the service.
 	 * 
-	 * @param contract the contract definition.
+	 * @param name the contract definition.
 	 * @return a dispatcher instance (which may the root of a hierarchy).This may be a shared instance or a new instance
 	 * depending upon the requirements defined when the dispatcher name was registered with the
 	 * factory.
@@ -69,24 +73,71 @@
 		if (name == null)
 			throw new IllegalArgumentException();
 		
-		DispatcherPlugin plugin = _registeredDispatchers.get(name);
+		if (name.getScheme().equals(DISPATCHER_SCHEME))
+		{
+			DispatcherPlugin plugin = _registeredDispatchers.get(name);
+			
+			if (plugin == null)
+				return null;
+			else
+				return plugin.create();
+		}
+		else
+			throw new IllegalArgumentException("URI is not of dispatcher scheme");
+	}
+	
+	/**
+	 * Obtain a Dispatcher given a contract definition, which specifies the
+	 * ultimate requirements for the service.
+	 * 
+	 * @param contract the contract definition.
+	 * @return a dispatcher instance (which may the root of a hierarchy).This may be a shared instance or a new instance
+	 * depending upon the requirements defined when the dispatcher name was registered with the
+	 * factory.
+	 */
+	
+	public Dispatcher getDispatcherHierarchy (URI contract) throws ConfigurationException
+	{
+		if (contract == null)
+			throw new IllegalArgumentException();
 		
-		if (plugin == null)
-			return null;
+		if (!contract.getScheme().equals(DISPATCHER_SCHEME))
+		{
+			ContractManager theContract = new ContractManager(contract);
+			DispatcherPlugin plugin = _registeredDispatchers.get(theContract.getRootContract().getDispatcher());
+			
+			if (plugin == null)
+				return null;
+			else
+				return plugin.create(theContract.getRootContract());
+		}
 		else
-			return plugin.create();
+			throw new IllegalArgumentException("Not a hierarchy dispatcher.");
 	}
 	
 	/**
-	 * Obtain a Dispatcher (hierarchy) given a class name. The contract definition is implied
-	 * by the specific dispatcher requested.
+	 * Obtain a Dispatcher given a contract definition, which specifies the
+	 * ultimate requirements for the service.
 	 * 
-	 * @param className the name of the class to instantiate.
-	 * @return an instance of the requested dispatcher. This may be a shared instance or a new instance
+	 * @param contract the contract definition.
+	 * @return a dispatcher instance (which may the root of a hierarchy).This may be a shared instance or a new instance
 	 * depending upon the requirements defined when the dispatcher name was registered with the
 	 * factory.
 	 */
 	
+	public Dispatcher getDispatcherHierarchy (Contract contract) throws ConfigurationException
+	{
+		if (contract == null)
+			throw new IllegalArgumentException();
+
+		DispatcherPlugin plugin = _registeredDispatchers.get(contract.getDispatcher());
+			
+		if (plugin == null)
+			return null;
+		else
+			return plugin.create(contract);
+	}
+	
 	/*
 	 * TODO should the classname not be part of the ContractDefinition?
 	 * TODO is this is a different type of contract? ContractDefinition was originally intended
@@ -94,7 +145,7 @@
 	 * part of the service in a way!
 	 */
 	
-	public void addDispatcherPlugin (DispatcherPlugin plugin)
+	public void addDispatcherPlugin (DispatcherPlugin plugin) throws URISyntaxException
 	{
 		if (plugin == null)
 			throw new IllegalArgumentException();
@@ -152,15 +203,11 @@
 						DispatcherPlugin plugin = (DispatcherPlugin) pluginClass.newInstance();
 						
 						if (dispatcherConfiguration != null)
-							plugin.initialize(dispatcherConfiguration);
+							plugin.initialize(dispatcherConfiguration);  // may then do lazy initialization on dispatcher instances created
 						
 						DispatcherFactory._registeredDispatchers.put(dispatcherName, plugin);
 					}
 				}
-				
-				/*
-				 * Add the default implementations.
-				 */
 			}
 		}
 		catch (Throwable ex)

Modified: labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/plugin/DispatcherPlugin.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/plugin/DispatcherPlugin.java	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/src/main/java/org/jboss/soa/esb/infrastructure/plugin/DispatcherPlugin.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -3,7 +3,9 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 
+import org.jboss.soa.esb.infrastructure.ContractManager;
 import org.jboss.soa.esb.infrastructure.Dispatcher;
+import org.jboss.soa.esb.infrastructure.ContractManager.Contract;
 
 /*
  * JBoss, Home of Professional Open Source
@@ -30,7 +32,9 @@
 {
 	public void initialize (URI conf);
 	
-	public Dispatcher create ();
+	public Dispatcher create ();  // returns just a single instance
 	
-	public URI getIdentifier () throws URISyntaxException;
+	public Dispatcher create (Contract hierarchy);  // returns the hierarchy
+	
+	public URI getIdentifier () throws URISyntaxException; // typically the root if it supports hierarchies
 }

Added: labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/DummyDispatcher.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/DummyDispatcher.java	                        (rev 0)
+++ labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/DummyDispatcher.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -0,0 +1,61 @@
+package org.jboss.soa.esb.infrastructure;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.soa.esb.infrastructure.ContractManager.Contract;
+import org.jboss.soa.esb.message.Message;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+/**
+ * This dispatcher does nothing.
+ * 
+ * @author Mark Little
+ *
+ */
+
+public class DummyDispatcher implements Dispatcher
+{
+	public DummyDispatcher ()
+	{
+	}
+	
+	public DummyDispatcher (Contract contract)
+	{
+	}
+	
+	public URI getIdentifier () throws URISyntaxException
+	{
+		return new URI(_identifier);
+	}
+	
+    public Message dispatch (Message msg)
+    {
+    	System.err.println("DUMMY DISPATCHER");
+    	
+    	return msg;
+    }
+    
+    static String _identifier = "dispatcher:dummy";
+}

Added: labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/DummyDispatcherPlugin.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/DummyDispatcherPlugin.java	                        (rev 0)
+++ labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/DummyDispatcherPlugin.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -0,0 +1,62 @@
+package org.jboss.soa.esb.infrastructure;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.soa.esb.infrastructure.ContractManager.Contract;
+import org.jboss.soa.esb.infrastructure.plugin.DispatcherPlugin;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+/**
+ * This dispatcher does nothing.
+ * 
+ * @author Mark Little
+ *
+ */
+
+public class DummyDispatcherPlugin implements DispatcherPlugin
+{
+	public DummyDispatcherPlugin ()
+	{
+	}
+	
+	public void initialize (URI conf)
+	{
+	}
+	
+	public Dispatcher create ()
+	{
+		return new DummyDispatcher();
+	}
+
+	public Dispatcher create (Contract hierarchy) // returns the hierarchy
+	{
+		return new DummyDispatcher(hierarchy);
+	}
+	
+	public URI getIdentifier () throws URISyntaxException
+	{
+		return new URI(DummyDispatcher._identifier);
+	}
+}

Modified: labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullReceiverDispatcher.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullReceiverDispatcher.java	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullReceiverDispatcher.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -3,6 +3,7 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 
+import org.jboss.soa.esb.infrastructure.ContractManager.Contract;
 import org.jboss.soa.esb.message.Message;
 
 /*
@@ -40,6 +41,29 @@
 	{
 	}
 	
+	public NullReceiverDispatcher (Contract contract)
+	{
+		if (contract != null)
+		{
+			try
+			{			
+				if (contract.getDispatcher().equals(getIdentifier()))
+				{
+					// take out our contract and pass the rest along
+			
+					if (contract.next() != null)
+						_link = DispatcherFactory.getFactory().getDispatcherHierarchy(contract.next());
+				}
+				else
+					throw new RuntimeException();
+			}
+			catch (Exception ex)
+			{
+				ex.printStackTrace();
+			}
+		}
+	}
+	
 	public URI getIdentifier () throws URISyntaxException
 	{
 		return new URI(_identifier);
@@ -47,8 +71,15 @@
 	
     public Message dispatch (Message msg)
     {
-    	return null;
+    	System.err.println("NULL RECEIVER");
+    	
+    	if (_link != null)
+    		return _link.dispatch(msg);
+    	else
+    		return null;
     }
     
-    static String _identifier = "urn:nullreceiver";
+    private Dispatcher _link;
+    
+    static String _identifier = "dispatcher:nullreceiver";
 }

Modified: labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullReceiverDispatcherPlugin.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullReceiverDispatcherPlugin.java	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullReceiverDispatcherPlugin.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -3,6 +3,7 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 
+import org.jboss.soa.esb.infrastructure.ContractManager.Contract;
 import org.jboss.soa.esb.infrastructure.plugin.DispatcherPlugin;
 
 /*
@@ -49,6 +50,11 @@
 		return new NullReceiverDispatcher();
 	}
 
+	public Dispatcher create (Contract hierarchy) // returns the hierarchy
+	{
+		return new NullReceiverDispatcher(hierarchy);
+	}
+	
 	public URI getIdentifier () throws URISyntaxException
 	{
 		return new URI(NullReceiverDispatcher._identifier);

Modified: labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullSenderDispatcher.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullSenderDispatcher.java	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullSenderDispatcher.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -3,6 +3,7 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 
+import org.jboss.soa.esb.infrastructure.ContractManager.Contract;
 import org.jboss.soa.esb.message.Message;
 
 /*
@@ -40,6 +41,29 @@
 	{
 	}
 	
+	public NullSenderDispatcher (Contract myContract)
+	{
+		if (myContract != null)
+		{
+			try
+			{
+				if (myContract.getDispatcher().equals(getIdentifier()))
+				{
+					// take out our contract and pass the rest along
+					
+					if (myContract.next() != null)
+						_link = DispatcherFactory.getFactory().getDispatcherHierarchy(myContract.next());
+				}
+				else
+					throw new RuntimeException();
+			}
+			catch (Exception ex)
+			{
+				ex.printStackTrace();
+			}
+		}
+	}
+	
 	public URI getIdentifier () throws URISyntaxException
 	{
 		return new URI(_identifier);
@@ -47,8 +71,15 @@
 	
     public Message dispatch (Message msg)
     {
-    	return null;
+    	System.err.println("NULL SENDER");
+    	
+    	if (_link != null)
+    		return _link.dispatch(msg);
+    	else
+    		return null;
     }
     
-    static String _identifier = "urn:nullsender";
+    private Dispatcher _link;
+    
+    static String _identifier = "dispatcher:nullsender";
 }

Modified: labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullSenderDispatcherPlugin.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullSenderDispatcherPlugin.java	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/NullSenderDispatcherPlugin.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -3,6 +3,7 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 
+import org.jboss.soa.esb.infrastructure.ContractManager.Contract;
 import org.jboss.soa.esb.infrastructure.plugin.DispatcherPlugin;
 
 /*
@@ -49,6 +50,11 @@
 		return new NullSenderDispatcher();
 	}
 
+	public Dispatcher create (Contract hierarchy) // returns the hierarchy
+	{
+		return new NullSenderDispatcher(hierarchy);
+	}
+	
 	public URI getIdentifier () throws URISyntaxException
 	{
 		return new URI(NullSenderDispatcher._identifier);

Modified: labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/tests/DispatcherUnitTest.java
===================================================================
--- labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/tests/DispatcherUnitTest.java	2007-05-17 20:39:25 UTC (rev 11916)
+++ labs/jbossesb/workspace/rearch2/core/src/test/java/org/jboss/soa/esb/infrastructure/tests/DispatcherUnitTest.java	2007-05-17 21:14:11 UTC (rev 11917)
@@ -26,8 +26,10 @@
 
 import junit.framework.TestCase;
 
+import org.jboss.soa.esb.infrastructure.ContractManager;
 import org.jboss.soa.esb.infrastructure.Dispatcher;
 import org.jboss.soa.esb.infrastructure.DispatcherFactory;
+import org.jboss.soa.esb.infrastructure.DummyDispatcherPlugin;
 import org.jboss.soa.esb.infrastructure.NullReceiverDispatcherPlugin;
 import org.jboss.soa.esb.infrastructure.NullSenderDispatcherPlugin;
 
@@ -56,7 +58,7 @@
 	{
 		try
 		{
-			URI dummyName = new URI("urn:foobar");
+			URI dummyName = new URI("dispatcher:foobar");
 			Dispatcher instance = DispatcherFactory.getFactory().getDispatcher(dummyName);
 			
 			assertEquals((instance == null), true);
@@ -91,4 +93,30 @@
 			fail();
 		}
 	}
+	
+	public void testDispatcherHierarchy ()
+	{
+		try
+		{
+			NullSenderDispatcherPlugin senderPlugin = new NullSenderDispatcherPlugin();
+			NullReceiverDispatcherPlugin receiverPlugin = new NullReceiverDispatcherPlugin();
+			DummyDispatcherPlugin dummyPlugin = new DummyDispatcherPlugin();
+			
+			DispatcherFactory.getFactory().addDispatcherPlugin(senderPlugin);
+			DispatcherFactory.getFactory().addDispatcherPlugin(receiverPlugin);
+			DispatcherFactory.getFactory().addDispatcherPlugin(dummyPlugin);
+			
+			ContractManager theContract = new ContractManager("etc/schemas/test/resources/hierarchy.xml");
+			
+			Dispatcher root = DispatcherFactory.getFactory().getDispatcherHierarchy(theContract.getRootContract());
+			
+			root.dispatch(null);
+		}
+		catch (Exception ex)
+		{
+			ex.printStackTrace();
+			
+			fail();
+		}
+	}
 }




More information about the jboss-svn-commits mailing list