geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1087589 - in /geronimo/bundles/trunk/axis2: pom.xml src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java src/main/java/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java src/main/java/org/apache/axis2/jaxws/runtime/
Date Fri, 01 Apr 2011 05:47:52 GMT
Author: xuhaihong
Date: Fri Apr  1 05:47:52 2011
New Revision: 1087589

URL: http://svn.apache.org/viewvc?rev=1087589&view=rev
Log:
Try with the new Axis2 change from Geronimo side

Removed:
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/runtime/
Modified:
    geronimo/bundles/trunk/axis2/pom.xml
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
    geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java

Modified: geronimo/bundles/trunk/axis2/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/pom.xml?rev=1087589&r1=1087588&r2=1087589&view=diff
==============================================================================
--- geronimo/bundles/trunk/axis2/pom.xml (original)
+++ geronimo/bundles/trunk/axis2/pom.xml Fri Apr  1 05:47:52 2011
@@ -243,12 +243,7 @@
                            org/apache/axis2/jaxws/message/databinding/JAXBUtils$4.class=target/classes/org/apache/axis2/jaxws/message/databinding/JAXBUtils$4.class,
                            org/apache/axis2/jaxws/message/databinding/JAXBUtils$3.class=target/classes/org/apache/axis2/jaxws/message/databinding/JAXBUtils$3.class,
                            org/apache/axis2/jaxws/message/databinding/JAXBUtils$2.class=target/classes/org/apache/axis2/jaxws/message/databinding/JAXBUtils$2.class,
-                           org/apache/axis2/jaxws/message/databinding/JAXBUtils$1.class=target/classes/org/apache/axis2/jaxws/message/databinding/JAXBUtils$1.class,
-                           org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor.class=target/classes/org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor.class,
-                           org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor$1.class=target/classes/org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor$1.class,
-                           org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor$2.class=target/classes/org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor$2.class,
-                           org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor$3.class=target/classes/org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor$3.class,
-                           org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor$4.class=target/classes/org/apache/axis2/jaxws/runtime/description/marshal/impl/ArtifactProcessor$4.class
+                           org/apache/axis2/jaxws/message/databinding/JAXBUtils$1.class=target/classes/org/apache/axis2/jaxws/message/databinding/JAXBUtils$1.class
                         </Include-Resource>
                         <SPI-Provider>true</SPI-Provider>
                     </instructions>

Modified: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java?rev=1087589&r1=1087588&r2=1087589&view=diff
==============================================================================
--- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
(original)
+++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/client/proxy/JAXWSProxyHandler.java
Fri Apr  1 05:47:52 2011
@@ -19,9 +19,27 @@
 
 package org.apache.axis2.jaxws.client.proxy;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.List;
+import java.util.TreeSet;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Holder;
+import javax.xml.ws.Response;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.WebServiceFeature;
+import javax.xml.ws.soap.SOAPBinding;
+
 import org.apache.axis2.addressing.AddressingConstants;
-import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.addressing.AddressingConstants.Final;
+import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.java.security.AccessController;
 import org.apache.axis2.jaxws.BindingProvider;
 import org.apache.axis2.jaxws.ExceptionFactory;
@@ -51,21 +69,6 @@ import org.apache.axis2.transport.http.H
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.xml.bind.JAXBContext;
-import javax.xml.ws.AsyncHandler;
-import javax.xml.ws.Holder;
-import javax.xml.ws.Response;
-import javax.xml.ws.WebServiceException;
-import javax.xml.ws.WebServiceFeature;
-import javax.xml.ws.soap.SOAPBinding;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
 /**
  * ProxyHandler is the java.lang.reflect.InvocationHandler implementation. When a JAX-WS
client
  * calls the method on a proxy object, created by calling the ServiceDelegate.getPort(...)
method,
@@ -696,6 +699,7 @@ public class JAXWSProxyHandler extends B
                 }
             }
             
+            List<String> classRefs = JAXBUtils.pruneDirectives(new TreeSet<String>(marshalDesc.getPackages()));
             // Heuristic to choose the better classloader to marshal the
             // data.  Slight priority given to the classloader that loaded
             // the sei class.
@@ -713,6 +717,10 @@ public class JAXWSProxyHandler extends B
                     log.debug("Could not load JAXBContext for Context ClassLoader");
                 }
                 cl = classCL;
+            } else if (JAXBUtils.containsClasses(jbc_classCL, classRefs)) {
+                cl = classCL;
+            } else if (JAXBUtils.containsClasses(jbc_contextCL, classRefs)) {
+                cl = contextCL;
             } else if (holder_contextCL.value == JAXBUtils.CONSTRUCTION_TYPE.BY_CONTEXT_PATH
&&
                     holder_classCL.value == JAXBUtils.CONSTRUCTION_TYPE.BY_CONTEXT_PATH)
{
                 // Both were successfully built with the context path.
@@ -748,7 +756,7 @@ public class JAXWSProxyHandler extends B
         }
         return cl;
     }
-    
+        
     private static ClassLoader getContextClassLoader() {
         // NOTE: This method must remain private because it uses AccessController
         ClassLoader cl = null;

Modified: geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java?rev=1087589&r1=1087588&r2=1087589&view=diff
==============================================================================
--- geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
(original)
+++ geronimo/bundles/trunk/axis2/src/main/java/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
Fri Apr  1 05:47:52 2011
@@ -34,6 +34,7 @@ import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.JAXBIntrospector;
 import javax.xml.bind.Marshaller;
+import javax.xml.bind.PropertyException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.ws.Holder;
@@ -45,6 +46,7 @@ import java.io.UnsupportedEncodingExcept
 import java.lang.annotation.Annotation;
 import java.lang.ref.SoftReference;
 import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Array;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.security.PrivilegedActionException;
@@ -61,50 +63,50 @@ import java.util.concurrent.ConcurrentHa
 
 
 /**
- * JAXB Utilites to pool JAXBContext and related objects.
+ * JAXB Utilites to pool JAXBContext and related objects. 
  */
 public class JAXBUtils {
 
     private static final Log log = LogFactory.getLog(JAXBUtils.class);
 
-    // Create a concurrent map to get the JAXBObject:
+    // Create a concurrent map to get the JAXBObject: 
     //    key is the String (sorted packages)
     //    value is a SoftReference to a ConcurrentHashMap of Classloader keys and JAXBContextValue
objects
     //               It is a soft map to encourage GC in low memory situations
     private static Map<
-        String,
+        String, 
         SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>> jaxbMap
=
-            new ConcurrentHashMap<String,
+            new ConcurrentHashMap<String, 
                 SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>>();
 
     private static Pool<JAXBContext, Marshaller>       mpool = new Pool<JAXBContext,
Marshaller>();
     private static Pool<JAXBContext, Unmarshaller>     upool = new Pool<JAXBContext,
Unmarshaller>();
     private static Pool<JAXBContext, JAXBIntrospector> ipool = new Pool<JAXBContext,
JAXBIntrospector>();
-
+    
     // From Lizet Ernand:
-    // If you really care about the performance,
-    // and/or your application is going to read a lot of small documents,
-    // then creating Unmarshaller could be relatively an expensive operation.
+    // If you really care about the performance, 
+    // and/or your application is going to read a lot of small documents, 
+    // then creating Unmarshaller could be relatively an expensive operation. 
     // In that case, consider pooling Unmarshaller objects.
-    // Different threads may reuse one Unmarshaller instance,
-    // as long as you don't use one instance from two threads at the same time.
+    // Different threads may reuse one Unmarshaller instance, 
+    // as long as you don't use one instance from two threads at the same time. 
     // ENABLE_ADV_POOLING is false...which means they are obtained from the JAXBContext instead
of
     // from the pool.
     private static boolean ENABLE_MARSHALL_POOLING = true;
     private static boolean ENABLE_UNMARSHALL_POOLING = true;
     private static boolean ENABLE_INTROSPECTION_POOLING = false;
-
+    
     private static int MAX_LOAD_FACTOR = 32;  // Maximum number of JAXBContext to store
 
     // Construction Type
     public enum CONSTRUCTION_TYPE {
-        BY_CLASS_ARRAY,   // New Instance with Class[]
+        BY_CLASS_ARRAY,   // New Instance with Class[] 
         BY_CONTEXT_PATH,  // New Instance with context path string (preferred)
         BY_CLASS_ARRAY_PLUS_ARRAYS, // New Instance with Class[] plus arrays of each class
are added
         UNKNOWN}
 
     ;
-
+    
     // Some packages have a known set of classes.
     // This map is immutable after its static creation.
     private static final Map<String, List<Class>> specialMap = new HashMap<String,
List<Class>>();
@@ -114,9 +116,9 @@ public class JAXBUtils {
         classes.add(W3CEndpointReference.class);
         specialMap.put("javax.xml.ws.wsaddressing", classes);
     }
-
+    
     public static final String DEFAULT_NAMESPACE_REMAP = getDefaultNamespaceRemapProperty();
-
+    
     /**
      * Get a JAXBContext for the class
      *
@@ -126,13 +128,13 @@ public class JAXBUtils {
      * @deprecated
      */
     public static JAXBContext getJAXBContext(TreeSet<String> contextPackages) throws
JAXBException {
-        return getJAXBContext(contextPackages, new Holder<CONSTRUCTION_TYPE>(),
+        return getJAXBContext(contextPackages, new Holder<CONSTRUCTION_TYPE>(), 
                               contextPackages.toString(), null, null);
     }
 
     /**
      * Get a JAXBContext for the class
-     *
+     * 
      * Note: The contextPackage object is used by multiple threads.  It should be considered
immutable
      * and not altered by this method.
      *
@@ -142,13 +144,13 @@ public class JAXBUtils {
      * @throws JAXBException
      * @deprecated
      */
-    public static JAXBContext getJAXBContext(TreeSet<String> contextPackages, ClassLoader
+    public static JAXBContext getJAXBContext(TreeSet<String> contextPackages, ClassLoader

                                              cacheKey) throws JAXBException {
         return getJAXBContext(contextPackages, new Holder<CONSTRUCTION_TYPE>(),
                               contextPackages.toString(), cacheKey, null);
     }
-
-    public static JAXBContext getJAXBContext(TreeSet<String> contextPackages,
+    
+    public static JAXBContext getJAXBContext(TreeSet<String> contextPackages, 
                                              Holder<CONSTRUCTION_TYPE> constructionType,
                                              String key)
         throws JAXBException {
@@ -160,8 +162,8 @@ public class JAXBUtils {
      *
      * Note: The contextPackage object is used by multiple threads.  It should be considered
immutable
      * and not altered by this method.
-     *
-     * @param contextPackage  Set<Package>
+     * 
+     * @param contextPackage  Set<Package> 
      * @param contructionType (output value that indicates how the context was constructed)
      * @param cacheKey ClassLoader
      * @return JAXBContext
@@ -173,11 +175,11 @@ public class JAXBUtils {
                                              ClassLoader cacheKey,
                                              Map<String, ?> properties)
             throws JAXBException {
-        return getJAXBContext(contextPackages,
-                        constructionType,
-                        false,
-                        key,
-                        cacheKey,
+        return getJAXBContext(contextPackages, 
+                        constructionType, 
+                        false, 
+                        key, 
+                        cacheKey, 
                         properties);
     }
     /**
@@ -185,8 +187,8 @@ public class JAXBUtils {
      *
      * Note: The contextPackage object is used by multiple threads.  It should be considered
immutable
      * and not altered by this method.
-     *
-     * @param contextPackage  Set<Package>
+     * 
+     * @param contextPackage  Set<Package> 
      * @param contructionType (output value that indicates how the context was constructed)
      * @param forceArrays (forces the returned JAXBContext to include the array types)
      * @param cacheKey ClassLoader
@@ -194,11 +196,11 @@ public class JAXBUtils {
      * @throws JAXBException
      */
     public static JAXBContext getJAXBContext(TreeSet<String> contextPackages,
-                                             Holder<CONSTRUCTION_TYPE> constructionType,
+                                             Holder<CONSTRUCTION_TYPE> constructionType,

                                              boolean forceArrays,
                                              String key,
                                              ClassLoader cacheKey,
-                                             Map<String, ?> properties)
+                                             Map<String, ?> properties) 
         throws JAXBException {
         // JAXBContexts for the same class can be reused and are supposed to be thread-safe
         if (log.isDebugEnabled()) {
@@ -213,13 +215,13 @@ public class JAXBUtils {
 
         // Get or Create The InnerMap using the package key
         ConcurrentHashMap<ClassLoader, JAXBContextValue> innerMap = null;
-        SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>
+        SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>> 
             softRef = jaxbMap.get(key);
-
+        
         if (softRef != null) {
             innerMap = softRef.get();
         }
-
+        
         if (innerMap == null) {
             synchronized(jaxbMap) {
                 softRef = jaxbMap.get(key);
@@ -228,38 +230,38 @@ public class JAXBUtils {
                 }
                 if (innerMap == null) {
                     innerMap = new ConcurrentHashMap<ClassLoader, JAXBContextValue>();
-                    softRef =
+                    softRef = 
                         new SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>(innerMap);
                     jaxbMap.put(key, softRef);
                 }
             }
         }
-
-        // Now get the contextValue using either the classloader key or
+        
+        // Now get the contextValue using either the classloader key or 
         // the current Classloader
         ClassLoader cl = getContextClassLoader();
         JAXBContextValue contextValue = null;
         if(cacheKey != null) {
             if(log.isDebugEnabled()) {
-                log.debug("Using supplied classloader to retrieve JAXBContext: " +
+                log.debug("Using supplied classloader to retrieve JAXBContext: " + 
                           cacheKey);
             }
             contextValue = innerMap.get(cacheKey);
         } else {
             if(log.isDebugEnabled()) {
-                log.debug("Using classloader from Thread to retrieve JAXBContext: " +
+                log.debug("Using classloader from Thread to retrieve JAXBContext: " + 
                           cl);
             }
             contextValue = innerMap.get(cl);
         }
-
+      
         // If the context value is found, but the caller requested that the JAXBContext
         // contain arrays, then rebuild the JAXBContext value
         if (forceArrays &&
-            contextValue != null &&
+            contextValue != null && 
             contextValue.constructionType != JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY_PLUS_ARRAYS)
{
             if(log.isDebugEnabled()) {
-                log.debug("Found a JAXBContextValue with constructionType=" +
+                log.debug("Found a JAXBContextValue with constructionType=" + 
                             contextValue.constructionType + "  but the caller requested a
JAXBContext " +
                           " that includes arrays.  A new JAXBContext will be built");
             }
@@ -276,39 +278,39 @@ public class JAXBUtils {
                 contextValue = innerMap.get(clKey);
                 adjustPoolSize(innerMap);
                 if (forceArrays &&
-                        contextValue != null &&
+                        contextValue != null && 
                         contextValue.constructionType != JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY_PLUS_ARRAYS)
{
                     contextValue = null;
                 }
                 if (contextValue==null) {
                     // Create a copy of the contextPackages.  This new TreeSet will
                     // contain only the valid contextPackages.
-                    // Note: The original contextPackage set is accessed by multiple
+                    // Note: The original contextPackage set is accessed by multiple 
                     // threads and should not be altered.
 
-                    TreeSet<String> validContextPackages = new TreeSet<String>(contextPackages);
-
+                    TreeSet<String> validContextPackages = new TreeSet<String>(contextPackages);

+                    
                     List<String> classRefs = pruneDirectives(validContextPackages);
-
+                    
                     int numPackages = validContextPackages.size();
-
-                    contextValue = createJAXBContextValue(validContextPackages,
-                            clKey,
-                            forceArrays,
-                            properties,
+                    
+                    contextValue = createJAXBContextValue(validContextPackages, 
+                            clKey, 
+                            forceArrays, 
+                            properties, 
                             classRefs);
-
+                    
                     synchronized (jaxbMap) {
                         // Add the context value with the original package set
                         ConcurrentHashMap<ClassLoader, JAXBContextValue> map1 = null;
-                        SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>
+                        SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>

                         softRef1 = jaxbMap.get(key);
                         if (softRef1 != null) {
                             map1 = softRef1.get();
                         }
                         if (map1 == null) {
                             map1 = new ConcurrentHashMap<ClassLoader, JAXBContextValue>();
-                            softRef1 =
+                            softRef1 = 
                                 new SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>(map1);
                             jaxbMap.put(key, softRef1);
                         }
@@ -318,24 +320,24 @@ public class JAXBUtils {
 
                         // Add the context value with the new package set
                         ConcurrentHashMap<ClassLoader, JAXBContextValue> map2 = null;
-                        SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>
+                        SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>

                         softRef2 = jaxbMap.get(validPackagesKey);
                         if (softRef2 != null) {
                             map2 = softRef2.get();
                         }
                         if (map2 == null) {
                             map2 = new ConcurrentHashMap<ClassLoader, JAXBContextValue>();
-                            softRef2 =
+                            softRef2 = 
                                 new SoftReference<ConcurrentHashMap<ClassLoader, JAXBContextValue>>(map2);
                             jaxbMap.put(validPackagesKey, softRef2);
                         }
                         map2.put(clKey, contextValue);
-
+                        
                         if (log.isDebugEnabled()) {
                             log.debug("JAXBContext [created] for " + key);
                             log.debug("JAXBContext also stored by the list of valid packages:"
+ validPackagesKey);
                         }
-                    }
+                    }        
                 }
             }
         } else {
@@ -351,16 +353,16 @@ public class JAXBUtils {
         constructionType.value = contextValue.constructionType;
         return contextValue.jaxbContext;
     }
-
+    
     /**
-     * The contextPackages may declare overrides.
+     * The contextPackages may declare overrides.  
      * Example:
      *    "com.A"
      *    "com.B"
      *    "com.C"
      *    "@com.A"   <-- Indicates a reference to a class (versus ns 2 pkg conversion)
      *    "com.A > com.B"   <-- This says com.A overrides com.B
-     *
+     *    
      * This method prunes the overrides and overriden packages.
      * Example return:
      *    "com.A"
@@ -368,11 +370,11 @@ public class JAXBUtils {
      * @param contextPackages
      * @return List<String> class references
      */
-    protected static List<String> pruneDirectives(TreeSet<String> contextPackages)
{
+    public static List<String> pruneDirectives(TreeSet<String> contextPackages)
{
         List<String> removePkgsList = new ArrayList<String>();
         List<String> strongPkgsList = new ArrayList<String>();
         List<String> classRefs = new ArrayList<String>();
-
+        
         // Walk the contextPackages looking for entries representing directives
         Iterator<String> it = contextPackages.iterator();
         while (it.hasNext()) {
@@ -383,8 +385,8 @@ public class JAXBUtils {
                     log.debug("Override found:" + entry);
                 }
                 // Remove the entry using an iterator remove()
-                it.remove();
-
+                it.remove();  
+                
                 // Store the overridden package
                 String removePkg = entry.substring(entry.indexOf(">") + 1);
                 removePkg = removePkg.trim();
@@ -395,8 +397,8 @@ public class JAXBUtils {
                     log.debug("Strong (class) reference found:" + entry);
                 }
                 // Remove the entry using an iterator remove()
-                it.remove();
-
+                it.remove();  
+                
                 // Store the overridden package
                 String strongPkg = entry.substring(1);
                 strongPkg = strongPkg.trim();
@@ -407,14 +409,14 @@ public class JAXBUtils {
                     log.debug("Class Reference found:" + entry);
                 }
                 // Remove the entry using an iterator remove()
-                it.remove();
-
+                it.remove();  
+                
                 // Store the class
                 String cls = entry.substring(1, entry.length()-1);
                 classRefs.add(cls);
             }
         }
-
+        
         // Now walk the contextPackages and remove the overriden packages
         it = contextPackages.iterator();
         while (it.hasNext()) {
@@ -425,10 +427,10 @@ public class JAXBUtils {
                     log.debug("Removing override package:" + entry);
                 }
                 // Remove the overridden package using an iterator remove()
-                it.remove();
+                it.remove();  
             }
         }
-
+        
         // Now add back all of the strong packages
         contextPackages.addAll(strongPkgsList);
         return classRefs;
@@ -453,9 +455,9 @@ public class JAXBUtils {
 
         JAXBContextValue contextValue = null;
         if (log.isDebugEnabled()) {
-
+            
             log.debug("Following packages are in this batch of getJAXBContext() :");
-
+            
             for (String pkg : contextPackages) {
                 log.debug(pkg);
             }
@@ -494,14 +496,14 @@ public class JAXBUtils {
         //    all of the packages separated by colons.
         // 2) USE A CLASS[], which is an array of all of the classes
         //    involved in the marshal/unmarshal.
-        //
+        //   
         // There are pros/cons with both approaches.
-        // USE A CONTEXTPATH:
-        //    Pros: preferred way of doing this.
+        // USE A CONTEXTPATH: 
+        //    Pros: preferred way of doing this.  
         //          performant
         //          most dynamic
         //    Cons: Each package in context path must have an ObjectFactory
-        //
+        //        
         //
         // USE CLASS[]:
         //    Pros: Doesn't require ObjectFactory in each package
@@ -559,7 +561,7 @@ public class JAXBUtils {
             }
         }
 
-        // The code above may have removed some packages from the list.
+        // The code above may have removed some packages from the list. 
         // Retry our lookup with the updated list
         if (contextConstruction) {
             if (log.isDebugEnabled()) {
@@ -575,15 +577,15 @@ public class JAXBUtils {
             if (innerMap != null) {
                 contextValue = innerMap.get(cl);
                 if (forceArrays &&
-                        contextValue != null &&
+                        contextValue != null && 
                         contextValue.constructionType != JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY_PLUS_ARRAYS)
{
                     if(log.isDebugEnabled()) {
-                        log.debug("Found a JAXBContextValue with constructionType=" +
+                        log.debug("Found a JAXBContextValue with constructionType=" + 
                                 contextValue.constructionType + "  but the caller requested
a JAXBContext " +
                         " that includes arrays.  A new JAXBContext will be built");
                     }
                     contextValue = null;
-                }
+                } 
 
                 if (contextValue != null) {
                     if (log.isDebugEnabled()) {
@@ -632,10 +634,6 @@ public class JAXBUtils {
             }
             JAXBContext context = JAXBContext_newInstance(classArray, cl, properties, classRefs);
             if (context != null) {
-                List<String> unContainedClasses = getUnContainedClasses(context, classRefs);
-                if (unContainedClasses.size() > 0) {
-                    throw new JAXBException("Classes in the " + unContainedClasses +" could
not find in the built JAXBContext with classArrays");
-                }
                 if (forceArrays) {
                     contextValue = new JAXBContextValue(context, CONSTRUCTION_TYPE.BY_CLASS_ARRAY_PLUS_ARRAYS);
                 } else {
@@ -735,7 +733,7 @@ public class JAXBUtils {
      */
     public static Marshaller getJAXBMarshaller(JAXBContext context) throws JAXBException
{
         Marshaller m = null;
-
+        
         if (!ENABLE_MARSHALL_POOLING) {
             if (log.isDebugEnabled()) {
                 log.debug("Marshaller created [no pooling]");
@@ -759,7 +757,7 @@ public class JAXBUtils {
     }
 
     /**
-     * releaseJAXBMarshalller
+     * releaseJAXBMarshalller 
      * Do not call this method if an exception occurred while using the
      * Marshaller. We don't want an object in an invalid state.
      *
@@ -774,7 +772,7 @@ public class JAXBUtils {
         }
         if (ENABLE_MARSHALL_POOLING) {
             // Make sure to clear any state or properties
-
+            
             try {
                 marshaller.setAttachmentMarshaller(null);
                 // Set the JAXB_ENCODING back to the default value UTF-8
@@ -786,7 +784,7 @@ public class JAXBUtils {
                     log.debug("The following exception is ignored. Processing continues "
+ t);
                 }
             }
-
+            
         }
     }
 
@@ -877,7 +875,7 @@ public class JAXBUtils {
             Class cls = forName(p + ".package-info", false, cl);
             if (cls != null) {
                 return true;
-            }
+            }  
         } catch (Throwable e) {
             //Catch Throwable as ClassLoader can throw an NoClassDefFoundError that
             //does not extend Exception. So we will absorb any Throwable exception here.
@@ -918,8 +916,8 @@ public class JAXBUtils {
                 log.debug("Attempting to create JAXBContext with contextPath=" + contextpath);
             }
             context = JAXBContext_newInstance(contextpath, cl);
-
-            if (getUnContainedClasses(context, classRefs).size() > 0) {
+            
+            if (!containsClasses(context, classRefs)) {
                 if (log.isDebugEnabled()) {
                     log.debug("  Unsuccessful: Will now use an alterative JAXBConstruct construction");
                 }
@@ -937,13 +935,13 @@ public class JAXBUtils {
         }
         return context;
     }
-
+    
     /**
      * containsClasses
-     * @param JAXBContext
+     * @param JAXBContext 
      * @param List<String> classRefs
      */
-    private static List<String> getUnContainedClasses(JAXBContext context, List<String>
classRefs) {
+    public static boolean containsClasses(JAXBContext context, List<String> classRefs)
{
         String text = context.toString();
         text = text.replace('\n', ' ');
         text = text.replace('\t', ' ');
@@ -951,8 +949,7 @@ public class JAXBUtils {
         text = text.replace('<', ' ');
         text = text.replace('[', ' ');
         text = text.replace(']', ' ');
-
-        List<String> unContainedClasses = new ArrayList<String>();
+        
         for (String classRef: classRefs) {
             // Strip off generic and array chars
             int index = classRef.indexOf('<');
@@ -963,7 +960,7 @@ public class JAXBUtils {
             if (index > 0) {
                 classRef = classRef.substring(0, index);
             }
-
+            
             if (classRef.length() == 0 ||
                 classRef.endsWith(".ObjectFactory") ||
                 classRef.startsWith("java.util.") ||
@@ -971,15 +968,15 @@ public class JAXBUtils {
                 // skip these
             } else {
                 String search = " " + classRef + " ";
-                if (!text.contains(search)) {
+                if (!text.contains(search)) {               
                     if (log.isDebugEnabled()) {
                         log.debug("The context does not contain " + classRef + " " + context);
                     }
-                    unContainedClasses.add(classRef);
+                    return false;
                 }
             }
         }
-        return unContainedClasses;
+        return true;
     }
 
     /**
@@ -1000,7 +997,7 @@ public class JAXBUtils {
             }
             return new ArrayList<Class>();
         }
-
+        
         // See if this is a special package that has a set of known classes.
         List<Class> knownClasses = specialMap.get(pkg);
         if (knownClasses != null) {
@@ -1062,7 +1059,7 @@ public class JAXBUtils {
             log.debug("End: Obtain packages from ClassFinder plugin");
         }
         if (log.isDebugEnabled()) {
-
+            
             try {
                 log.debug("End: getAllClassesFromPackage for " + pkg + "with classes " +
classes);
             } catch (Throwable e) {
@@ -1072,18 +1069,18 @@ public class JAXBUtils {
         }
         return classes;
     }
-
+    
     /**
      * @param list
      * @param pkg
      */
     private static void checkClasses(List<Class> list, String pkg) {
-        // The installed classfinder or directory search may inadvertently add too many
+        // The installed classfinder or directory search may inadvertently add too many 
         // classes.  This rountine is a 'double check' to make sure that the classes
         // are acceptable.
         for (int i=0; i<list.size();) {
             Class cls = list.get(i);
-            if (!cls.isInterface() &&
+            if (!cls.isInterface() && 
                     (cls.isEnum() ||
                      getAnnotation(cls, XmlType.class) != null ||
                      ClassUtils.getDefaultPublicConstructor(cls) != null) &&
@@ -1147,15 +1144,15 @@ public class JAXBUtils {
                         try {
                             Class clazz = forName(className,
                                                   false, getContextClassLoader());
-                            // Don't add any interfaces or JAXWS specific classes.
-                            // Only classes that represent data and can be marshalled
+                            // Don't add any interfaces or JAXWS specific classes.  
+                            // Only classes that represent data and can be marshalled 
                             // by JAXB should be added.
                             if (!clazz.isInterface()
                                     && (clazz.isEnum() ||
                                         getAnnotation(clazz, XmlType.class) != null ||
                                         ClassUtils.getDefaultPublicConstructor(clazz) !=
null)
                                     && !ClassUtils.isJAXWSClass(clazz)
-                                    && !isSkipClass(clazz)
+                                    && !isSkipClass(clazz) 
                                     && !java.lang.Exception.class.isAssignableFrom(clazz))
{
 
                                 // Ensure that all the referenced classes are loadable too
@@ -1194,7 +1191,7 @@ public class JAXBUtils {
                 }
             }
         }
-
+        
         return classes;
     }
 
@@ -1218,7 +1215,7 @@ public class JAXBUtils {
             "javax.xml.namespace.QName[]" };
 
     private static void addCommonArrayClasses(List<Class> list) {
-
+        
         // Add common primitives arrays (necessary for RPC list type support)
         ClassLoader cl = getContextClassLoader();
 
@@ -1240,10 +1237,10 @@ public class JAXBUtils {
                 }
             }
         }
-
+        
     }
-
-
+    
+    
 
     /** @return ClassLoader */
     private static ClassLoader getContextClassLoader() {
@@ -1266,19 +1263,19 @@ public class JAXBUtils {
 
         return cl;
     }
-
-
+    
+    
     /**
      * @return true if clazz is a class that should be skipped (should not
      * be a considered for JAXB)
      */
     private static boolean isSkipClass(Class clazz) {
-
+       
         Class cls = clazz;
         while (cls != null) {
             // Check the name of the class to see if it should be excluded.
             String clsName = cls.getCanonicalName();
-            if (clsName != null &&
+            if (clsName != null && 
                     (clsName.equals("javax.ejb.SessionBean")  ||
                             clsName.equals("org.apache.axis2.jaxws.spi.JAXBExclude"))) {
                 if (log.isDebugEnabled()) {
@@ -1287,13 +1284,13 @@ public class JAXBUtils {
                 }
                 return true;
             }
-
+            
             // Check the interfaces of the class to see if it should be excluded
             Class[] intferfaces = getInterfaces_priv(cls);
             if (intferfaces != null) {
                 for (int i=0; i<intferfaces.length; i++) {
                     clsName = intferfaces[i].getCanonicalName();
-                    if (clsName != null &&
+                    if (clsName != null && 
                             (clsName.equals("javax.ejb.SessionBean")  ||
                                     clsName.equals("org.apache.axis2.jaxws.spi.JAXBExclude")))
{
                         if (log.isDebugEnabled()) {
@@ -1301,7 +1298,7 @@ public class JAXBUtils {
                             log.debug("  (It is skipped because the class implements " +
clsName);
                         }
                         return true;
-                    }
+                    } 
                 }
             }
             cls = cls.getSuperclass();  // Proceed up the hierarchy
@@ -1311,7 +1308,7 @@ public class JAXBUtils {
         }
         return false;
     }
-
+    
     private static Class[] getInterfaces_priv(final Class cls) {
         Class[] intferfaces = null;
         if (cls == null) {
@@ -1414,7 +1411,7 @@ public class JAXBUtils {
      * @return
      * @throws Exception
      */
-    private static JAXBContext JAXBContext_newInstance(final Class[] classArray,
+    private static JAXBContext JAXBContext_newInstance(final Class[] classArray, 
                                                        final ClassLoader cl,
                                                        Map<String, ?> properties,
                                                        List<String> classRefs)
@@ -1432,9 +1429,9 @@ public class JAXBUtils {
         }
 
         // Get JAXBContext from classes
-        jaxbContext = JAXBContextFromClasses.newInstance(classArray,
-                cl,
-                properties,
+        jaxbContext = JAXBContextFromClasses.newInstance(classArray, 
+                cl, 
+                properties, 
                 classRefs);
 
         return jaxbContext;
@@ -1451,7 +1448,7 @@ public class JAXBUtils {
             this.constructionType = constructionType;
         }
     }
-
+    
     static private void adjustPoolSize(Map map) {
         if (map.size() > MAX_LOAD_FACTOR) {
             // Remove every other Entry in the map.
@@ -1474,16 +1471,16 @@ public class JAXBUtils {
      * @param <V> Pooled object
      */
     private static class Pool<K,V> {
-        private SoftReference<Map<K,List<V>>> softMap =
+        private SoftReference<Map<K,List<V>>> softMap = 
             new SoftReference<Map<K,List<V>>>(
                     new ConcurrentHashMap<K, List<V>>());
 
         // The maps are freed up when a LOAD FACTOR is hit
         private static int MAX_LIST_FACTOR = 50;
-
+        
         // Limit the adjustSize calls
         private int count = 0;
-
+        
         /**
          * @param key
          * @return removed item from pool or null.
@@ -1494,7 +1491,7 @@ public class JAXBUtils {
                 if (values.size()>0) {
                     V v = values.remove(values.size()-1);
                     return v;
-
+                    
                 }
             }
             return null;
@@ -1536,7 +1533,7 @@ public class JAXBUtils {
                 if (values == null) {
                     if (map == null) {
                         map = new ConcurrentHashMap<K, List<V>>();
-                        softMap =
+                        softMap = 
                             new SoftReference<Map<K,List<V>>>(map);
                     }
                     values = new ArrayList<V>();
@@ -1546,17 +1543,17 @@ public class JAXBUtils {
                 return values;
             }
         }
-
+        
         /**
          * AdjustSize
          * When the number of keys exceeds the maximum load, half
          * of the entries are deleted.
-         *
+         * 
          * The assumption is that the JAXBContexts, UnMarshallers, Marshallers, etc. require
          * a large footprint.
          */
         private void adjustSize() {
-
+            
             // Don't check each time, map.size() can be expensive
             count++;
             if (count < 10) {
@@ -1586,15 +1583,15 @@ public class JAXBUtils {
             }
         });
     }
-
+    
     private static String getDefaultNamespaceRemapProperty() {
         String external = "com.sun.xml.bind.defaultNamespaceRemap";
         String internal = "com.sun.xml.internal.bind.defaultNamespaceRemap";
-
+        
         Boolean isExternal = testJAXBProperty(external);
         if (Boolean.TRUE.equals(isExternal)) {
             return external;
-        }
+        }                
         Boolean isInternal = testJAXBProperty(internal);
         if (Boolean.TRUE.equals(isInternal)) {
             return internal;
@@ -1602,7 +1599,7 @@ public class JAXBUtils {
         // hmm... both properties cannot be set
         return external;
     }
-
+    
     private static Boolean testJAXBProperty(String propName) {
         final Map<String, String> props = new HashMap<String, String>();
         props.put(propName, "http://test");
@@ -1617,7 +1614,7 @@ public class JAXBUtils {
         } catch (PrivilegedActionException e) {
             if (e.getCause() instanceof JAXBException) {
                 return Boolean.FALSE;
-            }
+            } 
             return null;
         }
     }



Mime
View raw message