[jboss-svn-commits] JBL Code SVN: r15050 - in labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format: xml and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Sep 12 08:26:52 EDT 2007
Author: mark.little at jboss.com
Date: 2007-09-12 08:26:52 -0400 (Wed, 12 Sep 2007)
New Revision: 15050
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
Log:
http://jira.jboss.com/jira/browse/JBESB-1027
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java 2007-09-12 11:40:42 UTC (rev 15049)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java 2007-09-12 12:26:52 UTC (rev 15050)
@@ -1,12 +1,12 @@
package org.jboss.internal.soa.esb.message.format.serialized;
import java.io.Serializable;
-import java.util.Arrays;
import java.util.Hashtable;
import java.util.Set;
import org.jboss.internal.soa.esb.assertion.AssertArgument;
import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.body.content.BytesBody;
import org.jboss.soa.esb.util.Util;
/*
@@ -40,18 +40,17 @@
public BodyImpl()
{
- _content = null;
_objects = new Hashtable<String, Serializable>();
}
public void setByteArray(byte[] content)
{
- _content = content;
+ add(BytesBody.BYTES_LOCATION, content);
}
public byte[] getByteArray()
{
- return _content;
+ return (byte[]) get(BytesBody.BYTES_LOCATION);
}
public void setContents(byte[] content)
@@ -138,46 +137,31 @@
throw new IllegalArgumentException();
BodyImpl toMerge = null;
-
+
if (b instanceof BodyImpl)
- toMerge = (BodyImpl) b;
+ toMerge = (BodyImpl) b;
else
- throw new IllegalArgumentException();
-
+ throw new IllegalArgumentException();
+
_objects.putAll(toMerge._objects);
-
- byte[] toAdd = b.getByteArray();
+ byte[] toAdd = b.getByteArray();
+
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];
-
- System.arraycopy(_content, 0, buffer, 0, _content.length);
- System.arraycopy(toAdd, 0, buffer, _content.length,
- toAdd.length);
-
- _content = buffer;
- }
- }
+ setByteArray(toAdd);
}
public String toString()
{
String toReturn = "body: [ ";
+ byte[] content = getByteArray();
+
+ if (content != null)
+ toReturn += "byte[]: " + Util.format(new String(content));
- if (_content != null)
- toReturn += "byte[]: " + Util.format(new String(_content));
-
if (_objects != null)
{
- if (_content != null)
+ if (content != null)
toReturn += ", ";
toReturn += "objects: " + _objects.toString();
@@ -186,27 +170,24 @@
return toReturn + " ]";
}
- public boolean equals (Object o)
+ public boolean equals(Object o)
{
- if (o instanceof BodyImpl)
- {
- BodyImpl toCompare = (BodyImpl) o;
-
- return Arrays.equals(_content, toCompare._content) && _objects.equals(toCompare._objects);
- }
- else
- return false;
+ if (o instanceof BodyImpl)
+ {
+ BodyImpl toCompare = (BodyImpl) o;
+
+ return _objects.equals(toCompare._objects);
+ }
+ else
+ return false;
}
-
+
// copy constructor.
-
- protected BodyImpl (BodyImpl orig)
+
+ protected BodyImpl(BodyImpl orig)
{
- _content = orig._content;
_objects = orig._objects;
}
-
- protected byte[] _content;
protected Hashtable<String, Serializable> _objects;
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java 2007-09-12 11:40:42 UTC (rev 15049)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java 2007-09-12 12:26:52 UTC (rev 15050)
@@ -1,6 +1,5 @@
package org.jboss.internal.soa.esb.message.format.xml;
-import java.util.Arrays;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Set;
@@ -11,6 +10,7 @@
import org.jboss.soa.esb.MarshalException;
import org.jboss.soa.esb.UnmarshalException;
import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.body.content.BytesBody;
import org.jboss.soa.esb.util.Util;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
@@ -56,22 +56,21 @@
public BodyImpl()
{
- _content = null;
_objects = new Hashtable<String, Object>();
}
- public boolean equals (Object o)
+ public boolean equals(Object o)
{
- if (o instanceof BodyImpl)
- {
- BodyImpl toCompare = (BodyImpl) o;
-
- return Arrays.equals(_content, toCompare._content) && _objects.equals(toCompare._objects);
- }
- else
- return false;
+ if (o instanceof BodyImpl)
+ {
+ BodyImpl toCompare = (BodyImpl) o;
+
+ return _objects.equals(toCompare._objects);
+ }
+ else
+ return false;
}
-
+
public void add(Object value)
{
add(Body.DEFAULT_LOCATION, value);
@@ -132,12 +131,19 @@
envelope.appendChild(bodyElement);
- if (_content != null)
+ /*
+ * Keep separate byte array section for now, in case anyone
+ * is looking for it within the XML (e.g., roll-your-own CBR).
+ */
+
+ byte[] content = getByteArray();
+
+ if (content != null)
{
Element byteElement = doc.createElement(BYTES_TAG);
byteElement.appendChild(doc.createCDATASection(Base64
- .encodeBytes(_content)));
+ .encodeBytes(content)));
bodyElement.appendChild(byteElement);
}
@@ -210,9 +216,9 @@
// support empty byte (null files etc.)
if (cdata != null)
- _content = Base64.decode(cdata.getWholeText());
+ setByteArray(Base64.decode(cdata.getWholeText()));
else
- _content = new byte[0];
+ setByteArray(new byte[0]);
}
else
{
@@ -258,12 +264,12 @@
public void setByteArray(byte[] content)
{
- _content = content;
+ add(BytesBody.BYTES_LOCATION, content);
}
public byte[] getByteArray()
{
- return _content;
+ return (byte[]) get(BytesBody.BYTES_LOCATION);
}
public void setContents(byte[] content)
@@ -292,46 +298,31 @@
throw new IllegalArgumentException();
BodyImpl toMerge = null;
-
+
if (b instanceof BodyImpl)
- toMerge = (BodyImpl) b;
+ toMerge = (BodyImpl) b;
else
- throw new IllegalArgumentException();
-
+ throw new IllegalArgumentException();
+
_objects.putAll(toMerge._objects);
-
- byte[] toAdd = b.getByteArray();
+ byte[] toAdd = b.getByteArray();
+
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];
-
- System.arraycopy(_content, 0, buffer, 0, _content.length);
- System.arraycopy(toAdd, 0, buffer, _content.length,
- toAdd.length);
-
- _content = buffer;
- }
- }
+ setByteArray(toAdd);
}
public String toString()
{
String toReturn = "body: [ ";
+ byte[] content = getByteArray();
+
+ if (content != null)
+ toReturn += "byte[]: " + Util.format(new String(content));
- if (_content != null)
- toReturn += "byte[]: " + Util.format(new String(_content));
-
if (_objects != null)
{
- if (_content != null)
+ if (content != null)
toReturn += ", ";
toReturn += "objects: " + _objects.toString();
@@ -341,14 +332,11 @@
}
// copy constructor (almost - doesn't copy, just references).
-
- protected BodyImpl (BodyImpl copy)
+
+ protected BodyImpl(BodyImpl copy)
{
- _content = copy._content;
_objects = copy._objects;
}
-
- protected byte[] _content;
protected Hashtable<String, Object> _objects;
More information about the jboss-svn-commits
mailing list