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 ve...@apache.org on 2012/02/29 21:37:59 UTC

svn commit: r1295256 - in /axis/axis1/java/trunk: axis-ant/src/main/java/org/apache/axis/tools/ant/wsdl/ axis/src/main/java/org/apache/axis/providers/ axis/src/main/java/org/apache/axis/utils/ axis/src/main/java/org/apache/axis/wsdl/ axis/src/main/java...

Author: veithen
Date: Wed Feb 29 20:37:59 2012
New Revision: 1295256

URL: http://svn.apache.org/viewvc?rev=1295256&view=rev
Log:
Eliminated the static class name -> class loader map in ClassUtils and use class loaders (and Class objects) as they are intended to be used.

Modified:
    axis/axis1/java/trunk/axis-ant/src/main/java/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java
    axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/providers/BasicProvider.java
    axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/ClassUtils.java
    axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/wsdl/Java2WSDL.java
    axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/wsdl/fromJava/Emitter.java
    axis/axis1/java/trunk/axis/src/main/resources/org/apache/axis/i18n/resource.properties
    axis/axis1/java/trunk/maven/maven-java2wsdl-plugin/src/main/java/org/apache/axis/maven/java2wsdl/AbstractGenerateWsdlMojo.java

Modified: axis/axis1/java/trunk/axis-ant/src/main/java/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-ant/src/main/java/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java?rev=1295256&r1=1295255&r2=1295256&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis-ant/src/main/java/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java (original)
+++ axis/axis1/java/trunk/axis-ant/src/main/java/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java Wed Feb 29 20:37:59 2012
@@ -18,7 +18,6 @@ package org.apache.axis.tools.ant.wsdl;
 import org.apache.axis.encoding.TypeMappingImpl;
 import org.apache.axis.encoding.TypeMappingRegistryImpl;
 import org.apache.axis.encoding.TypeMappingDelegate;
-import org.apache.axis.utils.ClassUtils;
 import org.apache.axis.wsdl.fromJava.Emitter;
 import org.apache.tools.ant.AntClassLoader;
 import org.apache.tools.ant.BuildException;
@@ -37,7 +36,6 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.StringTokenizer;
 
 /*
  * Important. we autogenerate the ant task docs from this.
@@ -149,16 +147,6 @@ public class Java2WsdlAntTask extends Ta
                 classpath == null ? createClasspath() : classpath,
                 false);
         
-        ClassUtils.setDefaultClassLoader(cl);
-        //add extra classes to the classpath when the classpath attr is not null
-        if (extraClasses != null) {
-            StringTokenizer tokenizer = new StringTokenizer(extraClasses, " ,");
-            while (tokenizer.hasMoreTokens()) {
-                String clsName = tokenizer.nextToken();
-                ClassUtils.setClassLoader(clsName, cl);
-            }
-        }
-
         CommandlineJava.SysProperties sysProperties =
                 commandline.getSystemProperties();
         if (sysProperties != null) {
@@ -185,9 +173,9 @@ public class Java2WsdlAntTask extends Ta
                 emitter.setBindingName(bindingName);
             }
             log("Java2WSDL " + className, Project.MSG_INFO);
-            emitter.setCls(className);
+            emitter.setCls(cl.loadClass(className));
             if (implClass != null) {
-                emitter.setImplCls(implClass);
+                emitter.setImplCls(cl.loadClass(implClass));
             }
             if (exclude != null) {
                 emitter.setDisallowedMethods(exclude);
@@ -196,7 +184,7 @@ public class Java2WsdlAntTask extends Ta
                 emitter.setStopClasses(stopClasses);
             }
             if (extraClasses != null) {
-                emitter.setExtraClasses(extraClasses);
+                emitter.setExtraClasses(extraClasses, cl);
             }
 
             TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();

Modified: axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/providers/BasicProvider.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/providers/BasicProvider.java?rev=1295256&r1=1295255&r2=1295256&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/providers/BasicProvider.java (original)
+++ axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/providers/BasicProvider.java Wed Feb 29 20:37:59 2012
@@ -232,7 +232,7 @@ public abstract class BasicProvider exte
             }
 
             if (extraClasses != null && extraClasses.length() > 0) {
-                emitter.setExtraClasses(extraClasses);
+                emitter.setExtraClasses(extraClasses, msgContext.getClassLoader());
             }
 
             if (msgContext.isPropertyTrue(AxisEngine.PROP_EMIT_ALL_TYPES)) {

Modified: axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/ClassUtils.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/ClassUtils.java?rev=1295256&r1=1295255&r2=1295256&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/ClassUtils.java (original)
+++ axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/utils/ClassUtils.java Wed Feb 29 20:37:59 2012
@@ -34,9 +34,6 @@ public final class ClassUtils {
     private static ClassLoader defaultClassLoader
             = ClassUtils.class.getClassLoader();
 
-    /** hash table of class loaders */
-    private static java.util.Hashtable classloaders = new java.util.Hashtable();
-
     /**
      * Set the default ClassLoader. If loader is null, the default loader is
      * not changed.
@@ -53,42 +50,6 @@ public final class ClassUtils {
     }
 
     /**
-     * Set the ClassLoader associated with the given className. If either the
-     * class name or the loader are null, no action is performed.
-     *
-     * @param className the name of a class
-     * @param loader the ClassLoader for the class
-     */
-    public static void setClassLoader(String className, ClassLoader loader) {
-        if (className != null && loader != null)
-            classloaders.put(className, loader);
-    }
-
-    /**
-     * Obtain the ClassLoader (if any) associated with the given
-     * className.
-     *
-     * @param className the name of a class
-     * @return class loader
-     */
-    public static ClassLoader getClassLoader(String className) {
-        if (className == null) {
-            return null;
-        }
-        return (ClassLoader) classloaders.get(className);
-    }
-
-    /**
-     * Deregister the ClassLoader for a given className.
-     *
-     * @param className the name of a class
-     */
-    public static void removeClassLoader(String className) {
-        classloaders.remove(className);
-    }
-
-
-    /**
      * Use this method instead of Class.forName
      *
      * @param className Class name
@@ -162,15 +123,6 @@ public final class ClassUtils {
                     new PrivilegedAction() {
                         public Object run() {
                             try {
-                                // Check if the class is a registered class then
-                                // use the classloader for that class.
-                                ClassLoader classLoader = getClassLoader(className);
-                                return Class.forName(className, true, classLoader);
-                            } catch (ClassNotFoundException cnfe) {
-                            } catch (SecurityException cnfe) {
-                            }
-                            
-                            try {
                                 // Try the context class loader
                                 ClassLoader classLoader =
                                     Thread.currentThread().getContextClassLoader();

Modified: axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/wsdl/Java2WSDL.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/wsdl/Java2WSDL.java?rev=1295256&r1=1295255&r2=1295256&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/wsdl/Java2WSDL.java (original)
+++ axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/wsdl/Java2WSDL.java Wed Feb 29 20:37:59 2012
@@ -264,6 +264,11 @@ public class Java2WSDL {
     protected boolean isDeploy = false;
     
     /**
+     * The class loader to use to load classes specified on the command line.
+     */
+    private ClassLoader classLoader = Java2WSDL.class.getClassLoader();
+    
+    /**
      * Instantiate a Java2WSDL emitter.
      */
     protected Java2WSDL() {
@@ -336,7 +341,14 @@ public class Java2WSDL {
                 break;
 
             case IMPL_CLASS_OPT:
-                emitter.setImplCls(option.getArgument());
+                try {
+                    emitter.setImplCls(classLoader.loadClass(option.getArgument()));
+                } catch (ClassNotFoundException e) {
+                    System.out.println(Messages.getMessage("j2woptBadClass01",
+                            e.toString()));
+
+                    status = false;
+                }
                 break;
 
             case HELP_OPT:
@@ -474,7 +486,7 @@ public class Java2WSDL {
 
             case EXTRA_CLASSES_OPT:
                 try {
-                    emitter.setExtraClasses(option.getArgument());
+                    emitter.setExtraClasses(option.getArgument(), classLoader);
                 } catch (ClassNotFoundException e) {
                     System.out.println(Messages.getMessage("j2woptBadClass00",
                             e.toString()));
@@ -488,9 +500,9 @@ public class Java2WSDL {
                 break;
 
             case CLASSPATH_OPT:
-                ClassUtils.setDefaultClassLoader(ClassUtils.createClassLoader(
+                classLoader = ClassUtils.createClassLoader(
                         option.getArgument(),
-                        this.getClass().getClassLoader()));
+                        this.getClass().getClassLoader());
                 break;
                 
             case DEPLOY_OPT:
@@ -581,7 +593,7 @@ public class Java2WSDL {
             emitter.setTypeMappingRegistry(tmr);
 
             // Find the class using the name
-            emitter.setCls(className);
+            emitter.setCls(classLoader.loadClass(className));
 
             // Generate a full wsdl, or interface & implementation wsdls
             if (wsdlImplFilename == null) {

Modified: axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/wsdl/fromJava/Emitter.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/wsdl/fromJava/Emitter.java?rev=1295256&r1=1295255&r2=1295256&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/wsdl/fromJava/Emitter.java (original)
+++ axis/axis1/java/trunk/axis/src/main/java/org/apache/axis/wsdl/fromJava/Emitter.java Wed Feb 29 20:37:59 2012
@@ -35,7 +35,6 @@ import org.apache.axis.description.Servi
 import org.apache.axis.encoding.TypeMapping;
 import org.apache.axis.encoding.TypeMappingRegistry;
 import org.apache.axis.encoding.TypeMappingRegistryImpl;
-import org.apache.axis.utils.ClassUtils;
 import org.apache.axis.utils.JavaUtils;
 import org.apache.axis.utils.Messages;
 import org.apache.axis.utils.XMLUtils;
@@ -2070,16 +2069,6 @@ public class Emitter {
     }
 
     /**
-     * Sets the <code>Class</code> to export
-     * 
-     * @param className the name of the <code>Class</code> to export
-     * @throws ClassNotFoundException 
-     */
-    public void setCls(String className) throws ClassNotFoundException {
-        cls = ClassUtils.forName(className);
-    }
-
-    /**
      * Returns the implementation <code>Class</code> if set
      * 
      * @return the implementation Class or null
@@ -2098,20 +2087,6 @@ public class Emitter {
     }
 
     /**
-     * Sets the implementation <code>Class</code>
-     * 
-     * @param className the name of the implementation <code>Class</code>
-     */
-    public void setImplCls(String className) {
-
-        try {
-            implCls = ClassUtils.forName(className);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-        }
-    }
-
-    /**
      * Returns the interface namespace
      * 
      * @return interface target namespace
@@ -2706,14 +2681,17 @@ public class Emitter {
     }
 
     /**
-     * Provide a comma or space seperated list of classes which
-     * the emitter will produce WSDL type definitions for.
-     * The classes will be added to the current list.
-     * 
-     * @param text 
-     * @throws ClassNotFoundException 
+     * Convenience method that processes a comma or space separated list of classes which the
+     * emitter will produce WSDL type definitions for. The classes will be added to the current
+     * list.
+     * 
+     * @param text
+     *            a comma or space separated list of class names
+     * @param classLoader
+     *            the class loader that should be used to load the classes
+     * @throws ClassNotFoundException
      */
-    public void setExtraClasses(String text) throws ClassNotFoundException {
+    public void setExtraClasses(String text, ClassLoader classLoader) throws ClassNotFoundException {
 
         ArrayList clsList = new ArrayList();
 
@@ -2724,7 +2702,7 @@ public class Emitter {
                 String clsName = tokenizer.nextToken();
 
                 // Let the caller handler ClassNotFoundException
-                Class cls = ClassUtils.forName(clsName);
+                Class cls = classLoader.loadClass(clsName);
 
                 clsList.add(cls);
             }

Modified: axis/axis1/java/trunk/axis/src/main/resources/org/apache/axis/i18n/resource.properties
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis/src/main/resources/org/apache/axis/i18n/resource.properties?rev=1295256&r1=1295255&r2=1295256&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis/src/main/resources/org/apache/axis/i18n/resource.properties (original)
+++ axis/axis1/java/trunk/axis/src/main/resources/org/apache/axis/i18n/resource.properties Wed Feb 29 20:37:59 2012
@@ -925,6 +925,7 @@ j2woptUse00=The use of items in the bind
 j2woptBadUse00=The value of the use option must be LITERAL or ENCODED
 j2woptExtraClasses00=A space or comma separated list of class names to be added to the type section.
 j2woptBadClass00=Invalid class provided for --extraClasses option: {0}
+j2woptBadClass01=Invalid class provided for -i option: {0}
 operationAlreadySet=Can''t modify settings on a Call whose OperationDesc was set by setOperation()
 
 illegalStateException00=IllegalStateException:

Modified: axis/axis1/java/trunk/maven/maven-java2wsdl-plugin/src/main/java/org/apache/axis/maven/java2wsdl/AbstractGenerateWsdlMojo.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/maven/maven-java2wsdl-plugin/src/main/java/org/apache/axis/maven/java2wsdl/AbstractGenerateWsdlMojo.java?rev=1295256&r1=1295255&r2=1295256&view=diff
==============================================================================
--- axis/axis1/java/trunk/maven/maven-java2wsdl-plugin/src/main/java/org/apache/axis/maven/java2wsdl/AbstractGenerateWsdlMojo.java (original)
+++ axis/axis1/java/trunk/maven/maven-java2wsdl-plugin/src/main/java/org/apache/axis/maven/java2wsdl/AbstractGenerateWsdlMojo.java Wed Feb 29 20:37:59 2012
@@ -26,14 +26,12 @@ import java.util.List;
 
 import org.apache.axis.maven.shared.nsmap.Mapping;
 import org.apache.axis.maven.shared.nsmap.MappingUtil;
-import org.apache.axis.utils.ClassUtils;
 import org.apache.axis.wsdl.fromJava.Emitter;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.StringUtils;
 
 import com.github.veithen.ulog.PlexusLoggerInjector;
 
@@ -140,49 +138,41 @@ public abstract class AbstractGenerateWs
             }
         }
         ClassLoader cl = new URLClassLoader(urls);
-        // TODO: this will likely make the plugin non thread safe
-        ClassUtils.setDefaultClassLoader(cl);
-        if (extraClasses != null) {
-            for (int i=0; i<extraClasses.length; i++) {
-                ClassUtils.setClassLoader(extraClasses[i], cl);
-            }
+        Emitter emitter = new Emitter();
+        if (mappings != null && mappings.length > 0) {
+            emitter.setNamespaceMap(MappingUtil.getPackageToNamespaceMap(mappings));
         }
         try {
-            Emitter emitter = new Emitter();
-            if (mappings != null && mappings.length > 0) {
-                emitter.setNamespaceMap(MappingUtil.getPackageToNamespaceMap(mappings));
-            }
-            try {
-                emitter.setCls(className);
-            } catch (ClassNotFoundException ex) {
-                throw new MojoFailureException("Class " + className + " not found");
-            }
-            if (extraClasses != null) {
+            emitter.setCls(cl.loadClass(className));
+        } catch (ClassNotFoundException ex) {
+            throw new MojoFailureException("Class " + className + " not found");
+        }
+        if (extraClasses != null) {
+            Class[] loadedExtraClasses = new Class[extraClasses.length];
+            for (int i=0; i<extraClasses.length; i++) {
                 try {
-                    emitter.setExtraClasses(StringUtils.join(extraClasses, ","));
+                    loadedExtraClasses[i] = cl.loadClass(extraClasses[i]);
                 } catch (ClassNotFoundException ex) {
-                    throw new MojoExecutionException("Extra class not found: " + ex.getMessage());
+                    throw new MojoExecutionException("Extra class not found: " + extraClasses[i]);
                 }
             }
-            if (style != null) {
-                emitter.setStyle(style);
-            }
-            if (use != null) {
-                emitter.setUse(use);
-            }
-            emitter.setIntfNamespace(namespace);
-            emitter.setLocationUrl(location);
-            output.getParentFile().mkdirs();
-            try {
-                emitter.emit(output.getAbsolutePath(), Emitter.MODE_ALL);
-            } catch (Exception ex) {
-                throw new MojoFailureException("java2wsdl failed", ex);
-            }
-            postProcess(emitter, output);
-        } finally {
-            // TODO: apparently this is a no-op
-            ClassUtils.setDefaultClassLoader(null);
+            emitter.setExtraClasses(loadedExtraClasses);
+        }
+        if (style != null) {
+            emitter.setStyle(style);
+        }
+        if (use != null) {
+            emitter.setUse(use);
+        }
+        emitter.setIntfNamespace(namespace);
+        emitter.setLocationUrl(location);
+        output.getParentFile().mkdirs();
+        try {
+            emitter.emit(output.getAbsolutePath(), Emitter.MODE_ALL);
+        } catch (Exception ex) {
+            throw new MojoFailureException("java2wsdl failed", ex);
         }
+        postProcess(emitter, output);
     }
 
     protected abstract void postProcess(Emitter emitter, File wsdlFile) throws MojoExecutionException, MojoFailureException;