[jboss-svn-commits] JBL Code SVN: r12434 - labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Jun 9 15:13:22 EDT 2007
Author: mark.little at jboss.com
Date: 2007-06-09 15:13:22 -0400 (Sat, 09 Jun 2007)
New Revision: 12434
Modified:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
Log:
http://jira.jboss.com/jira/browse/JBESB-612
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-06-09 16:04:07 UTC (rev 12433)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java 2007-06-09 19:13:22 UTC (rev 12434)
@@ -43,287 +43,285 @@
public class BodyImpl implements Body
{
- public static final String BODY_TAG = "Body";
+ public static final String BODY_TAG = "Body";
- public static final String BYTES_TAG = "Bytes";
+ public static final String BYTES_TAG = "Bytes";
- public static final String CONTENT_TAG = "Content";
+ public static final String CONTENT_TAG = "Content";
- public static final String KEY_TAG = "Key";
+ public static final String KEY_TAG = "Key";
- public static final String VALUE_TAG = "Value";
+ public static final String VALUE_TAG = "Value";
- public BodyImpl()
- {
- _content = null;
- _objects = new Hashtable<String, Object>();
- }
+ public BodyImpl()
+ {
+ _content = null;
+ _objects = new Hashtable<String, Object>();
+ }
- public void add (Object value)
- {
- add(Body.DEFAULT_LOCATION, value);
- }
-
- public void add(String name, Object value)
- {
- AssertArgument.isNotNull(value, "value");
- if (name == null) {
- name = Body.DEFAULT_LOCATION;
- }
+ public void add (Object value)
+ {
+ add(Body.DEFAULT_LOCATION, value);
+ }
- synchronized (_objects)
- {
- _objects.put(name, value);
- }
- }
+ public void add (String name, Object value)
+ {
+ AssertArgument.isNotNull(value, "value");
+ AssertArgument.isNotNull(name, "name");
- public Object get ()
+ synchronized (_objects)
{
- return get(Body.DEFAULT_LOCATION);
+ _objects.put(name, value);
}
+ }
+
+ public Object get ()
+ {
+ return get(Body.DEFAULT_LOCATION);
+ }
+
+ public Object get (String name)
+ {
+ AssertArgument.isNotNull(name, "name");
- public Object get(String name)
+ synchronized (_objects)
{
- if (name == null) {
- name = Body.DEFAULT_LOCATION;
- }
- synchronized (_objects)
- {
- return _objects.get(name);
- }
+ return _objects.get(name);
}
+ }
- public String[] getNames()
+ public String[] getNames ()
+ {
+ Set<String> keys = _objects.keySet();
+
+ if (keys != null)
{
- Set<String> keys = _objects.keySet();
+ String[] toReturn = new String[keys.size()];
- if (keys != null)
- {
- String[] toReturn = new String[keys.size()];
-
- return keys.toArray(toReturn);
- }
- else
- return null;
+ return keys.toArray(toReturn);
}
+ else
+ return null;
+ }
- public Object remove(String name)
+ public Object remove (String name)
+ {
+ synchronized (_objects)
{
- synchronized (_objects)
- {
- return _objects.remove(name);
- }
+ return _objects.remove(name);
}
+ }
- public Element toXML(Element envelope) throws MarshalException
- {
- Document doc = envelope.getOwnerDocument();
- Element bodyElement = doc.createElement(BODY_TAG);
+ public Element toXML (Element envelope) throws MarshalException
+ {
+ Document doc = envelope.getOwnerDocument();
+ Element bodyElement = doc.createElement(BODY_TAG);
- envelope.appendChild(bodyElement);
+ envelope.appendChild(bodyElement);
- if (_content != null)
- {
- Element byteElement = doc.createElement(BYTES_TAG);
+ if (_content != null)
+ {
+ Element byteElement = doc.createElement(BYTES_TAG);
- byteElement.appendChild(doc.createCDATASection(Base64
- .encodeBytes(_content)));
+ byteElement.appendChild(doc.createCDATASection(Base64
+ .encodeBytes(_content)));
- bodyElement.appendChild(byteElement);
- }
+ bodyElement.appendChild(byteElement);
+ }
- /*
- * This would normally be handled by an external adapter.
- */
+ /*
+ * This would normally be handled by an external adapter.
+ */
- Enumeration<String> keys = _objects.keys();
+ Enumeration<String> keys = _objects.keys();
- while (keys.hasMoreElements())
- {
- String key = keys.nextElement();
- Object value = _objects.get(key);
+ while (keys.hasMoreElements())
+ {
+ String key = keys.nextElement();
+ Object value = _objects.get(key);
- Element objElement = doc.createElement(CONTENT_TAG);
- Element keyElement = doc.createElement(KEY_TAG);
- Element valueElement = doc.createElement(VALUE_TAG);
+ Element objElement = doc.createElement(CONTENT_TAG);
+ Element keyElement = doc.createElement(KEY_TAG);
+ Element valueElement = doc.createElement(VALUE_TAG);
- keyElement.appendChild(doc.createCDATASection(Base64
- .encodeBytes(key.getBytes())));
+ keyElement.appendChild(doc.createCDATASection(Base64
+ .encodeBytes(key.getBytes())));
- objElement.appendChild(keyElement);
- objElement.appendChild(valueElement);
+ objElement.appendChild(keyElement);
+ objElement.appendChild(valueElement);
- if (MarshalUnmarshalManager.getInstance().marshal(valueElement,
- value))
- {
- bodyElement.appendChild(objElement);
- }
- else
- throw new MarshalException("Cannot pack object " + key);
- }
-
- return bodyElement;
+ if (MarshalUnmarshalManager.getInstance().marshal(valueElement,
+ value))
+ {
+ bodyElement.appendChild(objElement);
+ }
+ else
+ throw new MarshalException("Cannot pack object " + key);
}
- public void fromXML(Element envelope) throws UnmarshalException
- {
- NodeList nl = envelope.getChildNodes();
+ return bodyElement;
+ }
- for (int i = 0; i < nl.getLength(); i++)
- {
- /*
- * TODO
- *
- * In the past, bugs in certain Dom implementations mean that
- * getElementsByName did not always work. Still the case? Plus this
- * way is quicker.
- */
+ public void fromXML (Element envelope) throws UnmarshalException
+ {
+ NodeList nl = envelope.getChildNodes();
- if (nl.item(i).getNodeName().equals(BODY_TAG))
- {
- NodeList children = nl.item(i).getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ /*
+ * TODO
+ *
+ * In the past, bugs in certain Dom implementations mean that
+ * getElementsByName did not always work. Still the case? Plus
+ * this way is quicker.
+ */
- for (int j = 0; j < children.getLength(); j++)
- {
- Object xxx = children.item(j);
+ if (nl.item(i).getNodeName().equals(BODY_TAG))
+ {
+ NodeList children = nl.item(i).getChildNodes();
- if (!(xxx instanceof Element))
- continue;
+ for (int j = 0; j < children.getLength(); j++)
+ {
+ Object xxx = children.item(j);
- Element node = (Element) xxx;
+ if (!(xxx instanceof Element))
+ continue;
- if (node.getNodeName().equals(BYTES_TAG))
- {
- CDATASection cdata = (CDATASection) node
- .getFirstChild();
+ Element node = (Element) xxx;
- // support empty byte (null files etc.)
+ if (node.getNodeName().equals(BYTES_TAG))
+ {
+ CDATASection cdata = (CDATASection) node
+ .getFirstChild();
- if (cdata != null)
- _content = Base64.decode(cdata.getWholeText());
- else
- _content = new byte[0];
- }
- else
- {
- if (node.getNodeName().equals(CONTENT_TAG))
- {
- final NodeList childList = node.getChildNodes();
+ // support empty byte (null files etc.)
- String key = null;
- Object value = null;
+ if (cdata != null)
+ _content = Base64.decode(cdata.getWholeText());
+ else
+ _content = new byte[0];
+ }
+ else
+ {
+ if (node.getNodeName().equals(CONTENT_TAG))
+ {
+ final NodeList childList = node.getChildNodes();
- for (int k = 0; k < childList.getLength(); k++)
- {
- if (childList.item(k).getNodeName().equals(
- VALUE_TAG))
- value = MarshalUnmarshalManager
- .getInstance()
- .unmarshal(
- (Element) childList.item(k));
+ String key = null;
+ Object value = null;
- if (childList.item(k).getNodeName().equals(
- KEY_TAG))
- {
- CDATASection cdata = (CDATASection) childList.item(k).getFirstChild();
+ for (int k = 0; k < childList.getLength(); k++)
+ {
+ if (childList.item(k).getNodeName().equals(
+ VALUE_TAG))
+ value = MarshalUnmarshalManager
+ .getInstance()
+ .unmarshal(
+ (Element) childList.item(k));
- key = new String(Base64.decode(cdata
- .getWholeText()));
- }
- }
+ if (childList.item(k).getNodeName().equals(
+ KEY_TAG))
+ {
+ CDATASection cdata = (CDATASection) childList
+ .item(k).getFirstChild();
- if (value == null)
- throw new UnmarshalException(
- "Cannot unpack object "
- + node.getNodeName());
- else
- _objects.put(key, value);
- }
- }
+ key = new String(Base64.decode(cdata
+ .getWholeText()));
}
+ }
+
+ if (value == null)
+ throw new UnmarshalException(
+ "Cannot unpack object "
+ + node.getNodeName());
+ else
+ _objects.put(key, value);
}
+ }
}
+ }
}
+ }
- public void setByteArray(byte[] content)
- {
- _content = content;
- }
+ public void setByteArray (byte[] content)
+ {
+ _content = content;
+ }
- public byte[] getByteArray()
- {
- return _content;
- }
+ public byte[] getByteArray ()
+ {
+ return _content;
+ }
- public void setContents (byte[] content)
- {
- setByteArray(content);
- }
+ public void setContents (byte[] content)
+ {
+ setByteArray(content);
+ }
- public byte[] getContents ()
- {
- return getByteArray();
- }
-
- public void replace(Body b)
- {
- if (b == null)
- throw new IllegalArgumentException();
+ public byte[] getContents ()
+ {
+ return getByteArray();
+ }
- setByteArray(b.getByteArray());
+ public void replace (Body b)
+ {
+ if (b == null)
+ throw new IllegalArgumentException();
- _objects = ((BodyImpl) b)._objects;
- }
+ setByteArray(b.getByteArray());
- public void merge(Body b)
- {
- if (b == null)
- throw new IllegalArgumentException();
+ _objects = ((BodyImpl) b)._objects;
+ }
- byte[] toAdd = b.getByteArray();
+ public void merge (Body b)
+ {
+ if (b == null)
+ throw new IllegalArgumentException();
- if ((toAdd != null) && (toAdd.length > 0))
- {
- if ((_content == null) || (_content.length == 0))
- {
- _content = toAdd;
- }
- else
- {
- int newSize = _content.length + toAdd.length;
- byte[] buffer = new byte[newSize];
+ byte[] toAdd = b.getByteArray();
- System.arraycopy(_content, 0, buffer, 0, _content.length);
- System.arraycopy(toAdd, 0, buffer, _content.length,
- toAdd.length);
+ if ((toAdd != null) && (toAdd.length > 0))
+ {
+ if ((_content == null) || (_content.length == 0))
+ {
+ _content = toAdd;
+ }
+ else
+ {
+ int newSize = _content.length + toAdd.length;
+ byte[] buffer = new byte[newSize];
- _content = buffer;
- }
- }
+ System.arraycopy(_content, 0, buffer, 0, _content.length);
+ System.arraycopy(toAdd, 0, buffer, _content.length,
+ toAdd.length);
- _objects.putAll(((BodyImpl) b)._objects);
+ _content = buffer;
+ }
}
- public String toString ()
+ _objects.putAll(((BodyImpl) b)._objects);
+ }
+
+ public String toString ()
+ {
+ String toReturn = "body: [ ";
+
+ if (_content != null)
+ toReturn += "byte[]: " + Util.format(new String(_content));
+
+ if (_objects != null)
{
- String toReturn = "body: [ ";
-
- if (_content != null)
- toReturn += "byte[]: "+Util.format(new String(_content));
-
- if (_objects != null)
- {
- if (_content != null)
- toReturn += ", ";
-
- toReturn += "objects: "+_objects.toString();
- }
-
- return toReturn+" ]";
+ if (_content != null)
+ toReturn += ", ";
+
+ toReturn += "objects: " + _objects.toString();
}
-
- private byte[] _content;
- private Hashtable<String, Object> _objects;
+ return toReturn + " ]";
+ }
+ private byte[] _content;
+
+ private Hashtable<String, Object> _objects;
+
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list