axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/i18n resource.properties
Date Sun, 30 Nov 2003 05:42:24 GMT
dims        2003/11/29 21:42:24

  Modified:    java/src/org/apache/axis/utils ClassUtils.java
               java/src/org/apache/axis/wsdl Java2WSDL.java WSDL2Java.java
               java/tools/org/apache/axis/tools/ant/wsdl
                        Java2WsdlAntTask.java Wsdl2javaAntTask.java
               java/src/org/apache/axis/i18n resource.properties
  Log:
  Fix for Bug 21950 - classpath parameter for Java2WSDL Ant task
  from matthew_pocock@yahoo.co.uk
  
  Revision  Changes    Path
  1.8       +65 -3     ws-axis/java/src/org/apache/axis/utils/ClassUtils.java
  
  Index: ClassUtils.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/utils/ClassUtils.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ClassUtils.java	15 Aug 2003 06:24:01 -0000	1.7
  +++ ClassUtils.java	30 Nov 2003 05:42:24 -0000	1.8
  @@ -55,6 +55,10 @@
   package org.apache.axis.utils;
   
   import java.io.InputStream;
  +import java.io.File;
  +import java.net.MalformedURLException;
  +import java.net.URL;
  +import java.net.URLClassLoader;
   import java.security.AccessController;
   import java.security.PrivilegedAction;
   
  @@ -62,16 +66,37 @@
    * Utility methods for Class Loading.
    *
    * @author Davanum Srinvas (dims@yahoo.com)
  + * @author Matthew Pocock (matthew_pocock@yahoo.co.uk)
    */
   public final class ClassUtils {
  +    /** default class loader */
  +    private static ClassLoader defaultClassLoader
  +            = ClassUtils.class.getClassLoader();
   
       /** hash table of class loaders */
       private static java.util.Hashtable classloaders = new java.util.Hashtable();
   
       /**
  -     * Set the ClassLoader associated with the given className.
  +     * Set the default ClassLoader. If loader is null, the default loader is
  +     * not changed.
  +     *
  +     * @param loader  the new default ClassLoader
  +     */
  +    public static void setDefaultClassLoader(ClassLoader loader) {
  +      if (loader != null)
  +          defaultClassLoader = loader;
  +    }
  +
  +    public static ClassLoader getDefaultClassLoader() {
  +        return defaultClassLoader;
  +    }
  +
  +    /**
  +     * 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)
  @@ -158,7 +183,8 @@
       }
   
       /**
  -     * Loads the class from the context class loader and then falls back to Class.forName
  +     * Loads the class from the context class loader and then falls back to
  +     * getDefaultClassLoader().forName
        *
        * @param _className Class name
        * @return java class
  @@ -196,7 +222,8 @@
                                   } catch (ClassNotFoundException cnfe3) {
                                       // Try the default class loader.
                                       try {
  -                                        return Class.forName(className);
  +                                        return defaultClassLoader.loadClass(
  +                                                className);
                                       } catch (Throwable e) {
                                           // Still not found, return exception
                                           return e;
  @@ -244,5 +271,40 @@
               myInputStream = clazz.getResourceAsStream(resource);
           }
           return myInputStream;
  +    }
  +
  +    /**
  +     * Creates a new ClassLoader from a classpath specification and a parent
  +     * class loader.
  +     * The classpath string will be split using the system path seperator
  +     * character (e.g. : or ;), just as the java system-wide class path is
  +     * processed.
  +     *
  +     * @param classpath  the classpath String
  +     * @param parent  the parent ClassLoader, or null if the default is to be
  +     *     used
  +     * @throws SecurityExcepiton if you don't have privilages to create
  +     *         class loaders
  +     * @throws IllegalArgumentException if your classpath string is silly
  +     */
  +    public static ClassLoader createClassLoader(String classpath,
  +                                                ClassLoader parent)
  +            throws SecurityException
  +    {
  +        String[] names = classpath.split(System.getProperty("path.seperator"));
  +
  +        URL[] urls = new URL[names.length];
  +        try {
  +            for(int i = 0; i < urls.length; i++)
  +                urls[i] = new File(names[i]).toURL();
  +        }
  +        catch (MalformedURLException e) {
  +          // I don't think this is possible, so I'm throwing this as an
  +          // un-checked exception
  +          throw (IllegalArgumentException) new IllegalArgumentException(
  +                  "Unable to parse classpath: " + classpath).initCause(e);
  +        }
  +
  +        return new URLClassLoader(urls, parent);
       }
   }
  
  
  
  1.41      +14 -1     ws-axis/java/src/org/apache/axis/wsdl/Java2WSDL.java
  
  Index: Java2WSDL.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/Java2WSDL.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- Java2WSDL.java	29 Oct 2003 20:46:23 -0000	1.40
  +++ Java2WSDL.java	30 Nov 2003 05:42:24 -0000	1.41
  @@ -61,6 +61,7 @@
   import org.apache.axis.utils.CLOptionDescriptor;
   import org.apache.axis.utils.CLUtil;
   import org.apache.axis.utils.Messages;
  +import org.apache.axis.utils.ClassUtils;
   import org.apache.axis.wsdl.fromJava.Emitter;
   
   import java.util.HashMap;
  @@ -148,6 +149,8 @@
       /** Field METHODS_NOTALLOWED_OPT */
       protected static final int METHODS_NOTALLOWED_OPT = 'x';
   
  +    protected static final int CLASSPATH_OPT = 'X';
  +
       /** Field STYLE_OPT */
       protected static final int STYLE_OPT = 'y';
   
  @@ -255,7 +258,11 @@
           new CLOptionDescriptor("importSchema",
                   CLOptionDescriptor.ARGUMENT_OPTIONAL,
                   IMPORT_SCHEMA_OPT,
  -                Messages.getMessage("j2woptImportSchema00"))
  +                Messages.getMessage("j2woptImportSchema00")),
  +        new CLOptionDescriptor("classpath",
  +                CLOptionDescriptor.ARGUMENT_OPTIONAL,
  +                CLASSPATH_OPT,
  +                Messages.getMessage("optionClasspath"))
       };
   
       /** Field emitter */
  @@ -513,6 +520,12 @@
   
               case IMPORT_SCHEMA_OPT:
                   emitter.setInputSchema(option.getArgument());
  +                break;
  +
  +            case CLASSPATH_OPT:
  +                ClassUtils.setDefaultClassLoader(ClassUtils.createClassLoader(
  +                        option.getArgument(),
  +                        this.getClass().getClassLoader()));
                   break;
   
               default :
  
  
  
  1.43      +16 -2     ws-axis/java/src/org/apache/axis/wsdl/WSDL2Java.java
  
  Index: WSDL2Java.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/WSDL2Java.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- WSDL2Java.java	29 Oct 2003 20:46:23 -0000	1.42
  +++ WSDL2Java.java	30 Nov 2003 05:42:24 -0000	1.43
  @@ -55,6 +55,7 @@
   package org.apache.axis.wsdl;
   
   import org.apache.axis.enum.Scope;
  +import org.apache.axis.utils.ClassUtils;
   import org.apache.axis.utils.CLOption;
   import org.apache.axis.utils.CLOptionDescriptor;
   import org.apache.axis.utils.JavaUtils;
  @@ -112,6 +113,8 @@
       /** Field PASSWORD_OPT */
       protected static final int PASSWORD_OPT = 'P';
   
  +    protected static final int CLASSPATH_OPT = 'X';
  +
       /** Field bPackageOpt */
       protected boolean bPackageOpt = false;
   
  @@ -127,6 +130,7 @@
        * recognised.
        * - A description of the option for the usage message
        */
  +
       protected static final CLOptionDescriptor[] options =
               new CLOptionDescriptor[]{
                   new CLOptionDescriptor("server-side",
  @@ -138,7 +142,7 @@
                           Messages.getMessage("optionSkeletonDeploy00")),
                   new CLOptionDescriptor("NStoPkg",
                           CLOptionDescriptor.DUPLICATES_ALLOWED
  -            + CLOptionDescriptor.ARGUMENTS_REQUIRED_2,
  +                        + CLOptionDescriptor.ARGUMENTS_REQUIRED_2,
                           NAMESPACE_OPT,
                           Messages.getMessage("optionNStoPkg00")),
                   new CLOptionDescriptor("fileNStoPkg",
  @@ -176,7 +180,11 @@
                   new CLOptionDescriptor("password",
                           CLOptionDescriptor.ARGUMENT_REQUIRED,
                           PASSWORD_OPT,
  -                        Messages.getMessage("optionPassword"))
  +                        Messages.getMessage("optionPassword")),
  +                new CLOptionDescriptor("classpath",
  +                        CLOptionDescriptor.ARGUMENT_OPTIONAL,
  +                        CLASSPATH_OPT,
  +                        Messages.getMessage("optionClasspath"))
               };
   
       /**
  @@ -288,6 +296,12 @@
   
               case PASSWORD_OPT:
                   emitter.setPassword(option.getArgument());
  +                break;
  +
  +            case CLASSPATH_OPT:
  +                ClassUtils.setDefaultClassLoader(ClassUtils.createClassLoader(
  +                        option.getArgument(),
  +                        this.getClass().getClassLoader()));
                   break;
   
               default :
  
  
  
  1.18      +8 -4      ws-axis/java/tools/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java
  
  Index: Java2WsdlAntTask.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/tools/org/apache/axis/tools/ant/wsdl/Java2WsdlAntTask.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Java2WsdlAntTask.java	30 Nov 2003 05:03:45 -0000	1.17
  +++ Java2WsdlAntTask.java	30 Nov 2003 05:42:24 -0000	1.18
  @@ -156,6 +156,7 @@
           log("\tmethods:" + methods, logLevel);
           log("\textraClasses:" + extraClasses, logLevel);
           log("\tsoapAction:" + soapAction, logLevel);
  +        log("\t:classpath" + classpath, logLevel);
         
   }
   
  @@ -179,11 +180,14 @@
        */
       public void execute() throws BuildException {
           if (classpath != null) {
  -            AntClassLoader cl = new AntClassLoader(null, project, classpath, false);
  +            AntClassLoader cl = new AntClassLoader(
  +                    getClass().getClassLoader(),
  +                    project,
  +                    classpath,
  +                    false);
               log("Using CLASSPATH " + cl.getClasspath(),
  -              Project.MSG_VERBOSE);
  -            ClassUtils.setClassLoader(className, cl);
  -            ClassUtils.setClassLoader(implClass, cl);
  +                    Project.MSG_VERBOSE);
  +            ClassUtils.setDefaultClassLoader(cl);
               //add extra classes to the classpath when the classpath attr is not null
               //??why do we do this? Why don't we do this when the classpath is unset?
               if(extraClasses!=null) {
  
  
  
  1.13      +27 -1     ws-axis/java/tools/org/apache/axis/tools/ant/wsdl/Wsdl2javaAntTask.java
  
  Index: Wsdl2javaAntTask.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/tools/org/apache/axis/tools/ant/wsdl/Wsdl2javaAntTask.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Wsdl2javaAntTask.java	20 Nov 2003 06:42:13 -0000	1.12
  +++ Wsdl2javaAntTask.java	30 Nov 2003 05:42:24 -0000	1.13
  @@ -60,10 +60,13 @@
   
   import org.apache.axis.enum.Scope;
   import org.apache.axis.utils.DefaultAuthenticator;
  +import org.apache.axis.utils.ClassUtils;
   import org.apache.axis.wsdl.toJava.Emitter;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
  +import org.apache.tools.ant.AntClassLoader;
  +import org.apache.tools.ant.types.Path;
   
   /*
    * IMPORTANT: see Java2WsdlAntTask on how to javadoc this task and rebuild
  @@ -128,6 +131,7 @@
       private MappingSet mappings = new MappingSet();
       private String username=null;
       private String password=null;
  +    private Path classpath=null;
   
       /**
        * do we print a stack trace when something goes wrong?
  @@ -190,6 +194,7 @@
           log("\tusername:" + username, logLevel);
           log("\t:password" + password, logLevel);
           log("\t:noWrapped" + noWrapped, logLevel);
  +        log("\t:classpath" + classpath, logLevel);
           traceNetworkSettings(logLevel);
       }
   
  @@ -243,7 +248,17 @@
               emitter.setTimeout(timeout);
   
               Authenticator.setDefault(new DefaultAuthenticator(username,password));
  -
  +            if (classpath != null) {
  +                AntClassLoader cl = new AntClassLoader(
  +                        getClass().getClassLoader(),
  +                        project,
  +                        classpath,
  +                        false);
  +                log("Using CLASSPATH " + cl.getClasspath(),
  +                        Project.MSG_VERBOSE);
  +                ClassUtils.setDefaultClassLoader(cl);
  +            }
  +            
               log("WSDL2Java " + url, Project.MSG_INFO);
               try {
                   emitter.run(url);
  @@ -497,6 +512,17 @@
        */ 
       public void setNoWrapped(boolean noWrapped) {
         this.noWrapped = noWrapped;
  +    }
  +
  +    /**
  +     * set the classpath
  +     * @return
  +     */ 
  +    public Path createClasspath() {
  +        if (classpath == null) {
  +            classpath = new Path(project);
  +        }
  +        return classpath.createPath();
       }
       
       private void traceSystemSetting(String setting,int logLevel) {
  
  
  
  1.76      +1 -0      ws-axis/java/src/org/apache/axis/i18n/resource.properties
  
  Index: resource.properties
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/i18n/resource.properties,v
  retrieving revision 1.75
  retrieving revision 1.76
  diff -u -r1.75 -r1.76
  --- resource.properties	24 Nov 2003 20:54:47 -0000	1.75
  +++ resource.properties	30 Nov 2003 05:42:24 -0000	1.76
  @@ -933,6 +933,7 @@
   optionPassword=password to access the WSDL-URI
   cantGetDoc00=Unable to retrieve WSDL document: {0}
   implAlreadySet=Attempt to set implementation class on a ServiceDesc which has already been
configured
  +optionClasspath=additional classpath elements
   
   cantCreateBean00=Unable to create JavaBean of type {0}.  Missing default constructor? 
Error was: {1}.
   faultDuringCleanup=AxisEngine faulted during cleanup!
  
  
  

Mime
View raw message