Author: ningjiang Date: Tue Dec 14 05:20:26 2010 New Revision: 1048938 URL: http://svn.apache.org/viewvc?rev=1048938&view=rev Log: Merged revisions 1048937 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.3.x-fixes
................ r1048937 | ningjiang | 2010-12-14 13:09:07 +0800 (Tue, 14 Dec 2010) | 9 lines Merged revisions 1048930 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1048930 | ningjiang | 2010-12-14 12:08:42 +0800 (Tue, 14 Dec 2010) | 1 line CXF-3180 remove the marshal and unmarshal cache as the lock is related to XmlStreamReader ........ ................ Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1048938&r1=1048937&r2=1048938&view=diff ============================================================================== --- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java (original) +++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java Tue Dec 14 05:20:26 2010 @@ -24,7 +24,6 @@ import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.lang.annotation.Annotation; -import java.lang.ref.SoftReference; import java.lang.reflect.Array; import java.lang.reflect.Type; import java.util.ArrayList; @@ -92,6 +91,7 @@ public abstract class AbstractJAXBProvid private static Map<String, JAXBContext> packageContexts = new HashMap<String, JAXBContext>(); private static Map<Class<?>, JAXBContext> classContexts = new HashMap<Class<?>, JAXBContext>(); + protected Set<Class<?>> collectionContextClasses = new HashSet<Class<?>>(); protected JAXBContext collectionContext; @@ -106,8 +106,6 @@ public abstract class AbstractJAXBProvid protected List<String> inDropElements; protected Map<String, String> inElementsMap; protected Map<String, String> inAppendMap; - protected Map<Long, SoftReference<JAXBMarshallerUnmarshallerCache>> threadMarshallerCaches - = new HashMap<Long, SoftReference<JAXBMarshallerUnmarshallerCache>>(); private boolean attributesToElements; private MessageContext mc; @@ -351,7 +349,6 @@ public abstract class AbstractJAXBProvid } } - public JAXBContext getPackageContext(Class<?> type) { if (type == null || type == JAXBElement.class) { return null; @@ -375,24 +372,6 @@ public abstract class AbstractJAXBProvid } } - public JAXBMarshallerUnmarshallerCache getThreadMarshallerCache(Thread thread) { - JAXBMarshallerUnmarshallerCache marshallerUnMarshallerCache = null; - synchronized (threadMarshallerCaches) { - SoftReference<JAXBMarshallerUnmarshallerCache> marshallerUnMarshallerCacheRef = - threadMarshallerCaches.get(thread.getId()); - if (marshallerUnMarshallerCacheRef != null) { - marshallerUnMarshallerCache = marshallerUnMarshallerCacheRef.get(); - } - if (marshallerUnMarshallerCache == null) { - marshallerUnMarshallerCache = new JAXBMarshallerUnmarshallerCache(); - threadMarshallerCaches - .put(thread.getId(), - new SoftReference<JAXBMarshallerUnmarshallerCache>(marshallerUnMarshallerCache)); - } - return marshallerUnMarshallerCache; - } - } - protected boolean isSupported(Class<?> type, Type genericType, Annotation[] anns) { if (jaxbElementClassMap != null && jaxbElementClassMap.containsKey(type.getName()) || isSkipJaxbChecks()) { @@ -429,10 +408,7 @@ public abstract class AbstractJAXBProvid throws JAXBException { JAXBContext context = isCollection ? getCollectionContext(cls) : getJAXBContext(cls, genericType); - - JAXBMarshallerUnmarshallerCache marshallerUnmarshallerCache = - getThreadMarshallerCache(Thread.currentThread()); - Unmarshaller unmarshaller = marshallerUnmarshallerCache.getUnmarshall(context); + Unmarshaller unmarshaller = context.createUnmarshaller(); if (schema != null) { unmarshaller.setSchema(schema); } @@ -451,16 +427,9 @@ public abstract class AbstractJAXBProvid ? ((JAXBElement)obj).getDeclaredType() : cls; JAXBContext context = getJAXBContext(objClazz, genericType); - JAXBMarshallerUnmarshallerCache marshallerUnmarshallerCache = - getThreadMarshallerCache(Thread.currentThread()); - Marshaller marshaller = marshallerUnmarshallerCache.getMarshall(context); - // need to set this value to make JAXRSClientServerBookTest passed - marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); + Marshaller marshaller = context.createMarshaller(); if (enc != null) { marshaller.setProperty(Marshaller.JAXB_ENCODING, enc); - } else { - // set the default the value to the marshaller - marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); } return marshaller; } @@ -706,40 +675,6 @@ public abstract class AbstractJAXBProvid } - protected static class JAXBMarshallerUnmarshallerCache { - private Map<JAXBContext, Marshaller> marshallers = new HashMap<JAXBContext, Marshaller>(); - private Map<JAXBContext, Unmarshaller> unmarshallers = new HashMap<JAXBContext, Unmarshaller>(); - - public Marshaller getMarshall(JAXBContext jaxbContext) throws JAXBException { - if (jaxbContext == null) { - return null; - } - // don't need the synchronized statement, as this ojbect is used per thread - Marshaller marshaller = marshallers.get(jaxbContext); - if (marshaller == null) { - marshaller = jaxbContext.createMarshaller(); - marshallers.put(jaxbContext, marshaller); - } - return marshaller; - - } - - public Unmarshaller getUnmarshall(JAXBContext jaxbContext) throws JAXBException { - if (jaxbContext == null) { - return null; - } - // don't need the synchronized statement, as this ojbect is used per thread - Unmarshaller unmarshaller = unmarshallers.get(jaxbContext); - if (unmarshaller == null) { - unmarshaller = jaxbContext.createUnmarshaller(); - unmarshallers.put(jaxbContext, unmarshaller); - } - return unmarshaller; - - } - - } - protected static class OutTransformWriter extends DelegatingXMLStreamWriter { private QNamesMap elementsMap; private Map<QName, QName> appendMap = new HashMap<QName, QName>(5);
