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/wsdl/toJava JavaBeanWriter.java
Date Fri, 28 Nov 2003 17:08:13 GMT
dims        2003/11/28 09:08:13

  Modified:    java/src/org/apache/axis/wsdl/symbolTable ElementDecl.java
                        SchemaUtils.java
               java/src/org/apache/axis/wsdl/toJava JavaBeanWriter.java
  Log:
  Fix for Bug 19214 - WSDL2Java ignores <xs:annotation> comments
  from "Hawkins, Peter" <HawkinsP-C@BATTELLE.ORG>
  
  Revision  Changes    Path
  1.7       +20 -0     ws-axis/java/src/org/apache/axis/wsdl/symbolTable/ElementDecl.java
  
  Index: ElementDecl.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/ElementDecl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ElementDecl.java	29 Oct 2003 20:46:24 -0000	1.6
  +++ ElementDecl.java	28 Nov 2003 17:08:13 -0000	1.7
  @@ -71,6 +71,9 @@
   
       /** Field type */
       private TypeEntry type;
  +    
  +    /** Field documentation */
  +    private String documentation;
   
       // The following property is set if minOccurs=0.
       // An item that is not set and has minOccurs=0
  @@ -195,5 +198,22 @@
        */
       public void setAnyElement(boolean anyElement) {
           this.anyElement = anyElement;
  +    }
  +
  +    /**
  +     * Method getDocumentation
  +     * 
  +     * @return string
  +     */
  +    public String getDocumentation() {
  +        return documentation;
  +    }
  +
  +    /**
  +     * Method setDocumentation
  +     * @param documentation
  +     */
  +    public void setDocumentation(String documentation) {
  +        this.documentation = documentation;
       }
   }
  
  
  
  1.31      +68 -1     ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SchemaUtils.java
  
  Index: SchemaUtils.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SchemaUtils.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- SchemaUtils.java	4 Nov 2003 18:07:22 -0000	1.30
  +++ SchemaUtils.java	28 Nov 2003 17:08:13 -0000	1.31
  @@ -56,6 +56,7 @@
   
   import org.apache.axis.Constants;
   import org.apache.axis.utils.JavaUtils;
  +import org.w3c.dom.DOMException;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
   
  @@ -65,6 +66,7 @@
   import java.util.Arrays;
   import java.util.HashSet;
   import java.util.Set;
  +import java.util.StringTokenizer;
   import java.util.Vector;
   
   /**
  @@ -390,6 +392,64 @@
       }
   
       /**
  +     * Returns named child node.
  +     * 
  +     * @param parentNode Parent node.
  +     * @param name Element name of child node to return.
  +     */
  +    private static Node getChildByName(Node parentNode, String name) throws DOMException
{
  +        if (parentNode == null) return null;
  +        NodeList children = parentNode.getChildNodes();
  +        if (children != null) {
  +            for (int i = 0; i < children.getLength(); i++) {
  +                Node child = children.item(i);
  +                if (child != null) {
  +                    if (child.getNodeName() != null && name.equals(child.getNodeName()))
{
  +                        return child;
  +                    }
  +                }
  +            }
  +        }
  +        return null;
  +    }
  +
  +    /**
  +     * Returns all textual nodes of a subnode defined by a parent node
  +     * and a path of element names to that subnode.
  +     * 
  +     * @param root Parent node.
  +     * @param path Path of element names to text of interest, delimited by "/". 
  +     */
  +    public static String getTextByPath(Node root, String path) throws DOMException {
  +        StringTokenizer st = new StringTokenizer(path, "/");
  +        Node node = root;
  +        while (st.hasMoreTokens()) {
  +            String elementName = st.nextToken();
  +            Node child = getChildByName(node, elementName);
  +            if (child == null)
  +                throw new DOMException(DOMException.NOT_FOUND_ERR, "could not find " +
elementName);
  +            node = child;
  +        }
  +    
  +        // should have found the node
  +        String text = "";
  +        NodeList children = node.getChildNodes();
  +        if (children != null) {
  +            for (int i = 0; i < children.getLength(); i++) {
  +                Node child = children.item(i);
  +                if (child != null) {
  +                    if (child.getNodeName() != null
  +                            && (child.getNodeName().equals("#text")
  +                            || child.getNodeName().equals("#cdata-section"))) {
  +                        text += child.getNodeValue();
  +                    }
  +                }
  +            }
  +        }
  +        return text;
  +    }
  +
  +    /**
        * Invoked by getContainedElementDeclarations to get the child element types
        * and child element names underneath a Sequence Node
        * 
  @@ -522,7 +582,13 @@
           // Get the name qnames.
           QName nodeName = Utils.getNodeNameQName(elementNode);
           BooleanHolder forElement = new BooleanHolder();
  -
  +        String comments = null;
  +        try {
  +            comments = getTextByPath(elementNode, "annotation/documentation");
  +        } catch (DOMException e) {
  +            // no comments
  +        }
  +        
           // The type qname is used to locate the TypeEntry, which is then
           // used to retrieve the proper java name of the type.
           QName nodeType = Utils.getTypeQName(elementNode, forElement, false);
  @@ -559,6 +625,7 @@
   
           if (type != null) {
               ElementDecl elem = new ElementDecl(type, nodeName);
  +            elem.setDocumentation(comments);
               String minOccurs = Utils.getAttribute(elementNode,
                       "minOccurs");
   
  
  
  
  1.51      +108 -0    ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java
  
  Index: JavaBeanWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- JavaBeanWriter.java	28 Nov 2003 02:42:34 -0000	1.50
  +++ JavaBeanWriter.java	28 Nov 2003 17:08:13 -0000	1.51
  @@ -60,6 +60,7 @@
   import org.apache.axis.wsdl.symbolTable.ElementDecl;
   import org.apache.axis.wsdl.symbolTable.SchemaUtils;
   import org.apache.axis.wsdl.symbolTable.TypeEntry;
  +import org.w3c.dom.DOMException;
   import org.w3c.dom.Node;
   
   import javax.xml.namespace.QName;
  @@ -69,6 +70,7 @@
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Set;
  +import java.util.StringTokenizer;
   import java.util.Vector;
   
   /**
  @@ -182,6 +184,35 @@
       }    // ctor
   
       /**
  +     * Write a common header, including the package name, the class
  +     * declaration, and the opening curly brace.  
  +     * Prints javadoc from WSDL documentation.  (Cannot pull up, type DOM not avail)
  +     */
  +    protected void writeFileHeader(PrintWriter pw) throws IOException {
  +        writeHeaderComments(pw);
  +        writePackage(pw);
  +    
  +        try
  +        {
  +            String comments = SchemaUtils.getTextByPath(type.getNode(), "annotation/documentation");
  +            comments = getJavadocDescriptionPart(comments, false);
  +            if (comments != null && comments.trim().length() > 0)
  +            {
  +                pw.println();
  +                pw.println("/**");
  +                pw.println(" * " + comments);
  +                pw.println(" */");
  +            }
  +        }
  +        catch (DOMException e)
  +        {
  +            // no comment
  +        }        
  +        // print class declaration
  +        pw.println(getClassModifiers() + getClassText() + getClassName() + ' ' + getExtendsText()
+ getImplementsText() + "{");
  +    } // writeFileHeader
  +
  +    /**
        * Generate the binding for the given complex type.
        * 
        * @param pw 
  @@ -405,10 +436,26 @@
           }
   
           for (int i = 0; i < names.size(); i += 2) {
  +            // get comments for this field
  +            String comments = "";
  +            if (elements != null)
  +            {
  +                if (elements != null && i < (elements.size()*2))
  +                {
  +                    ElementDecl elem = (ElementDecl)elements.get((int)i/2);
  +                    comments = elem.getDocumentation();
  +                }
  +            } 
  +            
               String typeName = (String) names.get(i);
               String variable = (String) names.get(i + 1);
   
               // Declare the bean element
  +            if (comments != null && comments.trim().length() > 0)
  +            {
  +                String flatComments = getJavadocDescriptionPart(comments, true);
  +                pw.println("    /** " + flatComments.trim() + " */");
  +            }
               pw.print("    private " + typeName + " " + variable + ";");
   
               // label the attribute fields.
  @@ -422,6 +469,31 @@
           pw.println();
       }
   
  +    
  +    /**
  +     * Takes out new lines and wraps at Javadoc tags
  +     * @param documentation the raw comments from schema
  +     * @param addTab if true adds a tab character when wrapping (methods)
  +     */
  +    private String getJavadocDescriptionPart(String documentation, boolean addTab) {
  +        String doc = "";
  +        if (documentation == null) return doc;
  +        if (documentation.trim().length() == 0) return doc;
  +
  +        StringTokenizer st2 = new StringTokenizer(documentation.trim(), "\n");
  +
  +        while (st2.hasMoreTokens()) {
  +            String line = st2.nextToken().trim();
  +            doc += line + " ";
  +        }
  +        StringTokenizer st = new StringTokenizer(doc.trim(), "@");
  +        String newComments = st.nextToken();
  +        while (st.hasMoreTokens()) {
  +            newComments += "\n" + (addTab ? "\t" : "") + " * @" + st.nextToken().trim();
  +        }
  +        return newComments;
  +    }
  +    
       /**
        * Writes the default constructor.
        */
  @@ -752,6 +824,17 @@
               String typeName = (String) names.get(i);
               String name = (String) names.get(i + 1);
               String capName = Utils.capitalizeFirstChar(name);
  +
  +            String documentation = "";
  +            if (elements != null)
  +            {
  +                if (elements != null && i < (elements.size()*2))
  +                {
  +                    ElementDecl elem = (ElementDecl)elements.get((int)i/2);
  +                    documentation = elem.getDocumentation();
  +                }
  +            } 
  +            
               String get = "get";
   
               if (typeName.equals("boolean")) {
  @@ -759,6 +842,17 @@
               }
   
               if (enableGetters) {
  +                try {
  +                    String comments = "Gets the " + name + " value for this " + getClassName()
+ ".";
  +                    pw.println();
  +                    pw.println("    /**");
  +                    pw.println("     * " + comments);
  +                    pw.println("     * ");
  +                    pw.println("     * @return " + name + " " + getJavadocDescriptionPart(documentation,
true));
  +                    pw.println("     */");
  +                } catch (DOMException e) {
  +                    // no comment
  +                }                    
                   pw.println("    public " + typeName + " " + get + capName
                           + "() {");
   
  @@ -773,6 +867,20 @@
               }
   
               if (enableSetters) {
  +                try
  +                {
  +                    String comments = "Sets the " + name + " value for this " + getClassName()
+ ".";
  +                    pw.println();
  +                    pw.println("    /**");
  +                    pw.println("     * " + comments);
  +                    pw.println("     * ");
  +                    pw.println("     * @param " + name + " " + getJavadocDescriptionPart(documentation,
true));
  +                    pw.println("     */");
  +                }
  +                catch (DOMException e)
  +                {
  +                    // no comment
  +                }                    
                   if (isUnion()) {
                       pw.println("    public void set" + capName + "(" + typeName
                               + " value) {");
  
  
  

Mime
View raw message