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 2004/09/02 14:15:59 UTC

cvs commit: ws-axis/java/src/org/apache/axis/encoding/ser SimpleListDeserializer.java

dims        2004/09/02 05:15:59

  Modified:    java/src/org/apache/axis/wsdl/symbolTable
                        ContainedAttribute.java ElementDecl.java
                        SchemaUtils.java
               java/test/wsdl/uddiv2 InquiryServiceTestCase.java
               java/src/org/apache/axis/wsdl/toJava JavaBeanWriter.java
                        JavaGeneratorFactory.java
               java/src/org/apache/axis/encoding/ser
                        SimpleListDeserializer.java
  Log:
  Fixes for the following from Steve Green <st...@epok.net>
  
  AXIS-1319 - WSDL2Java: incorrect handling of xsd:base64Binary?
  AXIS-1449 - Deserialization of xsd:list attribute broken
  AXIS-1488 - xs:list itemTypes are forced into namespace {http://www.w3.org/2001/XMLSchema}
  AXIS-1539 - WSDL2Java does not handle use="optional" properly for primitive types
  
  Revision  Changes    Path
  1.2       +22 -0     ws-axis/java/src/org/apache/axis/wsdl/symbolTable/ContainedAttribute.java
  
  Index: ContainedAttribute.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/ContainedAttribute.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContainedAttribute.java	22 Aug 2004 03:06:59 -0000	1.1
  +++ ContainedAttribute.java	2 Sep 2004 12:15:58 -0000	1.2
  @@ -20,10 +20,32 @@
   
   public class ContainedAttribute extends ContainedEntry {
   
  +    /** Field optional */
  +    private boolean optional = false;
  +
       /**
        * @param qname
        */
       protected ContainedAttribute(TypeEntry type, QName qname) {
           super(type, qname);
       }
  +
  +    /**
  +     * Method setOptional
  +     * 
  +     * @param optional 
  +     */
  +    public void setOptional(boolean optional) {
  +        this.optional = optional;
  +    }
  +
  +    /**
  +     * Method getOptional
  +     * 
  +     * @return 
  +     */
  +    public boolean getOptional() {
  +        return optional;
  +    }
  +
   }
  
  
  
  1.10      +21 -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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ElementDecl.java	22 Aug 2004 03:06:59 -0000	1.9
  +++ ElementDecl.java	2 Sep 2004 12:15:58 -0000	1.10
  @@ -43,6 +43,9 @@
       /** Field nillable */
       private boolean nillable = false;
   
  +    /** Field optional */
  +    private boolean optional = false;
  +
       // Indicate if the ElementDecl represents
       // an xsd:any element
   
  @@ -94,6 +97,24 @@
        */
       public boolean getNillable() {
           return nillable;
  +    }
  +
  +    /**
  +     * Method setOptional
  +     * 
  +     * @param optional 
  +     */
  +    public void setOptional(boolean optional) {
  +        this.optional = optional;
  +    }
  +
  +    /**
  +     * Method getOptional
  +     * 
  +     * @return 
  +     */
  +    public boolean getOptional() {
  +        return optional;
       }
   
       /**
  
  
  
  1.48      +23 -7     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.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- SchemaUtils.java	22 Aug 2004 03:06:59 -0000	1.47
  +++ SchemaUtils.java	2 Sep 2004 12:15:58 -0000	1.48
  @@ -709,6 +709,12 @@
                       JavaUtils.isTrueExplicitly(
                               Utils.getAttribute(elementNode, "nillable")));
   
  +            String useValue = Utils.getAttribute(elementNode, "use");
  +
  +            if (useValue != null) {
  +                elem.setOptional(useValue.equalsIgnoreCase("optional"));
  +            }
  +
               return elem;
           }
   
  @@ -1561,13 +1567,22 @@
           // Try to get the corresponding global attribute ElementEntry
           // from the symbol table.
           if (type instanceof org.apache.axis.wsdl.symbolTable.Element) {
  -        	type = ((org.apache.axis.wsdl.symbolTable.Element) type).getRefType();
  +                type = ((org.apache.axis.wsdl.symbolTable.Element) type).getRefType();
           }
           
           // add type and name to vector, skip it if we couldn't parse it
           // XXX - this may need to be revisited.
           if ((type != null) && (attributeName != null)) {
  -            v.add(new ContainedAttribute(type, attributeName));
  +            ContainedAttribute attr =
  +	    	new ContainedAttribute(type, attributeName);
  +
  +	    String useValue = Utils.getAttribute(child, "use");
  +
  +	    if (useValue != null) {
  +		attr.setOptional(useValue.equalsIgnoreCase("optional"));
  +	    }
  +
  +            v.add(attr);
           }
       }
   
  @@ -1904,11 +1919,12 @@
                       if (type.equals("")) {
                           return null;
                       }
  -                    int colonIndex = type.lastIndexOf(":");
  -                    if (colonIndex > 0) {
  -                        type = type.substring(colonIndex + 1);
  -                    }
  -                    return new QName(Constants.URI_2001_SCHEMA_XSD, type + "[]");
  +                    //int colonIndex = type.lastIndexOf(":");
  +                    //if (colonIndex > 0) {
  +                        //type = type.substring(colonIndex + 1);
  +                    //}
  +                    //return new QName(Constants.URI_2001_SCHEMA_XSD, type + "[]");
  +                    return Utils.getQNameFromPrefixedName(node, type);
                   }
               }
           }
  
  
  
  1.3       +1 -1      ws-axis/java/test/wsdl/uddiv2/InquiryServiceTestCase.java
  
  Index: InquiryServiceTestCase.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/wsdl/uddiv2/InquiryServiceTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InquiryServiceTestCase.java	2 Jul 2004 13:27:54 -0000	1.2
  +++ InquiryServiceTestCase.java	2 Sep 2004 12:15:58 -0000	1.3
  @@ -30,7 +30,7 @@
   
           test.wsdl.uddiv2.api_v2.Find_business find = new test.wsdl.uddiv2.api_v2.Find_business();
           find.setGeneric("2.0");
  -        find.setMaxRows(100);
  +        find.setMaxRows(new Integer(100));
           test.wsdl.uddiv2.api_v2.Name[] names = new test.wsdl.uddiv2.api_v2.Name[1];
           names[0] = new test.wsdl.uddiv2.api_v2.Name();
           names[0].set_value("IBM");
  
  
  
  1.70      +63 -4     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.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- JavaBeanWriter.java	26 Aug 2004 19:01:17 -0000	1.69
  +++ JavaBeanWriter.java	2 Sep 2004 12:15:59 -0000	1.70
  @@ -268,7 +268,8 @@
                   } else {
                       variableName = elem.getName();
                       
  -                    if (elem.getMinOccursIs0() || elem.getNillable()) {
  +                    if (elem.getMinOccursIs0() || elem.getNillable() ||
  +		            elem.getOptional()) {
                           typeName = Utils.getWrapperType(typeName);
                       }
                   }
  @@ -307,6 +308,13 @@
                   ContainedAttribute attr = (ContainedAttribute) attributes.get(i);
                   String typeName = attr.getType().getName(); 
                   String variableName = attr.getName();
  +
  +		// TODO - What about MinOccurs and Nillable? 
  +		// Do they make sense here?
  +		if (attr.getOptional()) {
  +		    typeName = Utils.getWrapperType(typeName);
  +		}
  +
                   names.add(typeName);
                   names.add(variableName);
   
  @@ -360,6 +368,52 @@
       }
   
       /**
  +     * Returns the class name that should be used to serialize and
  +     * deserialize this binary element
  +     */
  +    protected String getBinaryTypeEncoderName(String elementName)
  +    {
  +        TypeEntry type = getElementDecl(elementName);
  +	if (type != null)
  +	{
  +	    String typeName = type.getQName().getLocalPart();
  +
  +	    if (typeName.equals("base64Binary"))
  +	    	return "org.apache.axis.encoding.Base64";
  +	    if (typeName.equals("hexBinary"))
  +	    	return "org.apache.axis.types.HexBinary";
  +
  +	    throw new java.lang.RuntimeException("Unknown binary type " +
  +		typeName + " for element " + elementName);
  +	}
  +
  +	throw new java.lang.RuntimeException("Unknown element " + elementName);
  +    }
  +
  +    /**
  +     * Returns the TypeEntry of the given element
  +     */
  +    protected TypeEntry getElementDecl(String elementName)
  +    {
  +        if (elements != null) {
  +            for (int i = 0; i < elements.size(); i++) {
  +                ElementDecl elem = (ElementDecl) elements.get(i);
  +                String variableName;
  +
  +                if (elem.getAnyElement()) {
  +                    variableName = Constants.ANYCONTENT;
  +                } else {
  +                    variableName = elem.getName();
  +                }
  +
  +                if (variableName.equals(elementName))
  +		    return elem.getType();
  +	    }
  +	}
  +	return null;
  +    }
  +
  +    /**
        * Returns the appropriate extends text
        * 
        * @return "" or "abstract "
  @@ -706,8 +760,9 @@
                       + "(_value)." + simpleValueType + "Value();");
           } else {
               if (simpleValueType.equals("byte[]")) {
  +	        String encoder = getBinaryTypeEncoderName ("_value");
                   pw.println("        " + returnString
  -                        + " org.apache.axis.types.HexBinary.decode(_value);");
  +                        + " " + encoder + ".decode(_value);");
               } else if (simpleValueType.equals("org.apache.axis.types.URI")) {
                   pw.println("        try {");
                   pw.println("            " + returnString
  @@ -784,8 +839,10 @@
               } else {
                   String simpleValueType0 = (String)simpleValueTypes.get(0); 
                   if (simpleValueType0.equals("byte[]")) {
  +	            String encoder = getBinaryTypeEncoderName ("_value");
                       pw.println(
  -                            "        return _value == null ? null : org.apache.axis.types.HexBinary.encode(_value);");
  +                            "        return _value == null ? null : " +
  +			    encoder + ".encode(_value);");
                   } else if (simpleValueType0.equals("java.util.Calendar")) {
                       pw.println(
                               "        return _value == null ? null : new org.apache.axis.encoding.ser.CalendarSerializer().getValueAsString(_value, null);");
  @@ -814,8 +871,10 @@
                       + "(_value).toString();");
           } else {
               if (simpleValueType.equals("byte[]")) {
  +		String encoder = getBinaryTypeEncoderName ("_value");
                   pw.println(
  -                        "        this._value = _value == null ? null : org.apache.axis.types.HexBinary.encode(_value);");
  +                        "        this._value = _value == null ? null : " +
  +			encoder + ".encode(_value);");
               } else if (simpleValueType.equals("java.util.Calendar")) {
                   pw.println(
                           "        this._value = _value == null ? null : new org.apache.axis.encoding.ser.CalendarSerializer().getValueAsString(_value, null);");
  
  
  
  1.56      +11 -1     ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaGeneratorFactory.java
  
  Index: JavaGeneratorFactory.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaGeneratorFactory.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- JavaGeneratorFactory.java	22 Aug 2004 03:07:01 -0000	1.55
  +++ JavaGeneratorFactory.java	2 Sep 2004 12:15:59 -0000	1.56
  @@ -569,7 +569,17 @@
               // set typeQName to the value of the itemType attribute.
               QName itemType = SchemaUtils.getListItemType(tEntry.getNode());
               if (itemType != null) {
  -                typeQName = itemType;
  +                // Get the typeEntry so we know the absolute base type
  +                TypeEntry itemEntry = symbolTable.getTypeEntry(itemType, false);
  +		// TODO - If the itemEntry is not found, we need to throw
  +		// an exception.  "Item is referenced, but not defined"
  +                javifyTypeEntryName(symbolTable, itemEntry, anonQNames, uniqueNum);
  +                // Grab the referenced type, If it's there.
  +                TypeEntry refedEntry = itemEntry.getRefType();
  +                QName baseName = refedEntry == null ? itemEntry.getQName() : 
  +                        refedEntry.getQName();
  +                typeQName = new QName(baseName.getNamespaceURI(),
  +                                        baseName.getLocalPart() + "[]");
               }
   
               if ((typeQName.getLocalPart().
  
  
  
  1.4       +6 -2      ws-axis/java/src/org/apache/axis/encoding/ser/SimpleListDeserializer.java
  
  Index: SimpleListDeserializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/SimpleListDeserializer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleListDeserializer.java	23 Mar 2004 10:45:06 -0000	1.3
  +++ SimpleListDeserializer.java	2 Sep 2004 12:15:59 -0000	1.4
  @@ -15,6 +15,7 @@
    */
   
   package org.apache.axis.encoding.ser;
  +
   import java.lang.reflect.Array;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.InvocationTargetException;
  @@ -29,7 +30,6 @@
   import org.apache.axis.description.TypeDesc;
   import org.apache.axis.encoding.DeserializationContext;
   import org.apache.axis.encoding.Deserializer;
  -import org.apache.axis.encoding.DeserializerImpl;
   import org.apache.axis.encoding.SimpleType;
   import org.apache.axis.encoding.TypeMapping;
   import org.apache.axis.message.SOAPHandler;
  @@ -47,7 +47,7 @@
    *
    * @author Ias (iasandcb@tmax.co.kr)
    */
  -public class SimpleListDeserializer extends DeserializerImpl {
  +public class SimpleListDeserializer extends SimpleDeserializer {
   
       StringBuffer val = new StringBuffer();
       private Constructor constructor = null;
  @@ -67,10 +67,14 @@
        * javaType (which could be a java primitive like int.class)
        */
       public SimpleListDeserializer(Class javaType, QName xmlType) {
  +        super (javaType, xmlType);
  +
           this.xmlType = xmlType;
           this.javaType = javaType;
       }
       public SimpleListDeserializer(Class javaType, QName xmlType, TypeDesc typeDesc) {
  +        super (javaType, xmlType, typeDesc);
  +
           this.xmlType = xmlType;
           this.javaType = javaType;
           this.typeDesc = typeDesc;