[jboss-svn-commits] JBL Code SVN: r9367 - in labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml: marshal and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Feb 6 04:54:06 EST 2007


Author: mark.little at jboss.com
Date: 2007-02-06 04:54:06 -0500 (Tue, 06 Feb 2007)
New Revision: 9367

Modified:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/SerializedMarshalUnmarshalPlugin.java
Log:
http://jira.jboss.com/jira/browse/JBESB-383

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java	2007-02-06 07:19:34 UTC (rev 9366)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java	2007-02-06 09:54:06 UTC (rev 9367)
@@ -46,6 +46,12 @@
 
 	public static final String BYTES_TAG = "Bytes";
 
+	public static final String CONTENT_TAG = "Content";
+
+	public static final String KEY_TAG = "Key";
+
+	public static final String VALUE_TAG = "Value";
+
 	public BodyImpl()
 	{
 		_content = null;
@@ -121,11 +127,21 @@
 			String key = keys.nextElement();
 			Object value = _objects.get(key);
 
-			Element objElement = doc.createElement(key);
+			Element objElement = doc.createElement(CONTENT_TAG);
+			Element keyElement = doc.createElement(KEY_TAG);
+			Element valueElement = doc.createElement(VALUE_TAG);
 
-			if (MarshalUnmarshalManager.getInstance()
-					.marshal(objElement, value))
+			keyElement.appendChild(doc.createCDATASection(Base64
+					.encodeBytes(key.getBytes())));
+
+			objElement.appendChild(keyElement);
+			objElement.appendChild(valueElement);
+
+			if (MarshalUnmarshalManager.getInstance().marshal(valueElement,
+					value))
+			{
 				bodyElement.appendChild(objElement);
+			}
 			else
 				throw new MarshalException("Cannot pack object " + key);
 		}
@@ -154,12 +170,15 @@
 				for (int j = 0; j < children.getLength(); j++)
 				{
 					Object xxx = children.item(j);
+
 					if (!(xxx instanceof Element))
 						continue;
-					Element child = (Element) xxx;
-					if (child.getNodeName().equals(BYTES_TAG))
+
+					Element node = (Element) xxx;
+
+					if (node.getNodeName().equals(BYTES_TAG))
 					{
-						CDATASection cdata = (CDATASection) child
+						CDATASection cdata = (CDATASection) node
 								.getFirstChild();
 
 						// support empty byte (null files etc.)
@@ -171,24 +190,38 @@
 					}
 					else
 					{
-						Node node = child.getFirstChild();
-						
-						while (!(node instanceof Element))
+						if (node.getNodeName().equals(CONTENT_TAG))
 						{
-							node = node.getNextSibling();
-						}
-						
-						if (node instanceof Element)
-						{
-							final Object value = MarshalUnmarshalManager
-									.getInstance().unmarshal((Element) node);
-							
+							final NodeList childList = node.getChildNodes();
+
+							String key = null;
+							Object value = null;
+
+							for (int k = 0; k < childList.getLength(); k++)
+							{
+								if (childList.item(k).getNodeName().equals(
+										VALUE_TAG))
+									value = MarshalUnmarshalManager
+											.getInstance()
+											.unmarshal(
+													(Element) childList.item(k));
+
+								if (childList.item(k).getNodeName().equals(
+										KEY_TAG))
+								{
+									CDATASection cdata = (CDATASection) childList.item(k).getFirstChild();
+
+									key = new String(Base64.decode(cdata
+											.getWholeText()));
+								}
+							}
+
 							if (value == null)
 								throw new UnmarshalException(
 										"Cannot unpack object "
-												+ child.getNodeName());
+												+ node.getNodeName());
 							else
-								_objects.put(child.getNodeName(), value);
+								_objects.put(key, value);
 						}
 					}
 				}

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java	2007-02-06 07:19:34 UTC (rev 9366)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java	2007-02-06 09:54:06 UTC (rev 9367)
@@ -193,6 +193,8 @@
 		}
 		catch (Exception ex)
 		{
+			ex.printStackTrace();
+			
 			throw new UnmarshalException(ex);
 		}
 	}

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/SerializedMarshalUnmarshalPlugin.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/SerializedMarshalUnmarshalPlugin.java	2007-02-06 07:19:34 UTC (rev 9366)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/SerializedMarshalUnmarshalPlugin.java	2007-02-06 09:54:06 UTC (rev 9367)
@@ -34,19 +34,20 @@
  */
 
 /**
- * Used to plug in new Object marshal/unmarshal formats dynamically. When packing
- * objects in XML, the system runs through the list of registered plug-ins until it
- * finds one that can deal with the object type (or faults). When packing, the name (type)
- * of the plug-in that packed the object is also attached to facilitate unpacking.
- *  
+ * Used to plug in new Object marshal/unmarshal formats dynamically. When
+ * packing objects in XML, the system runs through the list of registered
+ * plug-ins until it finds one that can deal with the object type (or faults).
+ * When packing, the name (type) of the plug-in that packed the object is also
+ * attached to facilitate unpacking.
+ * 
  * @author Mark Little
- *
+ * 
  */
 
 public class SerializedMarshalUnmarshalPlugin implements MarshalUnmarshalPlugin
 {
 
-	public SerializedMarshalUnmarshalPlugin ()
+	public SerializedMarshalUnmarshalPlugin()
 	{
 		try
 		{
@@ -57,101 +58,118 @@
 			ex.printStackTrace();
 		}
 	}
-	
+
 	/**
 	 * Pack the provided object into the document.
 	 * 
-	 * @param doc the XML document.
-	 * @param param the object to pack.
+	 * @param doc
+	 *            the XML document.
+	 * @param param
+	 *            the object to pack.
 	 * 
-	 * @return <code>true</code> if the object was packed, <code>false</code> otherwise.
-	 * @throws MarshalException thrown if there is a problem packing.
+	 * @return <code>true</code> if the object was packed, <code>false</code>
+	 *         otherwise.
+	 * @throws MarshalException
+	 *             thrown if there is a problem packing.
 	 */
-	
-	public boolean marshal (Element doc, Object param) throws MarshalException
+
+	public boolean marshal(Element doc, Object param) throws MarshalException
 	{
 		if (param instanceof Serializable)
 		{
 			// we can deal with this type!
-			
+
 			try
 			{
-				Element nodeElement = doc.getOwnerDocument().createElement(MarshalUnmarshalPlugin.tagName);
-				
-				Element pluginType = doc.getOwnerDocument().createElement(MarshalUnmarshalPlugin.pluginType);
-				pluginType.appendChild(doc.getOwnerDocument().createTextNode(type().toString()));
+				Element nodeElement = doc.getOwnerDocument().createElement(
+						MarshalUnmarshalPlugin.tagName);
+
+				Element pluginType = doc.getOwnerDocument().createElement(
+						MarshalUnmarshalPlugin.pluginType);
+				pluginType.appendChild(doc.getOwnerDocument().createTextNode(
+						type().toString()));
 				nodeElement.appendChild(pluginType);
-				
-				nodeElement.appendChild(doc.getOwnerDocument().createCDATASection(Base64.encodeObject((Serializable) param)));
-				
+
+				nodeElement.appendChild(doc.getOwnerDocument()
+						.createCDATASection(
+								Base64.encodeObject((Serializable) param)));
+
 				doc.appendChild(nodeElement);
 			}
 			catch (Exception ex)
 			{
 				ex.printStackTrace();
-				
+
 				throw new MarshalException(ex);
 			}
-			
+
 			return true;
 		}
 		else
 			return false;
 	}
-	
+
 	/**
 	 * Unpack the object from the document.
 	 * 
-	 * @param doc the document.
+	 * @param doc
+	 *            the document.
 	 * 
-	 * @return the object, or <code>null</code> if this implementation cannot deal with the
-	 * format.
-	 * @throws UnmarshalException thrown if there is a problem unpacking.
+	 * @return the object, or <code>null</code> if this implementation cannot
+	 *         deal with the format.
+	 * @throws UnmarshalException
+	 *             thrown if there is a problem unpacking.
 	 */
-	
-	public Object unmarshal (Element doc) throws UnmarshalException
+
+	public Object unmarshal(Element doc) throws UnmarshalException
 	{
 		try
 		{
-			if (doc.getNodeName().equals(MarshalUnmarshalPlugin.tagName))
+			NodeList nl = doc.getChildNodes();
+
+			for (int i = 0; i < nl.getLength(); i++)
 			{
-				NodeList nl = doc.getChildNodes();
-				
-				for (int i = 0; i < nl.getLength(); i++)
+				if (nl.item(i).getNodeName().equals(MarshalUnmarshalPlugin.tagName))
 				{
-					Node el = nl.item(i);
-					
-					if (el.getNodeName().equals(MarshalUnmarshalPlugin.pluginType))
+					NodeList childList = nl.item(i).getChildNodes();
+
+					for (int j = 0; j < childList.getLength(); j++)
 					{
-						if (el.getTextContent().equals(type().toString()))
+						Node el = childList.item(j);
+
+						if (el.getNodeName().equals(
+								MarshalUnmarshalPlugin.pluginType))
 						{
-							CDATASection cdata = (CDATASection) nl.item(i+1);
-							
-							return Base64.decodeToObject(cdata.getWholeText());
+							if (el.getTextContent().equals(type().toString()))
+							{
+								CDATASection cdata = (CDATASection) childList
+										.item(j + 1);
+
+								return Base64.decodeToObject(cdata
+										.getWholeText());
+							}
 						}
 					}
 				}
-				
-				return null;
 			}
-			else
-				return null;
+
+			return null;
 		}
 		catch (Exception ex)
 		{
 			throw new UnmarshalException(ex);
 		}
 	}
-	
+
 	/**
 	 * @return the unique name for this plugin.
 	 */
-	
-	public URI type ()
+
+	public URI type()
 	{
 		return _type;
 	}
-	
+
 	private URI _type = null;
-	
+
 }




More information about the jboss-svn-commits mailing list