View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.xml.transformer.wire;
8   
9   import org.mule.module.xml.transformer.ObjectToXml;
10  import org.mule.module.xml.transformer.XStreamFactory;
11  import org.mule.module.xml.transformer.XmlToObject;
12  import org.mule.transformer.wire.TransformerPairWireFormat;
13  
14  import java.util.Map;
15  import java.util.Set;
16  
17  /**
18   * Serializes objects using XStream. This is equivelent of using the ObjectToXml and
19   * XmlToObject except that there is no source or return type checking.
20   */
21  public class XStreamWireFormat extends TransformerPairWireFormat
22  {
23      
24      public XStreamWireFormat() throws IllegalAccessException, InstantiationException, ClassNotFoundException
25      {
26          this(XStreamFactory.XSTREAM_XPP_DRIVER, null, null);
27      }
28  
29      public XStreamWireFormat(String driverClassName, Map aliases, Set converters)
30          throws IllegalAccessException, InstantiationException, ClassNotFoundException
31      {
32          XmlToObject in = new XmlToObject();
33          in.setDriverClass(driverClassName);
34          in.setAliases(aliases);
35          in.setConverters(converters);
36          setInboundTransformer(in);
37  
38          ObjectToXml out = new ObjectToXml();
39          out.setDriverClass(driverClassName);
40          out.setAliases(aliases);
41          out.setConverters(converters);
42          // TODO This is currently needed as a workaround for MULE-2881, this needs to
43          // be removed is this is not the solution to MULE-2881
44          out.setAcceptMuleMessage(true);
45          setOutboundTransformer(out);
46      }
47  
48  }