summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/databinding-jaxb
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-06-21 07:18:50 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-06-21 07:18:50 +0000
commitd9b088dff179d91e20324cbfee1138d8acbcf32c (patch)
treea66ac56f3a69771d64b2fc0e770a0bb7a79ea2c6 /java/sca/modules/databinding-jaxb
parent95e1fea0cfbebbf92d1493b85f20df3c3e7065ea (diff)
Avoid extra classes in the default JAXBContext
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@670156 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/databinding-jaxb')
-rw-r--r--java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java23
-rw-r--r--java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java4
2 files changed, 15 insertions, 12 deletions
diff --git a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
index 8b527bf079..30ca226dc1 100644
--- a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
+++ b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
@@ -75,17 +75,21 @@ public class JAXBContextCache {
protected static final Set<Class<?>> BUILTIN_CLASSES_SET = new HashSet<Class<?>>(Arrays.asList(JAXB_BUILTIN_CLASSES));
+ /*
protected static Class<?>[] COMMON_ARRAY_CLASSES =
new Class[] {char[].class, short[].class, int[].class, long[].class, float[].class, double[].class,
String[].class
};
protected static final Set<Class<?>> COMMON_CLASSES_SET = new HashSet<Class<?>>(Arrays.asList(COMMON_ARRAY_CLASSES));
+ */
protected LRUCache<Object, JAXBContext> cache;
protected LRUCache<JAXBContext, Unmarshaller> upool;
protected LRUCache<JAXBContext, Marshaller> mpool;
- protected JAXBContext commonContext;
+
+ // protected JAXBContext commonContext;
+ protected JAXBContext defaultContext;
public JAXBContextCache() {
this(CACHE_SIZE, CACHE_SIZE, CACHE_SIZE);
@@ -95,12 +99,12 @@ public class JAXBContextCache {
cache = new LRUCache<Object, JAXBContext>(contextSize);
upool = new LRUCache<JAXBContext, Unmarshaller>(unmarshallerSize);
mpool = new LRUCache<JAXBContext, Marshaller>(marshallerSize);
- commonContext = getCommonJAXBContext();
+ defaultContext = getDefaultJAXBContext();
}
-
- public static JAXBContext getCommonJAXBContext() {
+
+ public static JAXBContext getDefaultJAXBContext() {
try {
- return JAXBContext.newInstance(COMMON_CLASSES_SET.toArray(new Class<?>[COMMON_CLASSES_SET.size()]));
+ return JAXBContext.newInstance();
} catch (JAXBException e) {
throw new IllegalArgumentException(e);
}
@@ -201,8 +205,8 @@ public class JAXBContextCache {
}
public JAXBContext getJAXBContext(Class<?> cls) throws JAXBException {
- if (COMMON_CLASSES_SET.contains(cls) || BUILTIN_CLASSES_SET.contains(cls)) {
- return commonContext;
+ if (BUILTIN_CLASSES_SET.contains(cls)) {
+ return defaultContext;
}
synchronized (cache) {
JAXBContext context = cache.get(cls);
@@ -253,9 +257,8 @@ public class JAXBContextCache {
classSet.remove(Image[].class);
}
- // Is the common one
- if (COMMON_CLASSES_SET.containsAll(classSet)) {
- return commonContext;
+ if(classSet.isEmpty()) {
+ return defaultContext;
}
// For single class
diff --git a/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java b/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java
index e5fbd50b30..8e82e7bb38 100644
--- a/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java
+++ b/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java
@@ -50,8 +50,8 @@ public class JAXBContextCacheTestCase {
JAXBContext context3 = cache.getJAXBContext(String[].class);
JAXBContext context4 = cache.getJAXBContext(Source.class);
Assert.assertSame(context1, context2);
- Assert.assertSame(context2, context3);
- Assert.assertSame(context3, context4);
+ Assert.assertNotSame(context2, context3);
+ Assert.assertSame(context1, context4);
QName name = new QName("http://example.com/ns1", "e1");
JAXBElement<String> element = new JAXBElement<String>(name, String.class, "123");