diff options
Diffstat (limited to 'java/sca/modules/databinding-jaxb')
5 files changed, 29 insertions, 11 deletions
diff --git a/java/sca/modules/databinding-jaxb/META-INF/MANIFEST.MF b/java/sca/modules/databinding-jaxb/META-INF/MANIFEST.MF index 274579ba03..c4ca84e5fd 100644 --- a/java/sca/modules/databinding-jaxb/META-INF/MANIFEST.MF +++ b/java/sca/modules/databinding-jaxb/META-INF/MANIFEST.MF @@ -32,7 +32,9 @@ Import-Package: javax.activation, javax.xml.transform.dom,
javax.xml.transform.stream,
org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.common.xml.dom;version="2.0.0",
org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.databinding;version="2.0.0",
org.apache.tuscany.sca.databinding.impl;version="2.0.0",
org.apache.tuscany.sca.databinding.jaxb;version="2.0.0",
diff --git a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java index 3e262c7d12..1ff8f79059 100644 --- a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java +++ b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java @@ -21,11 +21,13 @@ package org.apache.tuscany.sca.databinding.jaxb; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; +import org.apache.tuscany.sca.common.xml.dom.DOMHelper; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.PullTransformer; import org.apache.tuscany.sca.databinding.TransformationContext; import org.apache.tuscany.sca.databinding.TransformationException; import org.apache.tuscany.sca.databinding.impl.BaseTransformer; -import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -34,7 +36,13 @@ import org.w3c.dom.Node; * @version $Rev$ $Date$ */ public class JAXB2Node extends BaseTransformer<Object, Node> implements PullTransformer<Object, Node> { - + private DOMHelper helper; + + public JAXB2Node(ExtensionPointRegistry registry) { + super(); + helper = DOMHelper.getInstance(registry); + } + public Node transform(Object source, TransformationContext tContext) { // if (source == null) { // return null; @@ -44,10 +52,10 @@ public class JAXB2Node extends BaseTransformer<Object, Node> implements PullTran Marshaller marshaller = context.createMarshaller(); // FIXME: The default Marshaller doesn't support // marshaller.getNode() - Document document = DOMHelper.newDocument(); + Document document = helper.newDocument(); Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source); marshaller.marshal(jaxbElement, document); - return DOMHelper.adjustElementName(tContext, document.getDocumentElement()); + return DOMDataBinding.adjustElementName(tContext, document.getDocumentElement()); } catch (Exception e) { throw new TransformationException(e); } diff --git a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java index 38efd288cb..14e5148050 100644 --- a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java +++ b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java @@ -26,10 +26,11 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.common.xml.dom.DOMHelper; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.WrapperHandler; import org.apache.tuscany.sca.databinding.XMLTypeHelper; import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; -import org.apache.tuscany.sca.databinding.impl.DOMHelper; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; @@ -49,11 +50,13 @@ public class JAXBDataBinding extends BaseDataBinding { private JAXBWrapperHandler wrapperHandler; private JAXBTypeHelper xmlTypeHelper; + private DOMHelper domHelper; - public JAXBDataBinding() { + public JAXBDataBinding(ExtensionPointRegistry registry) { super(NAME, JAXBElement.class); this.wrapperHandler = new JAXBWrapperHandler(); this.xmlTypeHelper = new JAXBTypeHelper(); + this.domHelper = DOMHelper.getInstance(registry); } @Override @@ -105,7 +108,7 @@ public class JAXBDataBinding extends BaseDataBinding { } JAXBContext context = JAXBContextHelper.createJAXBContext(dataType); arg = JAXBContextHelper.createJAXBElement(context, dataType, arg); - Document doc = DOMHelper.newDocument(); + Document doc = domHelper.newDocument(); context.createMarshaller().marshal(arg, doc); Object value = context.createUnmarshaller().unmarshal(doc, dataType.getPhysical()); if (isElement && value instanceof JAXBElement) { diff --git a/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBindingTestCase.java b/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBindingTestCase.java index 97038734f5..e612af396b 100644 --- a/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBindingTestCase.java +++ b/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBindingTestCase.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue; import javax.xml.bind.JAXBElement; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; @@ -46,7 +47,7 @@ public class JAXBDataBindingTestCase { @Before public void setUp() throws Exception { - binding = new JAXBDataBinding(); + binding = new JAXBDataBinding(new DefaultExtensionPointRegistry()); } /** diff --git a/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java b/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java index 61e3fcaaab..f1329ab571 100644 --- a/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java +++ b/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/sca/databinding/jaxb/JAXBTestCase.java @@ -22,6 +22,8 @@ import java.io.StringReader; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.TransformationContext; import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; import org.apache.tuscany.sca.interfacedef.DataType; @@ -68,6 +70,8 @@ public class JAXBTestCase { + " </item>" + " </items>" + "</ipo:purchaseOrder>"; + + private static ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); @Test public void testTransform() throws Exception { @@ -85,7 +89,7 @@ public class JAXBTestCase { TransformationContext tContext1 = new TransformationContextImpl(); tContext1.setSourceDataType(sourceDataType); - JAXB2Node t1 = new JAXB2Node(); + JAXB2Node t1 = new JAXB2Node(registry); Node node = t1.transform(object1, tContext1); Assert.assertNotNull(node); @@ -114,7 +118,7 @@ public class JAXBTestCase { TransformationContext tContext1 = new TransformationContextImpl(); tContext1.setSourceDataType(sourceDataType); - JAXB2Node t1 = new JAXB2Node(); + JAXB2Node t1 = new JAXB2Node(registry); Node node = t1.transform(object1, tContext1); Assert.assertNotNull(node); @@ -134,7 +138,7 @@ public class JAXBTestCase { tContext1.setSourceDataType(sourceDataType); - JAXB2Node t1 = new JAXB2Node(); + JAXB2Node t1 = new JAXB2Node(registry); PurchaseOrderType po = new ObjectFactory().createPurchaseOrderType(); Node node = t1.transform(po, tContext1); |