org.jboss.soa.esb.actions.converters
Class XStreamToObject

java.lang.Object
  extended by org.jboss.soa.esb.actions.AbstractActionLifecycle
      extended by org.jboss.soa.esb.actions.AbstractActionPipelineProcessor
          extended by org.jboss.soa.esb.actions.converters.AbstractObjectXStream
              extended by org.jboss.soa.esb.actions.converters.XStreamToObject
All Implemented Interfaces:
ActionLifecycle, ActionPipelineProcessor

public class XStreamToObject
extends AbstractObjectXStream

XML to Object processor that uses Uses the XStream .

Sample Action Configuration:

<action name="doCustomer" class="XStreamObject">
     <property name="class-alias" value="Customer"/> 
     <property name="incoming-type" value="CustomerProcessor"/>
     <property name="exclude-package" value="false"/>
     <property name="root-node" value="/root/Customer"/>
     <property name="aliases">
 		<alias name="aliasName" class="className" />
 		<alias name="aliasName" class="className" />
 		...
     </property>
     <property name="fieldAliases">
 		<field-alias alias="aliasName" class="className" fieldName="fieldName"/> 
 		<field-alias alias="aliasName" class="className" fieldName="fieldName"/>
 		...
     </property>
     <property name="attributeAliases">
 		<attribute-alias name="aliasName" class="className"/> 
 		<attribute-alias name="aliasName" class="className"/> 
 		...
     </property>
     <property name="implicit-collections">
 		<implicit-collection class="className" fieldName="fieldName" fieldType="java.lang.String" />
 		<implicit-collection class="className" fieldName="fieldName" fieldType="java.lang.Integer"/>
 		...
     </property>
     <property name="converters"> 
 		<converter class="className" />
 		<converter class="className" />
 		...
 </action>
 

  • class-alias Optional. Class alias for the 'incoming-type'.
  • incoming-type Required. Class of the incoming type.
  • exclude-package-type Optional, defaults to true. Determines whether package name should be removed from the incoming type.
  • root-node Optional. Specifies an XPath expression to be used to determine the root node that XStream will use.
  • aliases Optional. Specifies extra class aliases.
  • fieldAliases Optional. Specifies field aliases.
  • implicit-collections Optional. Specifies implicit collections which are when you have an xml element that is a place holder for a collection of other elements. In this case you are telling XStream to not include the holder element but instead place its element into the the 'fieldName' in the target class. 'className' is the collection type. 'fieldType' is the type the elements in the collection.
  • converters Optional. Specifies converters that will be registered with XStream.
  • The XML root element is either set from the "class-alias" property or the classes full name. In the later case, the class package is excluded unless "exclude-package" is set to "false"/"no".

    Since:
    Version 4.0
    Author:
    danielmarchant, Daniel Bevenius

    Field Summary
     
    Fields inherited from class org.jboss.soa.esb.actions.converters.AbstractObjectXStream
    classAlias, classMethod, classProcessor, excludePackage, processorClass, rootNodeName
     
    Fields inherited from interface org.jboss.soa.esb.actions.ActionPipelineProcessor
    PROCESS_EXCEPTION_METHOD, PROCESS_METHOD, PROCESS_SUCCESS_METHOD
     
    Constructor Summary
      XStreamToObject(ConfigTree properties)
              Public constructor.
    protected XStreamToObject(java.lang.String actionName, java.util.List<KeyValuePair> properties)
              Public constructor.
     
    Method Summary
    protected  void addAliases(java.util.Map<java.lang.String,java.lang.String> aliases, com.thoughtworks.xstream.XStream xstream)
              Added the aliases contained in the passed-in map to the passed-in XStream object
    protected  void addAttributeAliases(java.util.Map<java.lang.String,java.lang.String> aliases, com.thoughtworks.xstream.XStream xstream)
              Added the aliases contained in the passed-in map to the passed-in XStream object
    protected  void addConverters(java.util.List<java.lang.String> converters, com.thoughtworks.xstream.XStream xstream)
              Registers the converters contained in the passed in list
    protected  java.lang.Object fromXmlToObject(java.lang.String xml, java.lang.Object root)
               
    protected  java.util.Map<java.lang.String,java.lang.String> getAliases(ConfigTree configTree, java.lang.String childName)
              Will extract the alias elements from the passed-in conifgTree
    protected  java.util.List<java.lang.String> getConverters(ConfigTree configTree, java.lang.String childName)
              Will extract the converter elements from the passed-in conifgTree
    protected  java.util.List<FieldAliasConf> getFieldAliases(ConfigTree configTree, java.lang.String childName)
              Will extract the alias elements from the passed-in conifgTree
     Message process(Message message)
              Processes the message by using the giving class-processor.
     
    Methods inherited from class org.jboss.soa.esb.actions.converters.AbstractObjectXStream
    getAlias, getName, getRootNodeName, setName
     
    Methods inherited from class org.jboss.soa.esb.actions.AbstractActionPipelineProcessor
    processException, processSuccess
     
    Methods inherited from class org.jboss.soa.esb.actions.AbstractActionLifecycle
    destroy, initialise
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     
    Methods inherited from interface org.jboss.soa.esb.actions.ActionLifecycle
    destroy, initialise
     

    Constructor Detail

    XStreamToObject

    public XStreamToObject(ConfigTree properties)
    Public constructor.

    Parameters:
    properties - Action Properties.
    Throws:
    ConfigurationException - Action not properly configured.

    XStreamToObject

    protected XStreamToObject(java.lang.String actionName,
                              java.util.List<KeyValuePair> properties)
    Public constructor.

    Parameters:
    actionName - Action name.
    properties - Action Properties.
    Throws:
    ConfigurationException - Action not properly configured.
    Method Detail

    process

    public Message process(Message message)
                    throws ActionProcessingException
    Processes the message by using the giving class-processor.

    Parameters:
    message - The current message being processed.
    Returns:
    The message to be passed to the next stage of the pipeline.
    Throws:
    ActionProcessingException - for errors during processing.

    getAliases

    protected java.util.Map<java.lang.String,java.lang.String> getAliases(ConfigTree configTree,
                                                                          java.lang.String childName)
    Will extract the alias elements from the passed-in conifgTree

    Parameters:
    configTree - the configuration for this class
    Returns:
    Map either an empty map or a map containing the alias name as its key and the corresponding value is the class to map it to.

    getFieldAliases

    protected java.util.List<FieldAliasConf> getFieldAliases(ConfigTree configTree,
                                                             java.lang.String childName)
    Will extract the alias elements from the passed-in conifgTree

    Parameters:
    configTree - the configuration for this class
    Returns:
    Map either an empty map or a map containing the alias name as its key and the corresponding value is the class to map it to.

    getConverters

    protected java.util.List<java.lang.String> getConverters(ConfigTree configTree,
                                                             java.lang.String childName)
    Will extract the converter elements from the passed-in conifgTree

    Parameters:
    configTree - the configuration for this class
    Returns:
    Map either an empty map or a map containing the converter class

    addAliases

    protected void addAliases(java.util.Map<java.lang.String,java.lang.String> aliases,
                              com.thoughtworks.xstream.XStream xstream)
                       throws ActionProcessingException
    Added the aliases contained in the passed-in map to the passed-in XStream object

    Parameters:
    aliases - Map of aliases.
    Throws:
    ActionProcessingException

    addConverters

    protected void addConverters(java.util.List<java.lang.String> converters,
                                 com.thoughtworks.xstream.XStream xstream)
                          throws ActionProcessingException
    Registers the converters contained in the passed in list

    Parameters:
    converters - which should be registered with XStream
    xstream -
    Throws:
    ActionProcessingException

    addAttributeAliases

    protected void addAttributeAliases(java.util.Map<java.lang.String,java.lang.String> aliases,
                                       com.thoughtworks.xstream.XStream xstream)
                                throws ActionProcessingException
    Added the aliases contained in the passed-in map to the passed-in XStream object

    Parameters:
    aliases - Map of aliases.
    Throws:
    ActionProcessingException

    fromXmlToObject

    protected java.lang.Object fromXmlToObject(java.lang.String xml,
                                               java.lang.Object root)
                                        throws ActionProcessingException
    Parameters:
    xml - the xml String
    root - an instance of the type of the root element
    Throws:
    ActionProcessingException
    javax.xml.parsers.ParserConfigurationException
    java.io.IOException
    org.xml.sax.SAXException