[jboss-svn-commits] JBL Code SVN: r19703 - in labs/jbossesb/trunk/product/rosetta: tests/src/org/jboss/soa/esb/message/format/tests and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Apr 23 16:54:08 EDT 2008
Author: mark.little at jboss.com
Date: 2008-04-23 16:54:08 -0400 (Wed, 23 Apr 2008)
New Revision: 19703
Added:
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ErrorObject.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMarshalUnmarshalPlugin.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MarshalUnmarshalUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/SampleObject.java
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
Log:
http://jira.jboss.com/jira/browse/JBESB-1643
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 2008-04-23 17:01:48 UTC (rev 19702)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java 2008-04-23 20:54:08 UTC (rev 19703)
@@ -143,7 +143,7 @@
final String origValueURI = StreamHelper.writeStartElement(out, XMLUtil.ESB_QNAME_BODY_CONTENT_VALUE) ;
if (!MarshalUnmarshalManager.getInstance().marshal(out, entry.getValue()))
{
- throw new XMLStreamException("Cannot pack object:" + entry.getKey()) ;
+ throw new XMLStreamException("Cannot pack object:" + entry.getKey()+" "+entry.getValue()) ;
}
StreamHelper.writeEndElement(out, XMLUtil.ESB_QNAME_BODY_CONTENT_VALUE.getPrefix(), origValueURI) ;
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ErrorObject.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ErrorObject.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ErrorObject.java 2008-04-23 20:54:08 UTC (rev 19703)
@@ -0,0 +1,27 @@
+package org.jboss.soa.esb.message.format.tests;
+
+/*
+ * 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 mark.little at jboss.com
+ */
+
+public class ErrorObject
+{
+ public int val;
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMarshalUnmarshalPlugin.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMarshalUnmarshalPlugin.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMarshalUnmarshalPlugin.java 2008-04-23 20:54:08 UTC (rev 19703)
@@ -0,0 +1,124 @@
+package org.jboss.soa.esb.message.format.tests;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.internal.soa.esb.message.format.xml.marshal.MarshalUnmarshalPlugin;
+import org.jboss.soa.esb.MarshalException;
+import org.jboss.soa.esb.UnmarshalException;
+
+/*
+ * 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 mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new Object marshal/unmarshal formats dynamically. When
+ * packing objects in XML, the system runs through the list of registered
+ * plug-ins until it finds one that can deal with the object type (or faults).
+ * When packing, the name (type) of the plug-in that packed the object is also
+ * attached to facilitate unpacking.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class ExampleMarshalUnmarshalPlugin implements MarshalUnmarshalPlugin
+{
+ public ExampleMarshalUnmarshalPlugin()
+ {
+ try
+ {
+ _type = new URI("urn:xml/marshalunmarshal/plugin/example");
+ }
+ catch (URISyntaxException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ /**
+ * Can the plugin pack the specified object?
+ * @param value The object to pack.
+ * @return true if the object can be packed, false otherwise.
+ */
+ public boolean canPack(final Object value)
+ {
+ return (value instanceof SampleObject);
+ }
+
+ /**
+ * Pack the provided object into the document.
+ *
+ * @param param the object to pack.
+ * @return the packed version of the object.
+ *
+ * @throws MarshalException thrown if there is a problem packing.
+ */
+
+ public String marshal (Object param)
+ throws MarshalException
+ {
+ if (param instanceof SampleObject)
+ {
+ return ""+((SampleObject) param).val;
+ }
+ else
+ {
+ throw new MarshalException("Invalid value type for marshaling plugin:" + param.getClass().getName()) ;
+ }
+ }
+
+ /**
+ * Unpack the object from the document.
+ *
+ * @param content the object content.
+ *
+ * @return the object, or <code>null</code> if this implementation cannot deal with the
+ * format.
+ * @throws UnmarshalException thrown if there is a problem unpacking.
+ */
+ public Object unmarshal (final String content)
+ throws UnmarshalException
+ {
+ try
+ {
+ SampleObject s = new SampleObject();
+
+ s.val = new Integer(content).intValue();
+
+ return s;
+ }
+ catch (final NumberFormatException cnfe)
+ {
+ throw new UnmarshalException("Failed to decode value", cnfe) ;
+ }
+ }
+
+ /**
+ * @return the unique name for this plugin.
+ */
+
+ public URI type()
+ {
+ return _type;
+ }
+
+ private URI _type = null;
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MarshalUnmarshalUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MarshalUnmarshalUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MarshalUnmarshalUnitTest.java 2008-04-23 20:54:08 UTC (rev 19703)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.message.format.tests;
+
+import java.io.Serializable;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.message.format.xml.marshal.MarshalUnmarshalPlugin;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * Unit tests for the MarshalUnmarshal class.
+ *
+ * @author Mark Little
+ */
+
+public class MarshalUnmarshalUnitTest extends TestCase
+{
+
+ public void testMarshalUnmarshal () throws Exception
+ {
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).setProperty(MarshalUnmarshalPlugin.MARSHAL_UNMARSHAL_PLUGIN+"1", ExampleMarshalUnmarshalPlugin.class.getName());
+ Message msg = MessageFactory.getInstance().getMessage();
+ SampleObject s = new SampleObject();
+
+ s.val = 2001;
+
+ msg.getBody().add(s);
+
+ Serializable content = Util.serialize(msg);
+
+ Message unmarshal = Util.deserialize(content);
+
+ SampleObject s2 = (SampleObject) unmarshal.getBody().get();
+
+ assertEquals(s.val, s2.val);
+ }
+
+ public void testMarshalUnmarshalError () throws Exception
+ {
+ try
+ {
+ Message msg = MessageFactory.getInstance().getMessage();
+ ErrorObject s = new ErrorObject();
+
+ s.val = 2001;
+
+ msg.getBody().add(s);
+
+ Util.serialize(msg);
+
+ fail();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/SampleObject.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/SampleObject.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/SampleObject.java 2008-04-23 20:54:08 UTC (rev 19703)
@@ -0,0 +1,27 @@
+package org.jboss.soa.esb.message.format.tests;
+
+/*
+ * 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 mark.little at jboss.com
+ */
+
+public class SampleObject
+{
+ public int val;
+}
More information about the jboss-svn-commits
mailing list