1 10 11 package org.mule.transformers.xml; 12 13 import java.io.ByteArrayInputStream ; 14 15 import org.mule.umo.UMOEventContext; 16 import org.mule.umo.transformer.TransformerException; 17 18 27 28 public class XmlToObject extends AbstractXStreamTransformer 29 { 30 33 private static final long serialVersionUID = -2804761502812600068L; 34 35 private final DomDocumentToXml domTransformer = new DomDocumentToXml(); 36 37 public XmlToObject() 38 { 39 registerSourceType(String .class); 40 registerSourceType(byte[].class); 41 registerSourceType(org.w3c.dom.Document .class); 42 registerSourceType(org.dom4j.Document.class); 43 } 44 45 public Object transform(Object src, String encoding, UMOEventContext context) throws TransformerException 46 { 47 48 if (src instanceof byte[]) 49 { 50 return getXStream().fromXML(new ByteArrayInputStream ((byte[])src)); 51 } 52 else if (src instanceof String ) 53 { 54 return getXStream().fromXML(src.toString()); 55 } 56 else 57 { 58 return getXStream().fromXML((String )domTransformer.transform(src)); 59 } 60 } 61 } 62 | Popular Tags |