diff options
author | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-02-19 08:34:11 +0000 |
---|---|---|
committer | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-02-19 08:34:11 +0000 |
commit | e94c93aefa1cf98991b1e711111133852991f95f (patch) | |
tree | 09ec11b68195adf92cd093afddd37f5f159f9ab8 /branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca | |
parent | d3700527dbea081802e78cfbc3b6661c3f076dd3 (diff) |
Fixes for TUSCANY-2840-Part2
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@745778 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca')
2 files changed, 47 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java b/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java index 2056789089..b4fc718914 100644 --- a/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java +++ b/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java @@ -31,6 +31,7 @@ import org.apache.tuscany.sca.core.databinding.transformers.Exception2ExceptionT import org.apache.tuscany.sca.core.databinding.transformers.Input2InputTransformer; import org.apache.tuscany.sca.core.databinding.transformers.Output2OutputTransformer; import org.apache.tuscany.sca.core.databinding.transformers.XMLStreamReader2CallableReference; +import org.apache.tuscany.sca.core.databinding.transformers.OMElementXMLAdapter; import org.apache.tuscany.sca.core.databinding.wire.DataBindingRuntimeWireProcessor; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; @@ -43,6 +44,7 @@ import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSFaultExceptionMapper; import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor; import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; import org.osoa.sca.CallableReference; +import org.apache.axiom.om.OMElement; /** * @version $Rev$ $Date$ @@ -55,6 +57,7 @@ public class DataBindingModuleActivator implements ModuleActivator { XMLAdapterExtensionPoint xmlAdapterExtensionPoint = registry.getExtensionPoint(XMLAdapterExtensionPoint.class); xmlAdapterExtensionPoint.addAdapter(CallableReference.class, CallableReferenceXMLAdapter.class); + xmlAdapterExtensionPoint.addAdapter(OMElement.class, OMElementXMLAdapter.class); FaultExceptionMapper faultExceptionMapper = new JAXWSFaultExceptionMapper(dataBindings, xmlAdapterExtensionPoint); MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); diff --git a/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/OMElementXMLAdapter.java b/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/OMElementXMLAdapter.java new file mode 100644 index 0000000000..e94f034a40 --- /dev/null +++ b/branches/sca-java-1.x/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/OMElementXMLAdapter.java @@ -0,0 +1,44 @@ +package org.apache.tuscany.sca.core.databinding.transformers;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.transform.Source;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String;
+
+/**
+ * This special XmlAdapter can be used by JAXB classes to convert from OMElement to Source
+ */
+public class OMElementXMLAdapter extends XmlAdapter<Source, OMElement> {
+
+ private TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ private XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+
+ @Override
+ public Source marshal(OMElement v) throws Exception {
+ XMLStreamReader reader = v.getXMLStreamReaderWithoutCaching();
+ XMLStreamReader2String t2 = new XMLStreamReader2String();
+ String xml = t2.transform(reader, null);
+ return new StreamSource(new StringReader(xml));
+ }
+
+ @Override
+ public OMElement unmarshal(Source v) throws Exception {
+ StringWriter sw = new StringWriter();
+ StreamResult result = new StreamResult(sw);
+ transformerFactory.newTransformer().transform(v, result);
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(sw.toString()));
+ // Build OMElement from XMLStreamReader
+ StAXOMBuilder builder = new StAXOMBuilder(reader);
+ return builder.getDocumentElement();
+ }
+}
|