tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1177857 - in /tuscany/sca-java-2.x/trunk/modules: binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/ databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/ databinding-jaxb/src/main/reso...
Date Fri, 30 Sep 2011 22:07:56 GMT
Author: rfeng
Date: Fri Sep 30 22:07:56 2011
New Revision: 1177857

URL: http://svn.apache.org/viewvc?rev=1177857&view=rev
Log:
Use the cached marshaller/unmarshaller for JAXB databinding

Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/InputStream2JAXB.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2OutputStream.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer

Modified: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/CustomerServiceTestCase.java
Fri Sep 30 22:07:56 2011
@@ -40,9 +40,9 @@ import com.meterware.httpunit.WebRespons
 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;
 

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/InputStream2JAXB.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/InputStream2JAXB.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/InputStream2JAXB.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/InputStream2JAXB.java
Fri Sep 30 22:07:56 2011
@@ -47,10 +47,15 @@ public class InputStream2JAXB extends Ba
         }
         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);
         }

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java
Fri Sep 30 22:07:56 2011
@@ -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);

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2OutputStream.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2OutputStream.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2OutputStream.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2OutputStream.java
Fri Sep 30 22:07:56 2011
@@ -58,9 +58,14 @@ public class JAXB2OutputStream extends B
     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);
         }

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2SAX.java
Fri Sep 30 22:07:56 2011
@@ -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 BaseTransf
     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);
         }

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2String.java
Fri Sep 30 22:07:56 2011
@@ -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 BaseTra
     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);

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
Fri Sep 30 22:07:56 2011
@@ -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;
     }

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
Fri Sep 30 22:07:56 2011
@@ -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 BaseTrans
                 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) {

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java
Fri Sep 30 22:07:56 2011
@@ -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 BaseTra
             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);
         }

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/String2JAXB.java
Fri Sep 30 22:07:56 2011
@@ -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 BaseTra
         }
         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);
         }

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java
Fri Sep 30 22:07:56 2011
@@ -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 extend
     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);
         }

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
Fri Sep 30 22:07:56 2011
@@ -34,7 +34,7 @@ org.apache.tuscany.sca.databinding.jaxb.
 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
 

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer?rev=1177857&r1=1177856&r2=1177857&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
(original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
Fri Sep 30 22:07:56 2011
@@ -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



Mime
View raw message