summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-30 22:07:56 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-30 22:07:56 +0000
commit881494d2d1f8c186ebbe45433a34ef7d859c6adb (patch)
treef186323b9bc26ca9a7da4336a64e9974a873d559 /sca-java-2.x/trunk
parent9d3cbbfe0b8a62ed9e61bf32e72f6da27c73bba8 (diff)
Use the cached marshaller/unmarshaller for JAXB databinding
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1177857 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java6
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/InputStream2JAXB.java11
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java23
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2OutputStream.java9
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java12
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java10
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java1
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java16
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java15
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java13
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java24
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer6
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer6
13 files changed, 100 insertions, 52 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
index 9e1b99c9bc..2d0057adaa 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
@@ -40,9 +40,9 @@ import com.meterware.httpunit.WebResponse;
public class CustomerServiceTestCase {
private static final String SERVICE_URL = "http://localhost:8085/Customer";
- private static final String GET_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Customer xmlns:ns2=\"http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@domain.com</email><id>John</id><name>John</name></Customer>";
- private static final String UPDATED_ITEM = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Customer xmlns:ns2=\"http://customer.services/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@updated-domain.com</email><id>John</id><name>John</name></Customer>";
- private static final String GET_UPDATED_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Customer xmlns:ns2=\"http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@updated-domain.com</email><id>John</id><name>John</name></Customer>";
+ private static final String GET_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns2:root xmlns:ns2=\"http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@domain.com</email><id>John</id><name>John</name></ns2:root>";
+ private static final String UPDATED_ITEM = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns2:root xmlns:ns2=\"http://customer.services/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@updated-domain.com</email><id>John</id><name>John</name></ns2:root>";
+ private static final String GET_UPDATED_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns2:root xmlns:ns2=\"http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"customer\"><email>john@updated-domain.com</email><id>John</id><name>John</name></ns2:root>";
private static Node node;
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/InputStream2JAXB.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/InputStream2JAXB.java
index 90ce48d086..b6baf9c0bd 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/InputStream2JAXB.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/InputStream2JAXB.java
@@ -47,10 +47,15 @@ public class InputStream2JAXB extends BaseTransformer<InputStream, Object> imple
}
try {
JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false);
- Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StreamSource streamSource = new StreamSource(source);
- Object result = unmarshaller.unmarshal(streamSource, JAXBContextHelper.getJavaType(context.getTargetDataType()));
- return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
+ Unmarshaller unmarshaller = contextHelper.getUnmarshaller(jaxbContext);
+ try {
+ Object result =
+ unmarshaller.unmarshal(streamSource, JAXBContextHelper.getJavaType(context.getTargetDataType()));
+ return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
+ } finally {
+ contextHelper.releaseJAXBUnmarshaller(jaxbContext, unmarshaller);
+ }
} catch (Exception e) {
throw new TransformationException(e);
}
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java
index 3d25af5b25..44c3a5e04f 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java
@@ -23,10 +23,10 @@ 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.BaseTransformer;
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.BaseTransformer;
import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -38,25 +38,32 @@ import org.w3c.dom.Node;
public class JAXB2Node extends BaseTransformer<Object, Node> implements PullTransformer<Object, Node> {
private DOMHelper helper;
private JAXBContextHelper contextHelper;
-
+
public JAXB2Node(ExtensionPointRegistry registry) {
super();
helper = DOMHelper.getInstance(registry);
contextHelper = JAXBContextHelper.getInstance(registry);
}
-
+
public Node transform(Object source, TransformationContext tContext) {
-// if (source == null) {
-// return null;
-// }
+ // if (source == null) {
+ // return null;
+ // }
try {
JAXBContext context = contextHelper.createJAXBContext(tContext, true);
- Marshaller marshaller = context.createMarshaller();
+
// FIXME: The default Marshaller doesn't support
// marshaller.getNode()
Document document = helper.newDocument();
Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source);
- marshaller.marshal(jaxbElement, document);
+ Marshaller marshaller = contextHelper.getMarshaller(context);
+ marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE);
+
+ try {
+ marshaller.marshal(jaxbElement, document);
+ } finally {
+ contextHelper.releaseJAXBMarshaller(context, marshaller);
+ }
return DOMDataBinding.adjustElementName(tContext, document.getDocumentElement());
} catch (Exception e) {
throw new TransformationException(e);
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2OutputStream.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2OutputStream.java
index 2e7ab628c1..0dac091186 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2OutputStream.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2OutputStream.java
@@ -58,9 +58,14 @@ public class JAXB2OutputStream extends BaseTransformer<Object, OutputStream> imp
public void transform(Object source, OutputStream target, TransformationContext tContext) {
try {
JAXBContext context = contextHelper.createJAXBContext(tContext, true);
- Marshaller marshaller = context.createMarshaller();
Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source);
- marshaller.marshal(jaxbElement, target);
+ Marshaller marshaller = contextHelper.getMarshaller(context);
+ marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE);
+ try {
+ marshaller.marshal(jaxbElement, target);
+ } finally {
+ contextHelper.releaseJAXBMarshaller(context, marshaller);
+ }
} catch (Exception e) {
throw new TransformationException(e);
}
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java
index a0b6ff8237..83c7a78034 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java
@@ -23,10 +23,10 @@ import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.apache.tuscany.sca.databinding.PushTransformer;
import org.apache.tuscany.sca.databinding.TransformationContext;
import org.apache.tuscany.sca.databinding.TransformationException;
-import org.apache.tuscany.sca.databinding.BaseTransformer;
import org.xml.sax.ContentHandler;
/**
@@ -57,9 +57,15 @@ public class JAXB2SAX extends BaseTransformer<Object, ContentHandler> implements
public void transform(Object source, ContentHandler target, TransformationContext tContext) {
try {
JAXBContext context = contextHelper.createJAXBContext(tContext, true);
- Marshaller marshaller = context.createMarshaller();
Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source);
- marshaller.marshal(jaxbElement, target);
+ Marshaller marshaller = contextHelper.getMarshaller(context);
+ marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE);
+
+ try {
+ marshaller.marshal(jaxbElement, target);
+ } finally {
+ contextHelper.releaseJAXBMarshaller(context, marshaller);
+ }
} catch (Exception e) {
throw new TransformationException(e);
}
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java
index 7ecca3a042..6731f5ae1c 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java
@@ -25,10 +25,10 @@ import javax.xml.bind.Marshaller;
import javax.xml.transform.stream.StreamResult;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
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.BaseTransformer;
import org.apache.tuscany.sca.databinding.xml.XMLStringDataBinding;
/**
@@ -44,11 +44,15 @@ public class JAXB2String extends BaseTransformer<Object, String> implements Pull
public String transform(Object source, TransformationContext tContext) {
try {
JAXBContext context = contextHelper.createJAXBContext(tContext, true);
- Marshaller marshaller = context.createMarshaller();
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
Object jaxbElement = JAXBContextHelper.createJAXBElement(context, tContext.getSourceDataType(), source);
- marshaller.marshal(jaxbElement, result);
+ Marshaller marshaller = contextHelper.getMarshaller(context);
+ try {
+ marshaller.marshal(jaxbElement, result);
+ } finally {
+ contextHelper.releaseJAXBMarshaller(context, marshaller);
+ }
return writer.toString();
} catch (Exception e) {
throw new TransformationException(e);
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
index a73e2a1c24..77b6b619ad 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
@@ -199,6 +199,7 @@ public class JAXBContextCache {
if (marshaller == null) {
marshaller = context.createMarshaller();
}
+ marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
return marshaller;
}
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
index c191f42c1d..8c66195d29 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
@@ -24,10 +24,10 @@ import javax.xml.bind.ValidationEvent;
import javax.xml.bind.util.ValidationEventCollector;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
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.BaseTransformer;
import org.w3c.dom.Node;
/**
@@ -36,19 +36,18 @@ import org.w3c.dom.Node;
*/
public class Node2JAXB extends BaseTransformer<Node, Object> implements PullTransformer<Node, Object> {
private JAXBContextHelper contextHelper;
- private ValidationEventCollector validationEventCollector = new ValidationEventCollector();
public Node2JAXB(ExtensionPointRegistry registry) {
contextHelper = JAXBContextHelper.getInstance(registry);
}
public Object transform(Node source, TransformationContext context) {
+ ValidationEventCollector validationEventCollector = new ValidationEventCollector();
Object response = null;
if (source == null)
return null;
try {
JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false);
- Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Object result;
// TUSCANY-3791
synchronized(source){
@@ -56,9 +55,14 @@ public class Node2JAXB extends BaseTransformer<Node, Object> implements PullTran
System.setProperty("jaxb.debug", "true");
unmarshaller.setListener(new DebugListener());
*/
- validationEventCollector.reset();
- unmarshaller.setEventHandler(validationEventCollector);
- result = unmarshaller.unmarshal(source, JAXBContextHelper.getJavaType(context.getTargetDataType()));
+ Unmarshaller unmarshaller = contextHelper.getUnmarshaller(jaxbContext);
+ try {
+ validationEventCollector.reset();
+ unmarshaller.setEventHandler(validationEventCollector);
+ result = unmarshaller.unmarshal(source, JAXBContextHelper.getJavaType(context.getTargetDataType()));
+ } finally {
+ contextHelper.releaseJAXBUnmarshaller(jaxbContext, unmarshaller);
+ }
}
response = JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
} catch (Exception e) {
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java
index b063d9524f..59495d4234 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java
@@ -25,10 +25,10 @@ import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
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.BaseTransformer;
/**
*
@@ -46,11 +46,16 @@ public class Reader2JAXB extends BaseTransformer<Reader, Object> implements
return null;
}
try {
- JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false);
- Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StreamSource streamSource = new StreamSource(source);
- Object result = unmarshaller.unmarshal(streamSource, JAXBContextHelper.getJavaType(context.getTargetDataType()));
- return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
+
+ JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false);
+ Unmarshaller unmarshaller = contextHelper.getUnmarshaller(jaxbContext);
+ try {
+ Object result = unmarshaller.unmarshal(streamSource, JAXBContextHelper.getJavaType(context.getTargetDataType()));
+ return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
+ } finally {
+ contextHelper.releaseJAXBUnmarshaller(jaxbContext, unmarshaller);
+ }
} catch (Exception e) {
throw new TransformationException(e);
}
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java
index 9d0accefcc..82259d8618 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java
@@ -25,10 +25,10 @@ import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
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.BaseTransformer;
import org.apache.tuscany.sca.databinding.xml.XMLStringDataBinding;
/**
@@ -49,10 +49,15 @@ public class String2JAXB extends BaseTransformer<String, Object> implements
}
try {
JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false);
- Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+
StreamSource streamSource = new StreamSource(new StringReader(source));
- Object result = unmarshaller.unmarshal(streamSource, JAXBContextHelper.getJavaType(context.getTargetDataType()));
- return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
+ Unmarshaller unmarshaller = contextHelper.getUnmarshaller(jaxbContext);
+ try {
+ Object result = unmarshaller.unmarshal(streamSource, JAXBContextHelper.getJavaType(context.getTargetDataType()));
+ return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
+ } finally {
+ contextHelper.releaseJAXBUnmarshaller(jaxbContext, unmarshaller);
+ }
} catch (Exception e) {
throw new TransformationException(e);
}
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java
index 9c3760b119..4d400f963d 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java
@@ -23,10 +23,10 @@ import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
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.BaseTransformer;
/**
*
@@ -36,23 +36,29 @@ public class XMLStreamReader2JAXB extends BaseTransformer<XMLStreamReader, Objec
PullTransformer<XMLStreamReader, Object> {
private JAXBContextHelper contextHelper;
-
+
public XMLStreamReader2JAXB(ExtensionPointRegistry registry) {
contextHelper = JAXBContextHelper.getInstance(registry);
}
-
+
public Object transform(XMLStreamReader source, TransformationContext context) {
if (source == null) {
return null;
}
try {
JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false);
- Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
- // FIXME: [rfeng] If the java type is Object.class, the unmarshalled result will be
- // a DOM Node
- Object result = unmarshaller.unmarshal(source, JAXBContextHelper.getJavaType(context.getTargetDataType()));
- source.close();
- return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
+ Unmarshaller unmarshaller = contextHelper.getUnmarshaller(jaxbContext);
+ try {
+ // FIXME: [rfeng] If the java type is Object.class, the unmarshalled result will be
+ // a DOM Node
+ Object result =
+ unmarshaller.unmarshal(source, JAXBContextHelper.getJavaType(context.getTargetDataType()));
+ source.close();
+ return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
+ } finally {
+ contextHelper.releaseJAXBUnmarshaller(jaxbContext, unmarshaller);
+ }
+
} catch (Exception e) {
throw new TransformationException(e);
}
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
index 48d325c126..786e007560 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
@@ -34,7 +34,7 @@ org.apache.tuscany.sca.databinding.jaxb.InputStream2JAXB;source=application/xml#
org.apache.tuscany.sca.databinding.jaxb.InputStream2JAXB;source=application/xml#java.io.InputStream;target=javax.xml.bind.JAXBElement,weight=50,public=true
org.apache.tuscany.sca.databinding.jaxb.InputStream2JAXB;source=application/xml#java.io.InputStream;target=java:simpleType,weight=50,public=true
-org.apache.tuscany.sca.databinding.jaxb.InputStream2JAXB;source=text/xml#java.io.InputStream;target=javax.xml.bind.JAXBElement,weight=50,public=true
-org.apache.tuscany.sca.databinding.jaxb.InputStream2JAXB;source=text/xml#java.io.InputStream;target=java:complexType,weight=50,public=true
-org.apache.tuscany.sca.databinding.jaxb.InputStream2JAXB;source=text/xml#java.io.InputStream;target=java:simpleType,weight=50,public=true
+org.apache.tuscany.sca.databinding.jaxb.InputStream2JAXB;source=text/xml#java.io.InputStream;target=javax.xml.bind.JAXBElement,weight=50,public=false
+org.apache.tuscany.sca.databinding.jaxb.InputStream2JAXB;source=text/xml#java.io.InputStream;target=java:complexType,weight=50,public=false
+org.apache.tuscany.sca.databinding.jaxb.InputStream2JAXB;source=text/xml#java.io.InputStream;target=java:simpleType,weight=50,public=false
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
index ff00361404..37b151726f 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
@@ -14,6 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-org.apache.tuscany.sca.databinding.jaxb.JAXB2OutputStream;source=javax.xml.bind.JAXBElement;target=java.io.OutputStream,weight=50,public=true
-org.apache.tuscany.sca.databinding.jaxb.JAXB2OutputStream;source=java:complexType;target=java.io.OutputStream,weight=50,public=true
-org.apache.tuscany.sca.databinding.jaxb.JAXB2OutputStream;source=java:simpleType;target=java.io.OutputStream,weight=50,public=true
+org.apache.tuscany.sca.databinding.jaxb.JAXB2OutputStream;source=javax.xml.bind.JAXBElement;target=java.io.OutputStream,weight=50,public=false
+org.apache.tuscany.sca.databinding.jaxb.JAXB2OutputStream;source=java:complexType;target=java.io.OutputStream,weight=50,public=false
+org.apache.tuscany.sca.databinding.jaxb.JAXB2OutputStream;source=java:simpleType;target=java.io.OutputStream,weight=50,public=false