You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/05/30 14:35:17 UTC

cvs commit: ws-axis/java/src/org/apache/axis/wsdl/toJava JavaBeanWriter.java

dims        2005/05/30 05:35:17

  Modified:    java/src/org/apache/axis/wsdl/symbolTable ElementDecl.java
                        SchemaUtils.java
               java/src/org/apache/axis/wsdl/toJava JavaBeanWriter.java
  Log:
  Fix for AXIS-2020 - wsdl2java does not generate array of wrappers for array of nillable primitives
  from andrei.iltchenko@nl.compuware.com
  
  Revision  Changes    Path
  1.12      +21 -1     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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ElementDecl.java	12 Apr 2005 22:18:16 -0000	1.11
  +++ ElementDecl.java	30 May 2005 12:35:17 -0000	1.12
  @@ -55,6 +55,8 @@
       /** Field maxOccursIsUnbounded */
       private boolean maxOccursIsUnbounded = false;
   
  +    private boolean maxOccursExactOne;
  +
       /**
        * Constructor ElementDecl
        *
  @@ -93,7 +95,7 @@
       }
   
       /**
  -     * Method setMinOccursIsUnbounded
  +     * Method setMaxOccursIsUnbounded
        *
        * @param maxOccursIsUnbounded
        */
  @@ -102,6 +104,24 @@
       }
   
       /**
  +     * Method getMaxOccursIsExactlyOne
  +     *
  +     * @return
  +     */
  +    public boolean getMaxOccursIsExactlyOne() {
  +        return maxOccursExactOne;
  +    }
  +
  +    /**
  +     * Method setMaxOccursIsExactlyOne
  +     *
  +     * @param exactOne
  +     */
  +    public void setMaxOccursIsExactlyOne(boolean exactOne) {
  +        maxOccursExactOne = exactOne;
  +    }
  +
  +    /**
        * Method setNillable
        *
        * @param nillable
  
  
  
  1.58      +9 -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.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- SchemaUtils.java	20 May 2005 12:55:49 -0000	1.57
  +++ SchemaUtils.java	30 May 2005 12:35:17 -0000	1.58
  @@ -774,9 +774,17 @@
               }
   
               String maxOccurs = Utils.getAttribute(elementNode, "maxOccurs");
  -            if (maxOccurs != null && maxOccurs.equals("unbounded")) {
  +            if (maxOccurs != null) {
  +                if (maxOccurs.equals("unbounded")) {
                       elem.setMaxOccursIsUnbounded(true);
  +                }
  +                else if(maxOccurs.equals("1")) {
  +                    elem.setMaxOccursIsExactlyOne(true);
  +                }
               }
  +            else {
  +				elem.setMaxOccursIsExactlyOne(true);
  +			}
               elem.setNillable(
                       JavaUtils.isTrueExplicitly(
                               Utils.getAttribute(elementNode, "nillable")));
  
  
  
  1.76      +47 -8     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.75
  retrieving revision 1.76
  diff -u -r1.75 -r1.76
  --- JavaBeanWriter.java	22 Mar 2005 12:24:13 -0000	1.75
  +++ JavaBeanWriter.java	30 May 2005 12:35:17 -0000	1.76
  @@ -22,6 +22,9 @@
   import org.apache.axis.wsdl.symbolTable.ElementDecl;
   import org.apache.axis.wsdl.symbolTable.SchemaUtils;
   import org.apache.axis.wsdl.symbolTable.TypeEntry;
  +import org.apache.axis.wsdl.symbolTable.CollectionTE;
  +import org.apache.axis.wsdl.symbolTable.BaseType;
  +import org.apache.axis.wsdl.symbolTable.DefinedElement;
   import org.w3c.dom.DOMException;
   import org.w3c.dom.Node;
   
  @@ -32,9 +35,6 @@
   import java.util.Iterator;
   import java.util.Set;
   import java.util.Vector;
  -import java.util.TreeSet;
  -import java.util.TreeMap;
  -import java.util.Map;
   
   /**
    * This is Wsdl2java's Complex Type Writer.  It writes the <typeName>.java file.
  @@ -270,10 +270,49 @@
                       isAny = true;
                   } else {
                       variableName = elem.getName();
  -                    
  -                    if (elem.getMinOccursIs0() || elem.getNillable() ||
  -		            elem.getOptional()) {
  +
  +                    /*
  +                     * Quote from JAX-RPC 1.1, Section 4.2.1:
  +                     * There are a number of cases in which a built-in simple
  +                     * XML data type must be mapped to the corresponding Java
  +                     * wrapper class for the Java primitive type:
  +                     *   * an element declaration with the nillable attribute
  +                     *     set to true;
  +                     *   * an element declaration with the minOccurs attribute
  +                     *     set to 0 (zero) and the maxOccurs attribute set
  +                     *     to 1 (one) or absent;
  +                     *   * an attribute declaration with the use attribute set
  +                     *     to optional or absent and carrying neither
  +                     *     the default nor the fixed attribute;
  +                     */
  +                    if (elem.getMinOccursIs0() && elem.getMaxOccursIsExactlyOne()
  +                            || elem.getNillable() || elem.getOptional()) {
  +                        String   dims = null;
  +                        /*
  +                         * Handle situations where the nillable property is
  +                         * combined with a non-singular 'maxOccurs' value
  +                         * and the component type is a primitive, e.g.
  +                         * <xsd:element name="code" type="xsd:int" nillable="true" maxOccurs="unbounded"/>
  +                         * Under these circumstances we still have to promote
  +                         * the underlying type to the corresponding wrapper
  +                         * class.
  +                         */
  +                        if (elem.getType() instanceof CollectionTE) {
  +                            TypeEntry   te = elem.getType().getRefType();
  +                            if (te instanceof BaseType
  +                                ||  te instanceof DefinedElement
  +                                    &&  te.getRefType() instanceof BaseType) {
  +                                /*
  +                                 * Deliberately looking at the dimensions introduced
  +                                 * by the 'maxOccurs' only, further dimensions
  +                                 * (if any) must be disregarded.
  +                                 */
  +                                dims = elem.getType().getDimensions();
  +                                typeName = te.getName();
  +                            }
  +                        }
                           typeName = Utils.getWrapperType(typeName);
  +                        if (dims != null)  typeName += dims;
                       }
                   }
   
  @@ -312,10 +351,10 @@
   
               for (int i = 0; i < attributes.size(); i++) {
                   ContainedAttribute attr = (ContainedAttribute) attributes.get(i);
  -                String typeName = attr.getType().getName(); 
  +                String typeName = attr.getType().getName();
                   String variableName = attr.getName();
   
  -		// TODO - What about MinOccurs and Nillable? 
  +		// TODO - What about MinOccurs and Nillable?
   		// Do they make sense here?
   		if (attr.getOptional()) {
   		    typeName = Utils.getWrapperType(typeName);