cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r678629 - in /cxf/trunk/rt/databinding/jaxb/src: main/java/org/apache/cxf/jaxb/JAXBDataBinding.java test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
Date Tue, 22 Jul 2008 03:54:45 GMT
Author: dkulp
Date: Mon Jul 21 20:54:45 2008
New Revision: 678629

URL: http://svn.apache.org/viewvc?rev=678629&view=rev
Log:
[CXF-1712] Fix problems of caching objectfactories based on classname instead of Package object

Modified:
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=678629&r1=678628&r2=678629&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Mon
Jul 21 20:54:45 2008
@@ -24,13 +24,13 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -116,26 +116,26 @@
     }
     
     private static final class CachedClassOrNull {
-        private Class<?> cachedClass;
+        private WeakReference<Class<?>> cachedClass;
 
         public CachedClassOrNull(Class<?> cachedClass) {
-            this.cachedClass = cachedClass;
+            this.cachedClass = new WeakReference<Class<?>>(cachedClass);
         }
 
         public Class<?> getCachedClass() {
-            return cachedClass;
+            return cachedClass == null ? null : cachedClass.get();
         }
 
         public void setCachedClass(Class<?> cachedClass) {
-            this.cachedClass = cachedClass;
+            this.cachedClass = new WeakReference<Class<?>>(cachedClass);
         }
     }
 
     private static final Map<Set<Class<?>>, CachedContextAndSchemas> JAXBCONTEXT_CACHE

         = new CacheMap<Set<Class<?>>, CachedContextAndSchemas>();
     
-    private static final Map<String, CachedClassOrNull> OBJECT_FACTORY_CACHE
-        = new CacheMap<String, CachedClassOrNull>();
+    private static final Map<Package, CachedClassOrNull> OBJECT_FACTORY_CACHE
+        = new CacheMap<Package, CachedClassOrNull>();
 
     Class[] extraClass;
 
@@ -404,16 +404,6 @@
     }
 
     public JAXBContext createJAXBContext(Set<Class<?>> classes, String defaultNs)
throws JAXBException {
-        Iterator it = classes.iterator();
-        String className = "";
-        Object remoteExceptionObject = null;
-        while (it.hasNext()) {
-            remoteExceptionObject = (Class)it.next();
-            className = remoteExceptionObject.toString();
-            if (!("".equals(className)) && className.contains("RemoteException"))
{
-                it.remove();
-            }
-        }
         // add user extra class into jaxb context
         if (extraClass != null && extraClass.length > 0) {
             for (Class clz : extraClass) {
@@ -432,13 +422,17 @@
         for (Class<?> jcls : classes) {
             String pkgName = PackageUtils.getPackageName(jcls);
             if (!packages.containsKey(pkgName)) {
+                Package pkg = jcls.getPackage();
+                
                 packages.put(pkgName, jcls.getResourceAsStream("jaxb.index"));
                 packageLoaders.put(pkgName, jcls.getClassLoader());
                 String objectFactoryClassName = pkgName + "." + "ObjectFactory";
                 Class<?> ofactory = null;
                 CachedClassOrNull cachedFactory = null;
-                synchronized (OBJECT_FACTORY_CACHE) {
-                    cachedFactory = OBJECT_FACTORY_CACHE.get(objectFactoryClassName);
+                if (pkg != null) {
+                    synchronized (OBJECT_FACTORY_CACHE) {
+                        cachedFactory = OBJECT_FACTORY_CACHE.get(pkg);
+                    }
                 }
                 if (cachedFactory != null) {
                     ofactory = cachedFactory.getCachedClass();
@@ -448,9 +442,9 @@
                         ofactory = Class.forName(objectFactoryClassName, false, jcls
                                                  .getClassLoader());
                         objectFactories.add(ofactory);
-                        addToObjectFactoryCache(objectFactoryClassName, ofactory);
+                        addToObjectFactoryCache(pkg, ofactory);
                     } catch (ClassNotFoundException e) {
-                        addToObjectFactoryCache(objectFactoryClassName, null);
+                        addToObjectFactoryCache(pkg, null);
                     }
                 } else {
                     objectFactories.add(ofactory);                    
@@ -529,9 +523,12 @@
         return cachedContextAndSchemas.getContext();
     }
 
-    private void addToObjectFactoryCache(String objectFactoryClassName, Class<?> ofactory)
{
+    private void addToObjectFactoryCache(Package objectFactoryPkg, Class<?> ofactory)
{
+        if (objectFactoryPkg == null) {
+            return;
+        }
         synchronized (OBJECT_FACTORY_CACHE) {
-            OBJECT_FACTORY_CACHE.put(objectFactoryClassName, 
+            OBJECT_FACTORY_CACHE.put(objectFactoryPkg, 
                                      new CachedClassOrNull(ofactory));
         }
     }

Modified: cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java?rev=678629&r1=678628&r2=678629&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
Mon Jul 21 20:54:45 2008
@@ -121,17 +121,6 @@
     }
 
     @Test
-    public void testCreateJAXBContext() throws Exception {
-        try {
-            Set<Class<?>> classes = new HashSet<Class<?>>();
-            classes.add(Class.forName("java.rmi.RemoteException"));
-            assertNotNull(new JAXBDataBinding().createJAXBContext(classes));
-        } catch (Exception e) {
-            assertFalse(true);
-        }
-        
-    }
-    @Test
     public void testCreateReader() {
         DataReader reader = jaxbDataBinding.createReader(XMLStreamReader.class);
         assertTrue(reader instanceof DataReaderImpl);



Mime
View raw message