[jboss-svn-commits] JBL Code SVN: r6333 - 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
Wed Sep 20 16:45:18 EDT 2006


Author: estebanschifman
Date: 2006-09-20 16:45:12 -0400 (Wed, 20 Sep 2006)
New Revision: 6333

Added:
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/PropertiesImpl.java
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/PropertiesImpl.java
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Properties.java
Modified:
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java
   labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Message.java
Log:
Added properties handling to Message, serializable.MessageImpl and xml.MessageImpl

Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java	2006-09-20 19:04:16 UTC (rev 6332)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java	2006-09-20 20:45:12 UTC (rev 6333)
@@ -1,15 +1,3 @@
-package org.jboss.internal.soa.esb.message.format.serialized;
-
-import org.jboss.soa.esb.message.Attachment;
-import org.jboss.soa.esb.message.Body;
-import org.jboss.soa.esb.message.Context;
-import org.jboss.soa.esb.message.Fault;
-import org.jboss.soa.esb.message.Header;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageType;
-
-import java.net.URI;
-
 /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and others contributors as indicated 
@@ -30,7 +18,21 @@
  * (C) 2005-2006,
  * @author mark.little at jboss.com
  */
+package org.jboss.internal.soa.esb.message.format.serialized;
 
+import org.jboss.soa.esb.message.Attachment;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Context;
+import org.jboss.soa.esb.message.Fault;
+import org.jboss.soa.esb.message.Header;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.message.Properties;
+
+import java.net.URI;
+import java.io.Serializable;
+
+
 /**
  * This is the basic internal core message abstraction. A message consists of the following
  * components:
@@ -51,7 +53,7 @@
  *
  */
 
-public class MessageImpl implements Message, java.io.Serializable
+public class MessageImpl implements Message, Serializable
 {
 	private static final long serialVersionUID = 0x0;
 	
@@ -110,10 +112,18 @@
 		return MessageType.JAVA_SERIALIZED;
 	}
 
+	/**
+	 * @return Map<String,Object> - any message properties.
+	 */
+	public Properties getProperties() 
+	{
+		return _properties;
+	}
+
 	private HeaderImpl _theHeader = new HeaderImpl();
 	private ContextImpl _theContext = new ContextImpl();
 	private BodyImpl _theBody = new BodyImpl();
 	private FaultImpl _theFault = new FaultImpl();
 	private AttachmentImpl _theAttachment = new AttachmentImpl();
-	
+	private Properties _properties = new PropertiesImpl();
 }

Added: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/PropertiesImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/PropertiesImpl.java	2006-09-20 19:04:16 UTC (rev 6332)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/PropertiesImpl.java	2006-09-20 20:45:12 UTC (rev 6333)
@@ -0,0 +1,53 @@
+/*
+ * 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 schifest at heuristica.com.ar
+ */
+package org.jboss.internal.soa.esb.message.format.serialized;
+
+import org.jboss.soa.esb.message.Properties;
+
+import java.util.Hashtable;
+import java.io.Serializable;
+
+public class PropertiesImpl implements Properties
+{
+
+	public Object getProperty(String name) {
+		return _table.get(name);
+	}
+
+	public Object getProperty(String name, Object defaultVal) {
+		Object oRet = getProperty(name);
+		return (null==oRet) ? defaultVal : oRet;
+	}
+
+	public Object setProperty(String name, Object value) 
+	{
+		if (value instanceof Serializable)
+			return _table.put(name,(Serializable)value);
+		else
+			throw new IllegalArgumentException("Value must be serializable");
+	}
+
+	public String[] getNames() {
+		return _table.keySet().toArray(new String[_table.size()]);
+	}
+
+	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/MessageImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java	2006-09-20 19:04:16 UTC (rev 6332)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java	2006-09-20 20:45:12 UTC (rev 6333)
@@ -1,20 +1,3 @@
-package org.jboss.internal.soa.esb.message.format.xml;
-
-import org.jboss.soa.esb.message.Attachment;
-import org.jboss.soa.esb.message.Body;
-import org.jboss.soa.esb.message.Context;
-import org.jboss.soa.esb.message.Fault;
-import org.jboss.soa.esb.message.Header;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageType;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import java.net.URI;
-
 /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and others contributors as indicated 
@@ -35,7 +18,25 @@
  * (C) 2005-2006,
  * @author mark.little at jboss.com
  */
+package org.jboss.internal.soa.esb.message.format.xml;
 
+import org.jboss.soa.esb.message.Attachment;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Context;
+import org.jboss.soa.esb.message.Fault;
+import org.jboss.soa.esb.message.Header;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.message.Properties;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.net.URI;
+
+
 /**
  * This is the basic internal core message abstraction. A message consists of the following
  * components:
@@ -47,6 +48,7 @@
  * Body: the actual payload of the message.
  * Fault: any fault information associated with the message.
  * Attachment: any attachments associated with the message.
+ * Properties: any properties associated with the message.
  * 
  * Each message, once created, has a corresponding element for these 5 components. That element
  * may be empty (<b>NOT NULL</b>). The object representing the element can then be used to act
@@ -56,7 +58,7 @@
  *
  */
 
-public class MessageImpl implements Message
+public class MessageImpl implements Message   // also implement XmlSerializable ?
 {
 	/**
 	 * @return get the header component of the message.
@@ -112,6 +114,14 @@
 	{
 		return MessageType.JBOSS_XML;
 	}
+	/**
+	 * getProperties()
+	 * @return org.jboss.soa.esb.message.Properties - any message properties.
+	 */
+	public Properties getProperties() 
+	{
+		return _theProperties;
+	}
 	
 	// to/from XML here, rather than on individual elements
 	
@@ -130,6 +140,7 @@
 			_theBody.toXML(doc, envelope);
 			_theFault.toXML(doc, envelope);
 			_theAttachment.toXML(doc, envelope);
+			_theProperties.toXML(envelope);
 			
 			return doc;
 		}
@@ -165,7 +176,8 @@
 			_theContext.fromXML(envelope);
 			_theBody.fromXML(envelope);
 			_theFault.fromXML(envelope);
-			_theAttachment.fromXML(envelope);			
+			_theAttachment.fromXML(envelope);
+			_theProperties.fromXML(envelope);
 		}
 		catch (Exception ex)
 		{
@@ -180,5 +192,5 @@
 	private BodyImpl _theBody = new BodyImpl();
 	private FaultImpl _theFault = new FaultImpl();
 	private AttachmentImpl _theAttachment = new AttachmentImpl();
-	
+	private PropertiesImpl _theProperties = new PropertiesImpl();
 }

Added: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/PropertiesImpl.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/PropertiesImpl.java	2006-09-20 19:04:16 UTC (rev 6332)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/PropertiesImpl.java	2006-09-20 20:45:12 UTC (rev 6333)
@@ -0,0 +1,123 @@
+/*
+ * 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 schifest at heuristica.com.ar
+ */
+package org.jboss.internal.soa.esb.message.format.xml;
+
+import org.jboss.soa.esb.message.Properties;
+import org.w3c.dom.*;
+import org.jboss.internal.soa.esb.thirdparty.Base64;
+
+import java.util.Map;
+import java.util.Hashtable;
+import java.io.Serializable;
+
+public class PropertiesImpl implements Properties
+{
+
+	public Object getProperty(String name) {
+		return _table.get(name);
+	}
+
+	public Object getProperty(String name, Object defaultVal) {
+		Object oRet = getProperty(name);
+		return (null==oRet) ? defaultVal : oRet;
+	}
+
+	public Object setProperty(String name, Object value) 
+	{
+		if (value instanceof Serializable)
+			return _table.put(name,(Serializable)value);
+		else
+			throw new IllegalArgumentException("value must be XmlSerializable");
+	}
+
+	public String[] getNames() {
+		return _table.keySet().toArray(new String[_table.size()]);
+	}
+
+	/**
+	 * 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
+	 */
+	public Element toXML(Element elem) 
+	{
+		if (_table.size()<1)
+			return null;
+
+		Document doc = elem.getOwnerDocument();
+		Element thisElement = doc.createElement(THIS_TAG_NAME);
+
+		boolean bAdd = false;
+		for (Map.Entry<String,Serializable> oCurr: _table.entrySet())
+		{	
+			Element oProp = doc.createElement(oCurr.getKey());
+			oProp.appendChild(doc.createCDATASection(Base64.encodeObject(oCurr.getValue())));
+			thisElement.appendChild(oProp);
+			bAdd = true;
+		}
+		if (bAdd)
+		{	elem.appendChild(thisElement);
+			return thisElement;
+		}
+		else
+			return null;
+	}
+/**
+ * fromXml(elem) - Populate properties found in appropriate child element
+ * @see THIS_TAG_NAME
+ * @param elem - Element where to look for child nodes
+ */
+	public void fromXML(Element elem) 
+	{
+		_table.clear();
+
+		NodeList NL = elem.getElementsByTagName(THIS_TAG_NAME);
+		for (int i1=0; i1<NL.getLength(); i1++)
+		{	
+			Node oCurr = NL.item(i1);
+			if (! (oCurr instanceof Element))
+				continue;
+			NodeList props = oCurr.getChildNodes();
+			for (int i2=0; i2<props.getLength(); i2++)
+			{
+				Node oProp = props.item(i2);
+				if (oProp instanceof Element)
+				{
+					CDATASection cdata = (CDATASection) oProp.getFirstChild();
+					Object value = Base64.decodeToObject(cdata.getWholeText());				
+					_table.put(oProp.getNodeName(),(Serializable)value);
+				}
+			}
+		}
+	}
+	
+	public String toString() { return _table.toString(); }
+	
+	/**
+	 * THIS_TAG_NAME - contains tag name for XML
+	 */
+	public static final String THIS_TAG_NAME = "__properties";
+
+	Hashtable<String,Serializable> _table = new Hashtable<String,Serializable>();
+
+}

Modified: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Message.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Message.java	2006-09-20 19:04:16 UTC (rev 6332)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Message.java	2006-09-20 20:45:12 UTC (rev 6333)
@@ -82,4 +82,10 @@
 	
 	public URI getType ();
 	
+	/**
+	 * @return Properties - any message properties.
+	 */
+	
+	public Properties getProperties ();
+	
 }

Added: labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Properties.java
===================================================================
--- labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Properties.java	2006-09-20 19:04:16 UTC (rev 6332)
+++ labs/jbossesb/workspace/rearchitecture/product/core/rosetta/src/org/jboss/soa/esb/message/Properties.java	2006-09-20 20:45:12 UTC (rev 6333)
@@ -0,0 +1,57 @@
+/*
+ * 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 schifest at heuristica.com.ar
+ */
+
+package org.jboss.soa.esb.message;
+
+/**
+ * The message properties hold arbitrary information  in the form
+ * of &lt;String,Object&gt; pairs
+ * 
+ */
+
+public interface Properties {
+	/**
+	 * getProperty(name)
+	 * @param name String - name of property
+	 * @return Object - the value stored under the specified name
+	 */
+	public Object getProperty(String name);
+	/**
+	 * getProperty(name,defaultVal)
+	 * @param name String - name of property
+	 * @param defaultVal Object - value to return if no value found
+	 * @return Object - the value stored under the specified name
+	 */
+	public Object getProperty(String name, Object defaultVal);
+	/**
+	 * setProperty(name,value)
+	 * @param name String - name of property to store
+	 * @param value Object - value of property to store under specified name
+	 * @return Object - the previous value of the specified name, or null if it did not have one
+	 */
+	public Object setProperty(String name, Object value);
+	/**
+	 * getNames()
+	 * @return String[] - containing the names of all properties
+	 */
+	public String[] getNames();
+
+}




More information about the jboss-svn-commits mailing list