[jboss-svn-commits] JBL Code SVN: r16590 - in labs/jbossesb/trunk: product/docs and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 14 07:13:53 EST 2007
Author: beve
Date: 2007-11-14 07:13:53 -0500 (Wed, 14 Nov 2007)
New Revision: 16590
Added:
labs/jbossesb/trunk/product/lib/ext/xstream-1.2.2.jar
Removed:
labs/jbossesb/trunk/product/lib/ext/xstream-1.1.3.jar
Modified:
labs/jbossesb/trunk/IDE/JBossIDE/product/.classpath
labs/jbossesb/trunk/product/docs/MessageActionGuide.odt
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/converters/XStreamToObject.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/TestBean.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/converters/XStreamToObjectUnitTest.java
Log:
Work for JBESB-1185 "XStreamToObject. Add support for Atribute aliases and enum types"
Modified: labs/jbossesb/trunk/IDE/JBossIDE/product/.classpath
===================================================================
--- labs/jbossesb/trunk/IDE/JBossIDE/product/.classpath 2007-11-14 11:52:27 UTC (rev 16589)
+++ labs/jbossesb/trunk/IDE/JBossIDE/product/.classpath 2007-11-14 12:13:53 UTC (rev 16590)
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="lib" path="build/jbossesb/lib/jbossesb-config-model-1.0.1.jar"/>
<classpathentry excluding="**/.svn/" kind="src" path="rosetta/src"/>
+ <classpathentry kind="src" path="build/schema-model/src"/>
<classpathentry excluding="**/.svn/" kind="src" path="rosetta/tests/src"/>
<classpathentry kind="lib" path="etc/test/resources/log4j/dev"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
@@ -12,13 +14,10 @@
<classpathentry kind="lib" path="lib/ext/emma.jar"/>
<classpathentry kind="lib" path="lib/ext/groovy-all-1.0.jar"/>
<classpathentry kind="lib" path="lib/ext/hsqldb.jar"/>
- <classpathentry kind="lib" path="lib/ext/jaxr-api-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/ext/jbossall-client.jar"/>
<classpathentry kind="lib" path="lib/ext/jboss-system.jar"/>
<classpathentry kind="lib" path="lib/ext/jbossts-common.jar"/>
<classpathentry kind="lib" path="lib/ext/jsch-0.1.jar"/>
- <classpathentry kind="lib" path="lib/ext/juddi-1.0-SNAPSHOT.jar"/>
- <classpathentry kind="lib" path="lib/ext/juddi-client-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/ext/junit-4.1.jar"/>
<classpathentry kind="lib" path="lib/ext/log4j.jar"/>
<classpathentry kind="lib" path="lib/ext/mail.jar"/>
@@ -26,15 +25,12 @@
<classpathentry kind="lib" path="lib/ext/ognl-2.6.9.jar"/>
<classpathentry kind="lib" path="lib/ext/opencsv-1.6.jar"/>
<classpathentry kind="lib" path="lib/ext/properties-plugin.jar"/>
- <classpathentry kind="lib" path="lib/ext/scout-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/ext/stax-api-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/ext/xalan-2.7.0.jar"/>
<classpathentry kind="lib" path="lib/ext/xbean.jar"/>
<classpathentry kind="lib" path="lib/ext/xercesImpl-2.7.1.jar"/>
<classpathentry kind="lib" path="lib/ext/xml-apis-1.3.02.jar"/>
<classpathentry kind="lib" path="lib/ext/xmlpublic.jar"/>
- <classpathentry kind="lib" path="lib/ext/xstream-1.1.3.jar"/>
- <classpathentry kind="lib" path="build/jbossesb/lib/jbossesb-config-model-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/ext/jboss.jar"/>
<classpathentry kind="lib" path="lib/ext/commons-io-1.3.jar"/>
<classpathentry kind="lib" path="lib/ext/edtftpj-1.5.4.jar"/>
@@ -48,7 +44,6 @@
<classpathentry kind="lib" path="ftp/lib/slf4j-log4j12-1.3.0.jar"/>
<classpathentry kind="lib" path="services/jbpm/lib/ext/asm.jar"/>
<classpathentry kind="lib" path="services/jbpm/lib/ext/dom4j.jar"/>
- <classpathentry kind="lib" path="services/jbpm/lib/ext/hibernate3.jar"/>
<classpathentry kind="lib" path="services/jbpm/lib/ext/jbpm-identity.jar"/>
<classpathentry kind="lib" path="services/jbpm/lib/ext/jbpm-jpdl.jar"/>
<classpathentry kind="lib" path="lib/ext/jgroups-all.jar"/>
@@ -67,5 +62,17 @@
<classpathentry kind="lib" path="lib/ext/jbossweb.jar"/>
<classpathentry kind="lib" path="lib/ext/stringtemplate-3.0.jar"/>
<classpathentry kind="lib" path="lib/ext/trove.jar"/>
+ <classpathentry kind="lib" path="lib/ext/jakarta-oro-2.0.8.jar"/>
+ <classpathentry kind="lib" path="lib/ext/commons-ssl-0.3.4.jar"/>
+ <classpathentry kind="lib" path="services/jbrules/lib/ext/antlr-runtime-3.0.jar"/>
+ <classpathentry kind="lib" path="lib/ext/mvel14-1.2rc4rv908.jar"/>
+ <classpathentry kind="lib" path="lib/ext/quartz-1.5.2.jar"/>
+ <classpathentry kind="lib" path="lib/ext/jaxr-api-1.0rc1.jar"/>
+ <classpathentry kind="lib" path="lib/ext/jboss-jaxb-intros.jar"/>
+ <classpathentry kind="lib" path="lib/ext/scout-1.0rc1.jar"/>
+ <classpathentry kind="lib" path="lib/ext/commons-codec-1.3.jar"/>
+ <classpathentry kind="lib" path="lib/ext/juddi-20071022.191630-27.jar"/>
+ <classpathentry kind="lib" path="lib/ext/juddi-client-20071022.191630-6.jar"/>
+ <classpathentry kind="lib" path="lib/ext/xstream-1.2.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: labs/jbossesb/trunk/product/docs/MessageActionGuide.odt
===================================================================
(Binary files differ)
Deleted: labs/jbossesb/trunk/product/lib/ext/xstream-1.1.3.jar
===================================================================
(Binary files differ)
Added: labs/jbossesb/trunk/product/lib/ext/xstream-1.2.2.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/lib/ext/xstream-1.2.2.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/converters/XStreamToObject.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/converters/XStreamToObject.java 2007-11-14 11:52:27 UTC (rev 16589)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/converters/XStreamToObject.java 2007-11-14 12:13:53 UTC (rev 16590)
@@ -1,6 +1,7 @@
package org.jboss.soa.esb.actions.converters;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -11,11 +12,11 @@
import org.apache.log4j.Logger;
import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.actions.ActionProcessingException;
import org.jboss.soa.esb.actions.ActionUtils;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.MessagePayloadProxy;
import org.jboss.soa.esb.message.body.content.BytesBody;
@@ -25,6 +26,7 @@
import org.xml.sax.SAXException;
import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.io.xml.DomReader;
@@ -49,6 +51,10 @@
* <alias name="aliasName" class="className" />
* ...
* </property>
+ * <property name="converters"> <!-- Optional list of converter to register with XStream -->
+ * <converter class="className" />
+ * <converter class="className" />
+ * ...
* </Action>
* </pre>
* <p/>
@@ -70,7 +76,10 @@
// action related variables
private Map<String,String> aliases;
+ private Map<String,String> attributeAliases;
+ private List<String> converters;
private MessagePayloadProxy payloadProxy;
+
/**
* Public constructor.
@@ -79,7 +88,9 @@
*/
public XStreamToObject(ConfigTree properties) {
this(properties.getName(), properties.attributesAsList());
- aliases = getAliases( properties );
+ aliases = getAliases( properties, "alias" );
+ attributeAliases = getAliases( properties, "attribute-alias" );
+ converters = getConverters( properties, "converter" );
payloadProxy = new MessagePayloadProxy(properties,
new String[] {BytesBody.BYTES_LOCATION, ActionUtils.POST_ACTION_DATA},
new String[] {ActionUtils.POST_ACTION_DATA});
@@ -141,18 +152,39 @@
* as its key and the corresponding value is the class to map
* it to.
*/
- protected Map<String,String> getAliases( ConfigTree configTree )
+ protected Map<String,String> getAliases( final ConfigTree configTree, final String childName)
{
- Map<String,String> aliases = new HashMap<String,String>();
+ Map<String,String> aliases = new HashMap<String,String>();
- ConfigTree[] children = configTree.getChildren( "alias" );
+ ConfigTree[] children = configTree.getChildren( childName );
if ( children != null ) {
for ( ConfigTree alias : children )
aliases.put( alias.getAttribute( "name" ), alias.getAttribute( "class" ) );
}
return aliases;
+
}
+
+ /**
+ * Will extract the converter elements from the passed-in conifgTree
+ *
+ * @param configTree the configuration for this class
+ *
+ * @return Map<String,String> either an empty map or a map containing the converter class
+ */
+ protected List<String> getConverters( final ConfigTree configTree, final String childName )
+ {
+ List<String> converters = new ArrayList<String>();
+
+ ConfigTree[] children = configTree.getChildren( childName );
+
+ if ( children != null ) {
+ for ( ConfigTree converter : children )
+ converters.add( converter.getAttribute( "class" ) );
+ }
+ return converters;
+ }
/**
* Added the aliases contained in the passed-in map to the
@@ -173,14 +205,73 @@
Class clazz = ClassUtil.forName( className, getClass() );
xstream.alias((String)me.getKey(), clazz );
} catch (ClassNotFoundException e) {
- logger.error(e);
+ logger.error("ClassNotFoundException: ", e);
throw new ActionProcessingException("Could not add alias : " + (String)me.getKey() + ", class : " + className ,e );
}
}
}
/**
+ * Registers the converters contained in the passed in list
*
+ * @param converters which should be registered with XStream
+ * @param xstream
+ * @throws ActionProcessingException
+ */
+ protected void addConverters( List<String> converters, XStream xstream) throws ActionProcessingException
+ {
+ if ( converters == null )
+ return;
+
+ for( String converterClass : converters )
+ {
+ if ( converterClass == null )
+ continue;
+ try {
+ Class clazz = ClassUtil.forName( converterClass, getClass() );
+ xstream.registerConverter((Converter)clazz.newInstance());
+
+ } catch (ClassNotFoundException e) {
+ logger.error("ClassNotFoundException: ", e);
+ throw new ActionProcessingException("Could not register converter : " + converterClass.getClass().getName(),e );
+ } catch (InstantiationException e)
+ {
+ logger.error("InstantiationException: ", e);
+ } catch (IllegalAccessException e)
+ {
+ logger.error("IllegalAccessException: ", e);
+ }
+
+ }
+ }
+
+ /**
+ * Added the aliases contained in the passed-in map to the
+ * passed-in XStream object
+ *
+ * @param aliases Map of aliases.
+ * @throws ActionProcessingException
+ */
+ protected void addAttributeAliases( Map<String, String> aliases, XStream xstream) throws ActionProcessingException
+ {
+ if ( aliases == null )
+ return;
+
+ Set<Map.Entry<String,String>> set = aliases.entrySet();
+ for (Map.Entry me : set ) {
+ String className = (String) me.getValue();
+ try {
+ Class clazz = ClassUtil.forName( className, getClass() );
+ xstream.useAttributeFor( (String)me.getKey(), clazz );
+ } catch (ClassNotFoundException e) {
+ logger.error("ClassNotFoundException: ", e);
+ throw new ActionProcessingException("Could not add alias : " + (String)me.getKey() + ", class : " + className ,e );
+ }
+ }
+ }
+
+ /**
+ *
* @param xml the xml String
* @param root an instance of the type of the root element
* @throws ActionProcessingException
@@ -193,12 +284,13 @@
HierarchicalStreamReader reader = null;
try
{
- XStream xstream = new XStream( new DomDriver() );
-
reader = new DomReader( getRootElement( xml, rootNodeName ) );
+ XStream xstream = new XStream( new DomDriver() );
xstream.alias(getAlias(incomingType), incomingType);
addAliases( aliases, xstream );
+ addAttributeAliases( attributeAliases, xstream );
+ addConverters( converters, xstream );
return xstream.unmarshal( reader, root );
}
finally
@@ -213,32 +305,30 @@
*/
private Element getRootElement( String xml, String xPathExpression ) throws ActionProcessingException
{
- logger.debug( "rootNodeName : " + xPathExpression );
-
try
{
return XPathUtil.getNodeFromXPathExpression( xml, xPathExpression );
}
catch (ParserConfigurationException e)
{
- logger.error( e );
+ logger.error( "ParserConfigurationException:", e );
throw new ActionProcessingException( e );
}
catch (SAXException e)
{
- logger.error( e );
+ logger.error( "SAXException : ", e );
throw new ActionProcessingException( e );
}
catch (IOException e)
{
- logger.error( e );
+ logger.error( "IOException: ", e );
throw new ActionProcessingException( e );
}
catch (XPathExpressionException e)
{
- logger.error( e );
+ logger.error( "XPathExpressionException", e );
throw new ActionProcessingException( e );
}
}
-
+
}
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/TestBean.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/TestBean.java 2007-11-14 11:52:27 UTC (rev 16589)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/TestBean.java 2007-11-14 12:13:53 UTC (rev 16590)
@@ -31,10 +31,15 @@
{
private static final long serialVersionUID = 1L;
private String name;
+ private String initials;
private String phone;
+ public enum GENDER { MALE, FEMALE};
+
+ private GENDER gender;
public TestBean() {
}
+
public TestBean(String name, String phone) {
this.name = name;
this.phone = phone;
@@ -52,4 +57,22 @@
public void setPhone(String phone) {
this.phone = phone;
}
+ public String getInitials()
+ {
+ return initials;
+ }
+ public void setInitials(String initials)
+ {
+ this.initials = initials;
+ }
+
+ public GENDER getGender()
+ {
+ return gender;
+ }
+
+ public void setGender(GENDER gender)
+ {
+ this.gender = gender;
+ }
}
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/converters/XStreamToObjectUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/converters/XStreamToObjectUnitTest.java 2007-11-14 11:52:27 UTC (rev 16589)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/converters/XStreamToObjectUnitTest.java 2007-11-14 12:13:53 UTC (rev 16590)
@@ -26,24 +26,26 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.Serializable;
import java.util.ArrayList;
-import java.util.List;
import java.util.Map;
import junit.framework.JUnit4TestAdapter;
import org.apache.log4j.Logger;
import org.jboss.soa.esb.actions.ActionProcessingException;
-import org.jboss.soa.esb.actions.ActionUtils;
import org.jboss.soa.esb.actions.TestBean;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.helpers.KeyValuePair;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
-import org.junit.Ignore;
import org.junit.Test;
import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
/**
* XStreamToObject unit tests.
@@ -53,6 +55,7 @@
*/
public class XStreamToObjectUnitTest {
+ @SuppressWarnings("unused")
private Logger log = Logger.getLogger( XStreamToObjectUnitTest.class );
@Test
@@ -128,7 +131,7 @@
ConfigTree configTree = getConfigTreeWithAliases("TomsClass", false, TestBean.class, null );
XStreamToObject xstreamToObject = new XStreamToObject( configTree );
- Map<String, String> aliases = xstreamToObject.getAliases( configTree );
+ Map<String, String> aliases = xstreamToObject.getAliases( configTree, "alias" );
assertAliases( aliases );
}
@@ -139,7 +142,7 @@
ConfigTree configTree = getConfigTreeWithAliases("TomsClass", false, TestBean.class, null );
XStreamToObject xstreamToObject = new XStreamToObject( configTree );
- Map<String, String> aliases = xstreamToObject.getAliases( configTree );
+ Map<String, String> aliases = xstreamToObject.getAliases( configTree, "alias" );
xstreamToObject.addAliases( aliases, new XStream() );
assertAliases( aliases );
@@ -151,7 +154,7 @@
ConfigTree configTree = getConfigTree( "TomsClass", false, TestBean.class, null );
XStreamToObject xstreamToObject = createXStreamObject( "TomsClass", false, TestBean.class, null );
- Map<String, String> aliases = xstreamToObject.getAliases( configTree );
+ Map<String, String> aliases = xstreamToObject.getAliases( configTree, "alias" );
xstreamToObject.addAliases( aliases, new XStream() );
assertEquals( "Aliases map should have been empty!", 0, aliases.size() );
@@ -242,11 +245,116 @@
Object obj = new ArrayList<TestBean>();
obj = xstreamToObject.fromXmlToObject( xml, obj );
- assertTrue( "Object was not an instance of ArrayList", obj instanceof ArrayList );
+ assertTrue( obj instanceof ArrayList );
ArrayList<TestBean> nodes = (ArrayList<TestBean>) obj;
assertEquals( 2, nodes.size() );
}
+
+ @Test
+ public void fromXmlToObject_with_attributeAliases() throws ActionProcessingException
+ {
+ String rootNodeName = "/someNode/list";
+ ConfigTree configTree = getConfigTree( "list", true, ArrayList.class, rootNodeName);
+
+ ConfigTree alias1 = new ConfigTree( "alias", configTree);
+ alias1.setAttribute( "name", "TomsClass");
+ alias1.setAttribute( "class", TestBean.class.getName());
+
+ ConfigTree attrAlias = new ConfigTree( "attribute-alias", configTree);
+ attrAlias.setAttribute( "name", "initials");
+ attrAlias.setAttribute( "class", String.class.getName() );
+
+ XStreamToObject xstreamToObject = new XStreamToObject( configTree );
+
+ String xml = "<someNode><list><TomsClass initials='TF'><name>Tom</name></TomsClass><TomsClass initials='DB'><name>Daniel</name></TomsClass></list></someNode>";
+
+ Object obj = new ArrayList<TestBean>();
+ obj = xstreamToObject.fromXmlToObject( xml, obj );
+
+ assertTrue( obj instanceof ArrayList );
+ ArrayList<TestBean> nodes = (ArrayList<TestBean>) obj;
+ assertEquals( 2, nodes.size() );
+
+ assertEquals( "TF", nodes.get(0).getInitials() );
+ assertEquals( "DB", nodes.get(1).getInitials() );
+ }
+
+ @Test
+ public void fromXmlToObject_with_enum() throws ActionProcessingException
+ {
+ String rootNodeName = "/someNode/list";
+ ConfigTree configTree = getConfigTree( "list", true, ArrayList.class, rootNodeName);
+ ConfigTree alias1 = new ConfigTree( "alias", configTree);
+ alias1.setAttribute( "name", "TomsClass");
+ alias1.setAttribute( "class", TestBean.class.getName());
+
+ ConfigTree gender = new ConfigTree( "alias", configTree);
+ gender.setAttribute( "name", "gender");
+ gender.setAttribute( "class", TestBean.GENDER.class.getName());
+
+ XStreamToObject xstreamToObject = new XStreamToObject( configTree );
+
+ String xml = "<someNode><list><TomsClass><gender>MALE</gender></TomsClass><TomsClass><gender>FEMALE</gender></TomsClass></list></someNode>";
+
+ Object obj = new ArrayList<TestBean>();
+ obj = xstreamToObject.fromXmlToObject( xml, obj );
+
+ assertTrue( obj instanceof ArrayList );
+ ArrayList<TestBean> nodes = (ArrayList<TestBean>) obj;
+ assertEquals( 2, nodes.size() );
+
+ TestBean person1 = nodes.get( 0 );
+ assertEquals( TestBean.GENDER.MALE, person1.getGender() );
+
+ TestBean person2 = nodes.get( 1 );
+ assertEquals( TestBean.GENDER.FEMALE, person2.getGender() );
+ }
+
+ @Test
+ public void fromXmlToObject_with_collections() throws ActionProcessingException
+ {
+ String rootNodeName = "/someNode/list";
+ ConfigTree configTree = getConfigTree( "list", true, ArrayList.class, rootNodeName);
+ ConfigTree alias1 = new ConfigTree( "alias", configTree);
+ alias1.setAttribute( "name", "Persons");
+ alias1.setAttribute( "class", ArrayList.class.getName());
+
+ ConfigTree alias2 = new ConfigTree( "alias", configTree);
+ alias2.setAttribute( "name", "TomsClass");
+ alias2.setAttribute( "class", TestBean.class.getName());
+
+ XStreamToObject xstreamToObject = new XStreamToObject( configTree );
+
+ String xml = "<someNode><list><Persons><TomsClass><list></list></TomsClass><TomsClass></TomsClass></Persons></list></someNode>";
+
+ Object obj = new ArrayList<TestBean>();
+ obj = xstreamToObject.fromXmlToObject( xml, obj );
+
+ assertTrue( obj instanceof ArrayList );
+ ArrayList list = (ArrayList) obj;
+ ArrayList subList = (ArrayList)list.get( 0 );
+ assertEquals( 2, subList.size() );
+ }
+
+ @Test
+ public void fromXmlToObject_with_converter() throws ActionProcessingException
+ {
+ ConfigTree configTree = getConfigTree( "comment", true, Comment.class, null);
+
+ ConfigTree converter = new ConfigTree( "converter", configTree);
+ converter.setAttribute( "class", CommentConverter.class.getName());
+
+ XStreamToObject xstreamToObject = new XStreamToObject( configTree );
+
+ final String expectedComment = "Just a comment";
+ String xml = "<comment>" + expectedComment + "</comment>";
+
+ Object obj = new Comment();
+ obj = xstreamToObject.fromXmlToObject( xml, obj );
+ assertTrue( obj instanceof Comment );
+ assertEquals( expectedComment, ((Comment)obj).getComment());
+ }
private XStreamToObject createXStreamObject( String classAlias, boolean exludePackage, Class incomingType, String rootNodeName)
{
@@ -308,7 +416,54 @@
}
}
+ private static class Comment implements Serializable
+ {
+ private String comment;
+
+ public Comment() {}
+
+ public Comment(final String comment)
+ {
+ this.comment = comment;
+ }
+
+ public String getComment()
+ {
+ return comment;
+ }
+
+ public void setComment( String comment )
+ {
+ this.comment = comment;
+ }
+
+ public String toString()
+ {
+ return "[Comment: " + comment + "]";
+ }
+
+ }
+ static class CommentConverter implements Converter {
+ private Logger log = Logger.getLogger(CommentConverter.class);
+
+ public boolean canConvert(Class clazz) {
+ return clazz.equals(Comment.class);
+ }
+
+ public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
+ log.debug( value );
+ Comment comment = (Comment) value;
+ writer.startNode("comment");
+ writer.setValue(comment.getComment());
+ writer.endNode();
+ }
+
+ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
+ return new Comment(reader.getValue());
+ }
+ }
+
/**
* Just here to get Ant to find annotated test.
*/
More information about the jboss-svn-commits
mailing list