tomj        02/02/01 14:46:13

  Modified:    java/src/org/apache/axis/wsdl/fromJava Types.java
                        Emitter.java DefaultBuilderPortTypeClassRep.java
                        DefaultBuilderBeanClassRep.java ClassRep.java
                        BuilderPortTypeClassRep.java
               java/src/org/apache/axis/utils resources.properties
               java/src/org/apache/axis/wsdl Java2WSDL.java
  Log:
  Add some new features to JAva2WSDL to help control methods and inheritance.
  Do not emit methods of java.lang.Object when -all switch is given.
  
  Two new Emitter APIs and corresponding command line switches:
  - setDisallowedMethods(Vector disallowedMethods), command line switch: -x, --exclude
    A list of methods that are explicitly NOT published in the WSDL
  
  - setStopClasses(Vector stopClasses), command line switch: -c, --stopClasses
    A list of class names which will halt the walk up class heirachy for both types 
and methods.
  
  Example:
    class Parent {}
    class Child extends parent {}
    class Baby extends child {}
  
  Running 'Java2WSDL -all -c Parent Baby' will emit all methods in Child and Baby
  but no methods in 'parent'.  If these were JavaBeans, no member from parent
  would be included in the XML Schema types, and the child type will not extend
  parent.
  
  Revision  Changes    Path
  1.13      +7 -3      xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java
  
  Index: Types.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Types.java        1 Feb 2002 22:08:26 -0000       1.12
  +++ Types.java        1 Feb 2002 22:46:13 -0000       1.13
  @@ -107,6 +107,7 @@
       HashMap schemaElementNames = null;
       HashMap schemaUniqueElementNames = null; 
       BuilderBeanClassRep beanBuilder = null;
  +    Vector stopClasses = null;
   
       /**
        * This class serailizes a <code>Class</code> to XML Schema. The constructor
  @@ -124,13 +125,15 @@
                    TypeMapping defaultTM,   
                    Namespaces namespaces, 
                    String targetNamespace,
  -                 Java2WSDLFactory factory) {
  +                 Java2WSDLFactory factory, 
  +                 Vector stopClasses) {
           this.def = def;
           createDocumentFragment();
           this.tm = tm;
           this.defaultTM = defaultTM;
           this.namespaces = namespaces;
           this.targetNamespace = targetNamespace;
  +        this.stopClasses = stopClasses;
           schemaElementNames = new HashMap();
           schemaUniqueElementNames = new HashMap();
           schemaTypes = new HashMap();
  @@ -455,11 +458,12 @@
           writeSchemaElement(qName, complexType);
           complexType.setAttribute("name", qName.getLocalPart());
   
  -        // See if there is a super class
  +        // See if there is a super class, stop if we hit a stop class
           Element e = null;
           Class superClass = cls.getSuperclass();
           if (superClass != null &&
  -            superClass != java.lang.Object.class) {
  +                superClass != java.lang.Object.class &&
  +                (stopClasses == null || 
!stopClasses.contains(superClass.getName()))) {
               // Write out the super class
               String base = writeType(superClass);
               Element complexContent = docHolder.createElement("complexContent");
  
  
  
  1.12      +80 -6     xml-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java
  
  Index: Emitter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Emitter.java      1 Feb 2002 22:08:26 -0000       1.11
  +++ Emitter.java      1 Feb 2002 22:46:13 -0000       1.12
  @@ -120,8 +120,10 @@
       private Class cls;
       private Class implCls;                 // Optional implementation class
       private Vector allowedMethods = null;  // Names of methods to consider
  +    private Vector disallowedMethods = null; // Names of methods to exclude
  +    private Vector stopClasses = null;// class names which halt inheritace searches
       private boolean useInheritedMethods = false;
  -    private String intfNS;          
  +    private String intfNS;
       private String implNS;
       private String locationUrl;
       private String importUrl;
  @@ -299,7 +301,8 @@
   
           // Write interface header
           writeDefinitions(def, intfNS);
  -        types = new Types(def, tm, defaultTM, namespaces, intfNS, factory);
  +        types = new Types(def, tm, defaultTM, namespaces, 
  +                          intfNS, factory, stopClasses);
           Binding binding = writeBinding(def, true);
           writePortType(def, binding);
           writeService(def, binding);
  @@ -322,7 +325,8 @@
   
           // Write interface header
           writeDefinitions(def, intfNS);
  -        types = new Types(def, tm, defaultTM, namespaces, intfNS, factory);
  +        types = new Types(def, tm, defaultTM, namespaces, 
  +                          intfNS, factory, stopClasses);
           Binding binding = writeBinding(def, true);
           writePortType(def, binding);
           return def;
  @@ -531,9 +535,11 @@
           BuilderPortTypeClassRep builder = 
              factory.getBuilderPortTypeClassRep();
           ClassRep classRep = 
  -           builder.build(cls, useInheritedMethods, implCls);
  +           builder.build(cls, useInheritedMethods, stopClasses, implCls);
           Vector methods = 
  -           builder.getResolvedMethods(classRep, allowedMethods);
  +           builder.getResolvedMethods(classRep, 
  +                                      allowedMethods, 
  +                                      disallowedMethods);
   
           for(int i=0; i<methods.size(); i++) {
               MethodRep method = (MethodRep) methods.elementAt(i);
  @@ -966,19 +972,87 @@
       
       /**
        * Set a Vector of methods to export
  -     * @param allowedMethods a space separated list of methods to export
  +     * @param allowedMethods a vector of methods to export
        */
       public void setAllowedMethods(Vector allowedMethods) {
           this.allowedMethods = allowedMethods;
       }
   
  +    /**
  +     * Indicates if the emitter will search classes for inherited methods
  +     */ 
       public boolean getUseInheritedMethods() {
           return useInheritedMethods;
       }    
   
  +    /**
  +     * Turn on or off inherited method WSDL generation.
  +     */ 
       public void setUseInheritedMethods(boolean useInheritedMethods) {
           this.useInheritedMethods = useInheritedMethods;
       }    
  +
  +    /**
  +     * Set a list of methods NOT to export
  +     * @param a vector of method name strings
  +     */ 
  +    public void setDisallowedMethods(Vector disallowedMethods) {
  +        this.disallowedMethods = disallowedMethods;
  +    }
  +
  +    /**
  +     * Set a list of methods NOT to export
  +     * @param a space separated list of method names
  +     */ 
  +    public void setDisallowedMethods(String text) {
  +        if (text != null) {
  +            StringTokenizer tokenizer = new StringTokenizer(text, " ,+");
  +            disallowedMethods = new Vector();
  +            while (tokenizer.hasMoreTokens()) {
  +                disallowedMethods.add(tokenizer.nextToken());
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Return list of methods that should not be exported
  +     */ 
  +    public Vector getDisallowedMethods() {
  +        return disallowedMethods;
  +    }
  +
  +    /**
  +     * Set a list of classes (fully qualified) that will stop the traversal
  +     * of the inheritance tree if encounter in method or complex type generation
  +     * 
  +     * @param a vector of class name strings
  +     */ 
  +    public void setStopClasses(Vector stopClasses) {
  +        this.stopClasses = stopClasses;
  +    }
  +
  +    /**
  +     * Set a list of classes (fully qualified) that will stop the traversal
  +     * of the inheritance tree if encounter in method or complex type generation
  +     * 
  +     * @param a space separated list of class names
  +     */ 
  +    public void setStopClasses(String text) {
  +        if (text != null) {
  +            StringTokenizer tokenizer = new StringTokenizer(text, " ,+");
  +            stopClasses = new Vector();
  +            while (tokenizer.hasMoreTokens()) {
  +                stopClasses.add(tokenizer.nextToken());
  +            }
  +        }
  +    }
  +    
  +    /**
  +     * Return the list of classes which stop inhertance searches
  +     */ 
  +    public Vector getStopClasses() {
  +        return stopClasses;
  +    }
   
       /**
        * get the packagename to namespace map
  
  
  
  1.3       +21 -3     
xml-axis/java/src/org/apache/axis/wsdl/fromJava/DefaultBuilderPortTypeClassRep.java
  
  Index: DefaultBuilderPortTypeClassRep.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/DefaultBuilderPortTypeClassRep.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultBuilderPortTypeClassRep.java       3 Jan 2002 20:33:43 -0000       1.2
  +++ DefaultBuilderPortTypeClassRep.java       1 Feb 2002 22:46:13 -0000       1.3
  @@ -75,10 +75,12 @@
        * @param cls is the Class 
        * @param inhMethods if true, then the ClassRep will contain all methods 
inherited and
        *                   declared. If false, then ClassRep will contain just the 
declared methods.
  +     * @param stopClasses An optional vector of class names which if inhMethods
  +     *                    is true, will stop the inheritence search if encountered.
        * @param implClass  An optional implClass can be passed in that 
implements/extends cls.
        *                   The purpose of the implClass is to find method parameter 
names.             
        **/
  -    public ClassRep build(Class cls, boolean inhMethods, Class implClass) {
  +    public ClassRep build(Class cls, boolean inhMethods, Vector stopClasses, Class 
implClass) {
           // Constructs a default ClassRep from the class
           // The Java2WSDL code examines the names/methods/params in ClassRep (and 
its super classes)
           // when constructing complexTypes.  So if you want to change the WSDL
  @@ -86,7 +88,7 @@
           // For example, if you want to supply your own parameter names, you 
           // could walk the ParamRep objects of each MethodRep and supply your own 
names.
           // (See getResolvedMethods for a way to deal with overloading conflicts)
  -        ClassRep cr = new ClassRep(cls, inhMethods, implClass);
  +        ClassRep cr = new ClassRep(cls, inhMethods, stopClasses, implClass);
   
           return cr;
       }
  @@ -96,9 +98,13 @@
        * @param cr is the ClassRep for the PortType class
        * @param allowedMethods is a vector that contains the names of the methods to 
consider.
        *                       if empty or null, consider all methods.
  +     * @param disallowedMethods is a vector that contains the names of the methods 
NOT to consider.
  +     *                       if empty or null, consider all methods.
        * @return Vector of MethodRep objects
        **/
  -    public Vector getResolvedMethods(ClassRep cr, Vector allowedMethods) {
  +    public Vector getResolvedMethods(ClassRep cr,
  +                                     Vector allowedMethods,
  +                                     Vector disallowedMethods) {
           Vector methods = new Vector(cr.getMethods());
   
           // Remove from the array methods not contained in allowedMethods
  @@ -107,6 +113,18 @@
               int i = 0;
               while(i < methods.size()) {
                   if 
(!allowedMethods.contains(((MethodRep)methods.elementAt(i)).getName())) {
  +                    methods.remove(i);
  +                } else {
  +                    i++;
  +                }
  +            }
  +        }
  +        
  +        // Remove from the array methods that are listed in disallowedMethods
  +        if (disallowedMethods != null && disallowedMethods.size() > 0) {
  +            int i = 0;
  +            while(i < methods.size()) {
  +                if 
(disallowedMethods.contains(((MethodRep)methods.elementAt(i)).getName())) {
                       methods.remove(i);
                   } else {
                       i++;
  
  
  
  1.3       +1 -1      
xml-axis/java/src/org/apache/axis/wsdl/fromJava/DefaultBuilderBeanClassRep.java
  
  Index: DefaultBuilderBeanClassRep.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/DefaultBuilderBeanClassRep.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultBuilderBeanClassRep.java   3 Jan 2002 20:33:43 -0000       1.2
  +++ DefaultBuilderBeanClassRep.java   1 Feb 2002 22:46:13 -0000       1.3
  @@ -80,7 +80,7 @@
           // processing, you could add/change/remove/rename the ClassRep and FieldRep 
objects.
           // For example, if you want all of the field elements in the complexType to 
be
           // uppercased, you could walk all of the FieldRep and uppercase the names.
  -        ClassRep cr = new ClassRep(cls, false);
  +        ClassRep cr = new ClassRep(cls, false, null);
   
           return cr;
       }
  
  
  
  1.9       +51 -25    xml-axis/java/src/org/apache/axis/wsdl/fromJava/ClassRep.java
  
  Index: ClassRep.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/ClassRep.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ClassRep.java     14 Jan 2002 19:18:52 -0000      1.8
  +++ ClassRep.java     1 Feb 2002 22:46:13 -0000       1.9
  @@ -151,29 +151,37 @@
        * @param inhMethods if true, then the methods array will contain
        *                   methods declared and/or inherited else only
        *                   the declared methods are put in the list
  +     * @param stopList An optional vector of class names which if inhMethods
  +     *                    is true, will stop the inheritence search if encountered.
        * @param implClass  This is an optional parameter which is a 
        *                   class that implements or extends cls.  The
        *                   implClass is used to obtain parameter names.
        */ 
  -    public ClassRep(Class cls, boolean inhMethods) {
  -        init(cls, inhMethods, null);
  +    public ClassRep(Class cls, boolean inhMethods, Vector stopList) {
  +        init(cls, inhMethods, stopList, null);
       }
  -    public ClassRep(Class cls, boolean inhMethods, Class implClass) {
  -        init(cls, inhMethods, implClass);
  +    public ClassRep(Class cls, boolean inhMethods, Vector stopList, Class 
implClass) {
  +        init(cls, inhMethods, stopList, implClass);
       }
  -    protected void init(Class cls, boolean inhMethods, Class implClass) {
  +    protected void init(Class cls, boolean inhMethods, Vector stopList, Class 
implClass) {
           _name = cls.getName();
           _isInterface = cls.isInterface();
           _modifiers = cls.getModifiers();
  -        if (cls.getSuperclass() != null &&
  -            cls.getSuperclass() != Object.class) {
  -            _super = new ClassRep(cls.getSuperclass(), inhMethods);
  +
  +        // Get our parent class, avoid Object and any class on the stop list.
  +        Class superClazz = cls.getSuperclass();
  +        if (superClazz != null &&
  +            superClazz != Object.class &&
  +            (stopList == null || !stopList.contains(superClazz.getName()))) {
  +            _super = new ClassRep(superClazz, inhMethods, stopList);
           }
  +        
  +        // Add the interfaces
           for (int i=0; i < cls.getInterfaces().length; i++) {
  -            _interfaces.add(new ClassRep(cls.getInterfaces()[i], inhMethods));
  +            _interfaces.add(new ClassRep(cls.getInterfaces()[i], inhMethods, 
stopList));
           }
           // Add the methods
  -        addMethods(cls, inhMethods, implClass);
  +        addMethods(cls, inhMethods, stopList, implClass);
   
           // Add the fields
           addFields(cls);
  @@ -204,28 +212,46 @@
        * @param inhMethods if true, then the methods array will contain
        *                   methods declared and/or inherited else only
        *                   the declared methods are put in the list           
  +     * @param stopList An optional vector of class names which if inhMethods
  +     *                    is true, will stop the inheritence search if encountered.
        * @param implClass  This is an optional parameter which is a 
        *                   class that implements or extends cls.  The
        *                   implClass is used to obtain parameter names.            
        */ 
  -    protected void addMethods(Class cls, boolean inhMethods, Class implClass) {
  +    protected void addMethods(Class cls, boolean inhMethods, Vector stopList, Class 
implClass) {
           // Constructs a vector of all the public methods
           Method[] m;
  -        if (inhMethods)
  -            m = cls.getMethods();
  -        else
  -            m = cls.getDeclaredMethods();
  -        for (int i=0; i < m.length; i++) {
  -            int mod = m[i].getModifiers();
  -            if (Modifier.isPublic(mod) &&
  -                // Ignore the getParameterName method from the Skeleton class
  -                (!m[i].getName().equals("getParameterName") ||
  -                 !(Skeleton.class).isAssignableFrom(m[i].getDeclaringClass()))) {
  -                short[] modes = getParameterModes(m[i]);
  -                Class[] types = getParameterTypes(m[i]);
  -                _methods.add(new MethodRep(m[i], types, modes,
  -                                           getParameterNames(m[i], implClass, 
types)));
  +        
  +        // iterate up the inheritance chain and construct the list of methods
  +        Class currentClass = cls;
  +        while (currentClass != null &&
  +                currentClass != Object.class &&
  +                (stopList == null || !stopList.contains(currentClass.getName()))) {
  +
  +            // get the methods in this class
  +            m = currentClass.getDeclaredMethods();
  +
  +            // add each method in this class to the list
  +            for (int i=0; i < m.length; i++) {
  +                int mod = m[i].getModifiers();
  +                if (Modifier.isPublic(mod) &&
  +                        // Ignore the getParameterName method from the Skeleton 
class
  +                        (!m[i].getName().equals("getParameterName") ||
  +                        
!(Skeleton.class).isAssignableFrom(m[i].getDeclaringClass()))) {
  +                    short[] modes = getParameterModes(m[i]);
  +                    Class[] types = getParameterTypes(m[i]);
  +                    _methods.add(new MethodRep(m[i], types, modes,
  +                                               getParameterNames(m[i], implClass, 
types)));
  +                }
  +            }
  +            
  +            // if we don't want inherited methods, don't walk the chain
  +            if (!inhMethods) {
  +                break;
               }
  +            
  +            // move up the inhertance chain
  +            currentClass = currentClass.getSuperclass();
           }
           return;
       }
  
  
  
  1.3       +4 -2      
xml-axis/java/src/org/apache/axis/wsdl/fromJava/BuilderPortTypeClassRep.java
  
  Index: BuilderPortTypeClassRep.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/BuilderPortTypeClassRep.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BuilderPortTypeClassRep.java      3 Jan 2002 20:33:43 -0000       1.2
  +++ BuilderPortTypeClassRep.java      1 Feb 2002 22:46:13 -0000       1.3
  @@ -72,10 +72,12 @@
        * @param cls is the Class 
        * @param inhMethods if true, then the ClassRep will contain all methods 
inherited and
        *                   declared. If false, then ClassRep will contain just the 
declared methods.
  +    * @param stopClasses An optional vector of class names which if inhMethods
  +    *                    is true, will stop the inheritence search if encountered.
        * @param implClass  An optional implClass can be passed in that 
implements/extends cls.
        *                   The purpose of the implClass is to find method parameter 
names.             
        **/
  -    public ClassRep build(Class cls, boolean inhMethods, Class implClass);
  +    public ClassRep build(Class cls, boolean inhMethods, Vector stopClasses, Class 
implClass);
   
       /**
        * Returns a list of MethodReps to be used for portType operation processing.
  @@ -84,5 +86,5 @@
        *                       if empty or null, consider all methods.
        * @return Vector of MethodRep objects
        **/
  -    public Vector getResolvedMethods(ClassRep cr, Vector allowedMethods);
  +    public Vector getResolvedMethods(ClassRep cr, Vector allowedMethods, Vector 
disallowedMethods);
   }
  
  
  
  1.48      +2 -0      xml-axis/java/src/org/apache/axis/utils/resources.properties
  
  Index: resources.properties
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/resources.properties,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- resources.properties      30 Jan 2002 20:36:09 -0000      1.47
  +++ resources.properties      1 Feb 2002 22:46:13 -0000       1.48
  @@ -613,6 +613,8 @@
   j2woptimplClass00=optional class that contains implementation of methods in 
class-of-portType.  The debug information in the class is used to obtain the method 
parameter names, which are used to set the WSDL part names.
   j2werror00=Error: {0}
   j2wmodeerror=Error Unrecognized Mode: {0} Use All, Interface or Implementation. 
Continuing with All.
  +j2woptexclude00=space or comma separated list of methods not to export
  +j2woptstopClass00=space or comma separated list of class names which will stop 
inheritance search if --all switch is given
   
   optionSkeletonDeploy00=(true or false) Indicate whether to deploy skeleton or 
implementation class.
   j2wMissingLocation00=The -l <location> option must be specified if the full wsdl or 
the implementation wsdl is requested.
  
  
  
  1.7       +19 -1     xml-axis/java/src/org/apache/axis/wsdl/Java2WSDL.java
  
  Index: Java2WSDL.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Java2WSDL.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Java2WSDL.java    14 Jan 2002 15:24:03 -0000      1.6
  +++ Java2WSDL.java    1 Feb 2002 22:46:13 -0000       1.7
  @@ -88,6 +88,8 @@
       protected static final int INHERITED_CLASS_OPT = 'a';
       protected static final int FACTORY_CLASS_OPT = 'f';
       protected static final int IMPL_CLASS_OPT = 'i';
  +    protected static final int METHODS_NOTALLOWED_OPT = 'x';
  +    protected static final int STOP_CLASSES_OPT = 'c';
   
       /**
        *  Define the understood options. Each CLOptionDescriptor contains:
  @@ -155,7 +157,14 @@
                   CLOptionDescriptor.ARGUMENT_REQUIRED,
                   IMPL_CLASS_OPT,
                   JavaUtils.getMessage("j2woptimplClass00")),
  -
  +        new CLOptionDescriptor("exclude",
  +                CLOptionDescriptor.ARGUMENT_REQUIRED,
  +                METHODS_NOTALLOWED_OPT,
  +                JavaUtils.getMessage("j2woptexclude00")),
  +        new CLOptionDescriptor("stopClasses",
  +                CLOptionDescriptor.ARGUMENT_REQUIRED,
  +                STOP_CLASSES_OPT,
  +                JavaUtils.getMessage("j2woptstopClass00"))
       };
   
       
  @@ -270,6 +279,15 @@
                       case LOCATION_IMPORT_OPT:
                           emitter.setImportUrl(option.getArgument());
                           break;
  +                        
  +                    case METHODS_NOTALLOWED_OPT:
  +                        emitter.setDisallowedMethods(option.getArgument());
  +                        break;
  +                        
  +                    case STOP_CLASSES_OPT:
  +                        emitter.setStopClasses(option.getArgument());
  +                        break;
  +                        
                   }
               }
   
  
  
  


Reply via email to