You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by sc...@apache.org on 2010/08/28 16:55:23 UTC

svn commit: r990378 - /axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java

Author: scheu
Date: Sat Aug 28 14:55:23 2010
New Revision: 990378

URL: http://svn.apache.org/viewvc?rev=990378&view=rev
Log:
AXIS2-4803
Contributor:Rich Scheuerle
Changed JAXBUtils to verify that classes are present in the constructed JAXBContext.
If not, the code automatically falls back to the existing "load by classes" algorithm.

Modified:
    axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java

Modified: axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java?rev=990378&r1=990377&r2=990378&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java Sat Aug 28 14:55:23 2010
@@ -606,7 +606,7 @@ public class JAXBUtils {
 
         // CONTEXT construction
         if (contextConstruction) {
-            JAXBContext context = createJAXBContextUsingContextPath(contextPackages, cl);
+            JAXBContext context = createJAXBContextUsingContextPath(contextPackages, cl, classRefs);
             if (context != null) {
                 contextValue = new JAXBContextValue(context, CONSTRUCTION_TYPE.BY_CONTEXT_PATH);
             }
@@ -885,10 +885,12 @@ public class JAXBUtils {
      *
      * @param packages
      * @param cl       ClassLoader
+     * @param List<String> classRefs
      * @return JAXBContext or null if unsuccessful
      */
     private static JAXBContext createJAXBContextUsingContextPath(TreeSet<String> packages,
-                                                                 ClassLoader cl) {
+                                                                 ClassLoader cl,
+                                                                 List<String> classRefs) {
         JAXBContext context = null;
         String contextpath = "";
 
@@ -907,6 +909,13 @@ public class JAXBUtils {
                 log.debug("Attempting to create JAXBContext with contextPath=" + contextpath);
             }
             context = JAXBContext_newInstance(contextpath, cl);
+            
+            if (!containsClasses(context, classRefs)) {
+                if (log.isDebugEnabled()) {
+                    log.debug("  Unsuccessful: Will now use an alterative JAXBConstruct construction");
+                    return null;
+                }
+            }
             if (log.isDebugEnabled()) {
                 log.debug("  Successfully created JAXBContext:" + context);
             }
@@ -919,6 +928,32 @@ public class JAXBUtils {
         }
         return context;
     }
+    
+    /**
+     * containsClasses
+     * @param JAXBContext 
+     * @param List<String> classRefs
+     */
+    private static boolean containsClasses(JAXBContext context, List<String> classRefs) {
+        String text = context.toString();
+        
+        text = text.replace('\n', ' ');
+        text = text.replace('\t', ' ');
+        text = text.replace('\r', ' ');
+        
+        for (String classRef: classRefs) {
+            if (!classRef.endsWith(".ObjectFactory")) {
+                String search = " " + classRef + " ";
+                if (text.contains(search)) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("The context does not contain " + classRef + " " + context);
+                    }
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
 
     /**
      * This method will return all the Class names needed to construct a JAXBContext