diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-17 05:50:57 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-17 05:50:57 +0000 |
commit | 3c6f40cb143a0e929891d45b0bea69983bf957cb (patch) | |
tree | 6598153d8f396e4c59a6232eb17d56576f781128 /branches/sca-equinox/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java | |
parent | 876081a082efa0cfe078137ebcde076483f2b41c (diff) |
Commit changes for TUSCANY-2590.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@696164 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-equinox/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java')
-rw-r--r-- | branches/sca-equinox/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/branches/sca-equinox/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java b/branches/sca-equinox/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java index dd9fbfbfd0..b6fa362ed9 100644 --- a/branches/sca-equinox/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java +++ b/branches/sca-equinox/modules/databinding-jaxb-axiom/src/main/java/org/apache/tuscany/sca/databinding/jaxb/axiom/JAXBDataSource.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.tuscany.sca.databinding.jaxb.axiom; import java.io.OutputStream; @@ -37,6 +36,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.axiom.om.OMDataSource; import org.apache.axiom.om.OMOutputFormat; import org.apache.axiom.om.util.StAXUtils; +import org.apache.tuscany.sca.databinding.jaxb.JAXBContextHelper; /** * @@ -55,11 +55,14 @@ public class JAXBDataSource implements OMDataSource { private Marshaller getMarshaller() throws JAXBException { if (marshaller == null) { // For thread safety, not sure we can cache the marshaller - // marshaller = JAXBContextHelper.getMarshaller(context); - marshaller = context.createMarshaller(); + marshaller = JAXBContextHelper.getMarshaller(context); } return marshaller; } + + private void releaseMarshaller(Marshaller marshaller) { + JAXBContextHelper.releaseJAXBMarshaller(context, marshaller); + } public XMLStreamReader getReader() throws XMLStreamException { // FIXME: [rfeng] This is a quick and dirty implementation @@ -75,11 +78,12 @@ public class JAXBDataSource implements OMDataSource { // marshaller.setProperty(Marshaller.JAXB_ENCODING, format.getCharSetEncoding()); AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { - Marshaller marshaller = getMarshaller(); - // Set the FRAGEMENT property to avoid duplicate XML declaration - marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); - marshaller.marshal(element, xmlWriter); - marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); + try { + Marshaller marshaller = getMarshaller(); + marshaller.marshal(element, xmlWriter); + } finally { + releaseMarshaller(marshaller); + } return null; } }); @@ -93,8 +97,12 @@ public class JAXBDataSource implements OMDataSource { // marshaller.setProperty(Marshaller.JAXB_ENCODING, format.getCharSetEncoding()); AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { - Marshaller marshaller = getMarshaller(); - marshaller.marshal(element, output); + try { + Marshaller marshaller = getMarshaller(); + marshaller.marshal(element, output); + } finally { + releaseMarshaller(marshaller); + } return null; } }); @@ -107,8 +115,12 @@ public class JAXBDataSource implements OMDataSource { try { AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { public Object run() throws Exception { - Marshaller marshaller = getMarshaller(); - marshaller.marshal(element, writer); + try { + Marshaller marshaller = getMarshaller(); + marshaller.marshal(element, writer); + } finally { + releaseMarshaller(marshaller); + } return null; } }); |