[jboss-svn-commits] JBL Code SVN: r6347 - in labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss: internal/soa/esb/message/format/serialized internal/soa/esb/message/format/xml soa/esb/message

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Sep 21 17:55:24 EDT 2006


Author: estebanschifman
Date: 2006-09-21 17:55:19 -0400 (Thu, 21 Sep 2006)
New Revision: 6347

Modified:
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/AttachmentImpl.java
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Attachment.java
Log:
Populate interface Attachment - serialized and XML implementations of it

Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/AttachmentImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/AttachmentImpl.java	2006-09-21 19:10:24 UTC (rev 6346)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/AttachmentImpl.java	2006-09-21 21:55:19 UTC (rev 6347)
@@ -1,7 +1,3 @@
-package org.jboss.internal.soa.esb.message.format.serialized;
-
-import org.jboss.soa.esb.message.Attachment;
-
 /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and others contributors as indicated 
@@ -23,6 +19,13 @@
  * @author mark.little at jboss.com
  */
 
+package org.jboss.internal.soa.esb.message.format.serialized;
+
+import org.jboss.soa.esb.message.Attachment;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.io.Serializable;
+
 /**
  * Messages may contain attachments that do not appear in the main payload body.
  * For example, binary document formats, zip files etc.
@@ -33,4 +36,78 @@
 public class AttachmentImpl implements Attachment, java.io.Serializable
 {
 	private static final long serialVersionUID = 0x0;
+
+	public Object get(String name)
+	{
+		return _table.get(name);
+	}
+
+	public Object put(String name, Object value) 
+	{
+		if (value instanceof Serializable)
+			return _table.put(name,(Serializable)value);
+		throw new IllegalArgumentException("value must be Serializable");
+	}
+
+	public Object remove(String name) 
+	{
+		return _table.remove(name);
+	}
+
+	public String[] getNames() 
+	{
+		return _table.keySet().toArray(new String[_table.size()]);
+	}
+
+	public Object itemAt(int index) throws IndexOutOfBoundsException 
+	{
+		return _list.get(index);
+	}
+
+	public Object removeItemAt(int index) throws IndexOutOfBoundsException 
+	{
+		return _list.remove(index);
+	}
+
+	public Object replaceItemAt(int index, Object value) throws IndexOutOfBoundsException 
+	{
+		if (value instanceof Serializable)
+			return _list.set(index,(Serializable)value);
+		throw new IllegalArgumentException("value must be Serializable");
+	}
+
+	public void addItem(Object value) 
+	{
+		if (value instanceof Serializable)
+			_list.add((Serializable)value);
+		else
+			throw new IllegalArgumentException("value must be Serializable");
+	}
+
+	public void addItemAt(int index, Object value) throws IndexOutOfBoundsException 
+	{
+		if (value instanceof Serializable)
+			_list.add(index,(Serializable)value);
+		else
+			throw new IllegalArgumentException("value must be Serializable");
+	}
+
+	public int getNamedCount() 
+	{
+		return _table.size();
+	}
+	public int getUnnamedCount() 
+	{
+		return _list.size();
+	}
+	public String toString() 
+	{ return new StringBuilder()
+		.append("Attachment - Named:").append(_table.toString())
+		.append(" Unnamed:").append(_list.toString())
+		.toString();
+	}
+
+
+	ArrayList<Serializable> _list = new ArrayList<Serializable>();
+	Hashtable<String,Serializable> _table = new Hashtable<String,Serializable>();
 }

Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java	2006-09-21 19:10:24 UTC (rev 6346)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java	2006-09-21 21:55:19 UTC (rev 6347)
@@ -1,10 +1,3 @@
-package org.jboss.internal.soa.esb.message.format.xml;
-
-import org.jboss.soa.esb.message.Attachment;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
 /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and others contributors as indicated 
@@ -26,6 +19,21 @@
  * @author mark.little at jboss.com
  */
 
+package org.jboss.internal.soa.esb.message.format.xml;
+
+import org.jboss.internal.soa.esb.thirdparty.Base64;
+import org.jboss.soa.esb.message.Attachment;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Map;
+import java.io.Serializable;
+
 /**
  * Messages may contain attachments that do not appear in the main payload body.
  * For example, binary document formats, zip files etc.
@@ -33,20 +41,178 @@
  * @author Mark Little
  */
 
-public class AttachmentImpl implements Attachment
+public class AttachmentImpl implements Attachment, java.io.Serializable
 {
-	public Element toXML (Element envelope)
+	private static final long serialVersionUID = 0x0;
+
+	public Object get(String name)
 	{
-		Document doc = envelope.getOwnerDocument();
-		Element attachmentElement = doc.createElement(XMLUtil.ATTACHMENT_TAG);
+		return _table.get(name);
+	}
+
+	public Object put(String name, Object value) 
+	{
+		if (value instanceof Serializable)
+			return _table.put(name,(Serializable)value);
+		throw new IllegalArgumentException("value must be Serializable");
+	}
+
+	public Object remove(String name) 
+	{
+		return _table.remove(name);
+	}
+
+	public String[] getNames() 
+	{
+		return _table.keySet().toArray(new String[_table.size()]);
+	}
+
+	public Object itemAt(int index) throws IndexOutOfBoundsException 
+	{
+		return _list.get(index);
+	}
+
+	public Object removeItemAt(int index) throws IndexOutOfBoundsException 
+	{
+		return _list.remove(index);
+	}
+
+	public Object replaceItemAt(int index, Object value) throws IndexOutOfBoundsException 
+	{
+		if (value instanceof Serializable)
+			return _list.set(index,(Serializable)value);
+		throw new IllegalArgumentException("value must be Serializable");
+	}
+
+	public void addItem(Object value) 
+	{
+		if (value instanceof Serializable)
+			_list.add((Serializable)value);
+		else
+			throw new IllegalArgumentException("value must be Serializable");
+	}
+
+	public void addItemAt(int index, Object value) throws IndexOutOfBoundsException 
+	{
+		if (value instanceof Serializable)
+			_list.add(index,(Serializable)value);
+		else
+			throw new IllegalArgumentException("value must be Serializable");
+	}
+
+	public int getNamedCount() 
+	{
+		return _table.size();
+	}
+	public int getUnnamedCount() 
+	{
+		return _list.size();
+	}
+	
+	public String toString() 
+	{ return new StringBuilder()
+		.append("Attachment - Named:").append(_table.toString())
+		.append(" Unnamed:").append(_list.toString())
+		.toString();
+	}
+
+	/**
+	 * toXML(elem) - Will build a child element with appropriate values and append it
+	 * to arg0
+	 * @param elem Element - where to add 'this' as a child node 
+	 * @return Element - 'this' as the added Element, or &lt;null&gt; if no properties in table
+	 * and nothing was appended to arg0
+	 * @see XMLUtil.ATTACHMENT_TAG
+	 */
+	public Element toXML(Element elem) 
+	{
+		if (_table.size()<1 && _list.size()<1)
+			return null;
+
+		Document doc = elem.getOwnerDocument();
+		Element thisElement = doc.createElement(XMLUtil.ATTACHMENT_TAG);
+
+		listToXml	(doc, thisElement);
+		tableToXml	(doc, thisElement);
+
+		elem.appendChild(thisElement);
+		return thisElement;
+	}
 		
-		envelope.appendChild(attachmentElement);
-		
-		return attachmentElement;
+	private void tableToXml (Document doc, Element elem)
+	{
+		for (Map.Entry<String,Serializable> oCurr: _table.entrySet())
+		{	
+			Element named = doc.createElement(XMLUtil.NAMED_TAG);
+			named.setAttribute("name",oCurr.getKey());
+			named.appendChild(doc.createCDATASection(Base64.encodeObject(oCurr.getValue())));
+			elem.appendChild(named);
+		}
 	}
+	private void listToXml (Document doc, Element elem)
+	{
+		for (Serializable oCurr: _list)
+		{	
+			Element anonymous = doc.createElement(XMLUtil.UNNAMED_TAG);
+			anonymous.appendChild(doc.createCDATASection(Base64.encodeObject(oCurr)));
+			elem.appendChild(anonymous);
+		}
+	}
+/**
+ * fromXml(elem) - Populate properties found in appropriate child element
+ * @see XMLUtil.ATTACHMENT_TAG
+ * @param elem - Element where to look for child nodes
+ */
+	public void fromXML(Element elem) 
+	{
+		_table.clear();
+		_list.clear();
+
+		NodeList NL = elem.getElementsByTagName(XMLUtil.ATTACHMENT_TAG);
+		for (int i1=0; i1<NL.getLength(); i1++)
+		{	
+			Node oCurr = NL.item(i1);
+			if ((oCurr instanceof Element))
+			{
+				listFromXml	((Element)oCurr);
+				tableFromXml((Element)oCurr);
+			}
+		}
+	}
 	
-	public void fromXML (Element envelope)
+	private void listFromXml(Element elem)
 	{
+		NodeList anonymous = elem.getElementsByTagName(XMLUtil.UNNAMED_TAG);
+		for (int i1=0; i1<anonymous.getLength(); i1++)
+		{
+			Node oCurr = anonymous.item(i1);
+			if (oCurr instanceof Element)
+			{
+				CDATASection cdata = (CDATASection) oCurr.getFirstChild();
+				Object value = Base64.decodeToObject(cdata.getWholeText());				
+				_list.add((Serializable)value);
+			}
+		}
 	}
 	
+	private void tableFromXml(Element elem)
+	{
+		NodeList named = elem.getElementsByTagName(XMLUtil.NAMED_TAG);
+		for (int i1=0; i1<named.getLength(); i1++)
+		{
+			Node oCurr = named.item(i1);
+			if (oCurr instanceof Element)
+			{
+				CDATASection cdata = (CDATASection) oCurr.getFirstChild();
+				String name  = ((Element)oCurr).getAttribute("name");
+				Object value = Base64.decodeToObject(cdata.getWholeText());				
+				_table.put(name,(Serializable)value);
+			}
+		}
+	}
+	
+
+	
+	ArrayList<Serializable> _list = new ArrayList<Serializable>();
+	Hashtable<String,Serializable> _table = new Hashtable<String,Serializable>();
 }

Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java	2006-09-21 19:10:24 UTC (rev 6346)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java	2006-09-21 21:55:19 UTC (rev 6347)
@@ -39,4 +39,7 @@
     public static final String HEADER_TAG = "Header";
     public static final String ENVELOPE_TAG = "Envelope";
     public static final String PROPERTIES_TAG = "Properties";
+    
+    public static final String NAMED_TAG = "Named";
+    public static final String UNNAMED_TAG = "UnNamed";
 }

Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Attachment.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Attachment.java	2006-09-21 19:10:24 UTC (rev 6346)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Attachment.java	2006-09-21 21:55:19 UTC (rev 6347)
@@ -24,11 +24,87 @@
 /**
  * Messages may contain attachments that do not appear in the main payload body.
  * For example, binary document formats, zip files etc.
+ * <br/>Handles both 'named' attachment and a list of 'unnamed' attachments
  * 
  * @author Mark Little
  */
 
 public interface Attachment
 {
-	// TODO
+	/**
+	 * Returns the attachment to which this object maps the specified key. 
+	 * Returns null if the there's no value mapped for this key.
+	 * @param name String - The name of the attachment to get
+	 * @return Object - the value mapped to arg0 or &lt;null&gt; if none
+	 */
+	Object get(String name);
+	/**
+	 * Associates the specified value with the specified name
+	 * If there was already a mapping for this name, the old value is replaced by 
+	 * arg1
+	 * @param name String - the name for the object to be stored
+	 * @param value Object - the object to be associated with the name (arg0)
+	 * @return Object - previous value associated with specified name,
+	 * or null  if there was none
+	 */
+	Object put(String name, Object value);
+	/**
+	 * Removes the mapping for this name if it was present
+	 * @param name String - the name of the object to be removed
+	 * @return the value previously associated the name, or null if there was none
+	 */
+	Object remove(String name);
+	/**
+	 * @return String[] - the list of names of the named Objects
+	 */
+	String[] getNames();
+
+	/**
+     * get the item at the specified position in the list of unnamed objects
+     * @param index int - index of element to return
+     * @return Object the element at the specified position in the list of unnamed objects
+     * @throws IndexOutOfBoundsException - if the index is out of range
+     */
+	Object itemAt 		(int index) throws IndexOutOfBoundsException;
+	/**
+	 * Removes the element at the specified position in the list of unnamed objects
+	 * Shifts any subsequent elements to the left 
+	 * @param index int - index of element to remove
+	 * @return Object - the element that was removed from the list
+	 * @throws IndexOutOfBoundsException - if the index is out of range
+	 */
+	Object removeItemAt	(int index) throws IndexOutOfBoundsException;
+	/**
+	 * Replaces the element at the specified position in the list of unnamed objects 
+	 * with the value supplied
+	 * @param index int - index of element to be replaced
+	 * @param  value Object - the object to replace the one previously stored at that index
+	 * @return Object - previous value at that index
+	 * @throws IndexOutOfBoundsException - if the index is out of range
+	 */
+	Object replaceItemAt(int index, Object value) throws IndexOutOfBoundsException;
+	/**
+	 * Appends the specified element to the end of the list of unnamed objects
+	 * <br/>null values are allowed 
+	 * @param value Object - the object to be appended
+	 */
+	void addItem		(Object value);
+	/**
+	 * Replaces the element at the specified position in the list of unnamed objects
+	 * <br/> allows null values
+	 * @param index int - index where to insert the value - Shifts any subsequent elements to the right
+	 * @param value Object - value to be stored at the specified position
+	 * @throws IndexOutOfBoundsException
+	 */
+	void addItemAt	(int index, Object value) throws IndexOutOfBoundsException;
+	/**
+	 * getUnnamedCount()
+	 * @return the count of unnamed objects
+	 */
+	int	getUnnamedCount();
+	/**
+	 * getNamedCount()
+	 * @return the count of named objects
+	 */
+	public int getNamedCount(); 
 }




More information about the jboss-svn-commits mailing list