diff options
Diffstat (limited to 'branches/sca-java-1.3/modules/databinding-jaxb')
2 files changed, 15 insertions, 12 deletions
diff --git a/branches/sca-java-1.3/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java b/branches/sca-java-1.3/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java index 8b527bf079..30ca226dc1 100644 --- a/branches/sca-java-1.3/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java +++ b/branches/sca-java-1.3/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/branches/sca-java-1.3/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java b/branches/sca-java-1.3/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java index e5fbd50b30..8e82e7bb38 100644 --- a/branches/sca-java-1.3/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java +++ b/branches/sca-java-1.3/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"); |