Author: ningjiang
Date: Tue Dec 14 04:08:42 2010
New Revision: 1048930
URL: http://svn.apache.org/viewvc?rev=1048930&view=rev
Log:
CXF-3180 remove the marshal and unmarshal cache as the lock is related to
XmlStreamReader
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1048930&r1=1048929&r2=1048930&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Tue Dec 14 04:08:42 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);