diff options
3 files changed, 78 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/core-databinding/pom.xml b/branches/sca-java-1.x/modules/core-databinding/pom.xml index 95b4b1f71f..26080f87b3 100644 --- a/branches/sca-java-1.x/modules/core-databinding/pom.xml +++ b/branches/sca-java-1.x/modules/core-databinding/pom.xml @@ -85,6 +85,37 @@ </exclusion> </exclusions> </dependency> + + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-api</artifactId> + <version>1.2.7</version> + <exclusions> + <exclusion> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + </exclusion> + <exclusion> + <groupId>javax.mail</groupId> + <artifactId>mail</artifactId> + </exclusion> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>xml-apis</groupId> + <artifactId>xml-apis</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-impl</artifactId> + <version>1.2.7</version> + <scope>runtime</scope> + </dependency> </dependencies> <build> 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();
+ }
+}
|