View Javadoc

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