From 169777e33763d7a38fdaad4449d168c12832a623 Mon Sep 17 00:00:00 2001 From: scottkurz Date: Fri, 29 May 2009 01:09:54 +0000 Subject: Fix for TUSCANY-3065. Thanks Greg. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@779808 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/databinding/jaxb/axiom/JAXBDataSource.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'branches/sca-java-1.x/modules') diff --git a/branches/sca-java-1.x/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java b/branches/sca-java-1.x/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java index d5cd68cd70..27c46cdb21 100644 --- a/branches/sca-java-1.x/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java +++ b/branches/sca-java-1.x/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java @@ -49,7 +49,6 @@ import org.apache.tuscany.sca.databinding.jaxb.JAXBContextHelper; public class JAXBDataSource extends OMDataSourceExtBase { private JAXBContext context; private Object element; - private Marshaller marshaller; public JAXBDataSource(Object element, JAXBContext context) { this.element = element; @@ -57,11 +56,7 @@ public class JAXBDataSource extends OMDataSourceExtBase { } private Marshaller getMarshaller() throws JAXBException { - if (marshaller == null) { - // For thread safety, not sure we can cache the marshaller - marshaller = JAXBContextHelper.getMarshaller(context); - } - return marshaller; + return JAXBContextHelper.getMarshaller(context); } private void releaseMarshaller(Marshaller marshaller) { @@ -103,8 +98,9 @@ public class JAXBDataSource extends OMDataSourceExtBase { // marshaller.setProperty(Marshaller.JAXB_ENCODING, format.getCharSetEncoding()); AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws Exception { + Marshaller marshaller = null; try { - Marshaller marshaller = getMarshaller(); + marshaller = getMarshaller(); // Marshalling directly to the output stream is faster than marshalling through the // XMLStreamWriter. Take advantage of this optimization if there is an output stream. OutputStream os = getOutputStream(xmlWriter); @@ -129,8 +125,9 @@ public class JAXBDataSource extends OMDataSourceExtBase { // marshaller.setProperty(Marshaller.JAXB_ENCODING, format.getCharSetEncoding()); AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws Exception { + Marshaller marshaller = null; try { - Marshaller marshaller = getMarshaller(); + marshaller = getMarshaller(); marshaller.marshal(element, output); } finally { releaseMarshaller(marshaller); @@ -147,8 +144,9 @@ public class JAXBDataSource extends OMDataSourceExtBase { try { AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws Exception { + Marshaller marshaller = null; try { - Marshaller marshaller = getMarshaller(); + marshaller = getMarshaller(); marshaller.marshal(element, writer); } finally { releaseMarshaller(marshaller); @@ -176,9 +174,10 @@ public class JAXBDataSource extends OMDataSourceExtBase { try { return AccessController.doPrivileged(new PrivilegedExceptionAction() { public byte[] run() throws JAXBException, XMLStreamException, UnsupportedEncodingException { + Marshaller marshaller = null; try { StringWriter sw = new StringWriter(); - Marshaller marshaller = getMarshaller(); + marshaller = getMarshaller(); marshaller.marshal(element, sw); return sw.toString().getBytes(encoding); } finally { -- cgit v1.2.3