[jboss-svn-commits] JBL Code SVN: r16725 - labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 21 05:21:59 EST 2007


Author: tfennelly
Date: 2007-11-21 05:21:59 -0500 (Wed, 21 Nov 2007)
New Revision: 16725

Modified:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java
Log:
http://jira.jboss.com/jira/browse/JBESB-1352

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java	2007-11-21 10:19:25 UTC (rev 16724)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java	2007-11-21 10:21:59 UTC (rev 16725)
@@ -60,12 +60,11 @@
 
 	public Object put(String name, Object value)
 	{
-		if (value instanceof Serializable)
-			return _table.put(name, (Serializable) value);
-		throw new IllegalArgumentException(value+" must be Serializable");
-	}
+        assertValidValue(value);
+		return _table.put(name, (Serializable) value);
+    }
 
-	public Object remove(String name)
+    public Object remove(String name)
 	{
 		return _table.remove(name);
 	}
@@ -88,26 +87,21 @@
 	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");
+        assertValidValue(value);
+        return _list.set(index, (Serializable) value);
 	}
 
 	public void addItem(Object value)
 	{
-		if (value instanceof Serializable)
-			_list.add((Serializable) value);
-		else
-			throw new IllegalArgumentException(value+" must be Serializable");
+        assertValidValue(value);
+        _list.add((Serializable) value);
 	}
 
 	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");
+        assertValidValue(value);
+        _list.add(index, (Serializable) value);
 	}
 
 	public int getNamedCount()
@@ -294,6 +288,14 @@
 		return true;		
 	}
 
+    private void assertValidValue(Object value) {
+        if(value == null) {
+            throw new IllegalArgumentException("Cannot set null object as a message attachment.  Attachment objects must be non-null and Serializable.");
+        } else if(!(value instanceof Serializable)) {
+            throw new IllegalArgumentException("Cannot set an Object of type '" + value.getClass().getName() + "' as a message attachment.  Attachment objects must be Serializable.");
+        }
+    }
+
 	ArrayList<Serializable> _list = new ArrayList<Serializable>();
 	Hashtable<String, Serializable> _table = new Hashtable<String, Serializable>();
 }




More information about the jboss-svn-commits mailing list