You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by da...@apache.org on 2004/03/28 00:59:41 UTC

cvs commit: xml-xmlbeans/v2/test/cases/schema/typesonly typesonly.xsd

daveremy    2004/03/27 15:59:41

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        Schema2Java.java
               v2/test/cases/schema/typesonly typesonly.xsd
  Log:
  Groundwork for SOAP array support in JAX-RPC binding Schema2Java.
  Added one extra test.
  Contributed by Radu Preotiuc.
  
  Revision  Changes    Path
  1.19      +65 -18    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2Java.java
  
  Index: Schema2Java.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2Java.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Schema2Java.java	25 Mar 2004 22:00:28 -0000	1.18
  +++ Schema2Java.java	27 Mar 2004 23:59:41 -0000	1.19
  @@ -280,17 +280,17 @@
         } else if (sType.isDocumentType()) {
           scratch = new Scratch(sType, XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, sType.getDocumentElementName()), Scratch.ELEMENT);
         } else if (sType.isAttributeType()) {
  -        scratch = new Scratch(sType, XmlTypeName.forGlobalName(XmlTypeName.ATTRIBUTE, sType.getDocumentElementName()), Scratch.ATTRIBUTE);
  +        scratch = new Scratch(sType, XmlTypeName.forGlobalName(XmlTypeName.ATTRIBUTE, sType.getAttributeTypeAttributeName()), Scratch.ATTRIBUTE);
         } else if (isSoapArray(sType)) {
           scratch = new Scratch(sType, xmlName, Scratch.SOAPARRAY_REF);
  -        xmlName = soapArrayTypeName(sType);
  -        scratch.setAsIf(xmlName);
  +        XmlTypeName altXmlName = soapArrayTypeName(sType);
  +        scratch.setAsIf(altXmlName);
   
           // soap arrays unroll like this
  -        while (xmlName.getComponentType() == XmlTypeName.SOAP_ARRAY) {
  -          scratch = new Scratch(null, xmlName, Scratch.SOAPARRAY);
  -          scratchFromXmlName.put(xmlName, scratch);
  -          xmlName = xmlName.getOuterComponent();
  +        while (altXmlName.getComponentType() == XmlTypeName.SOAP_ARRAY) {
  +          Scratch altScratch = new Scratch(sType, altXmlName, Scratch.SOAPARRAY);
  +          scratchFromXmlName.put(altXmlName, altScratch);
  +          altXmlName = altXmlName.getOuterComponent();
           }
         } else if (isLiteralArray(sType)) {
           scratch = new Scratch(sType, xmlName, Scratch.LITERALARRAY_TYPE);
  @@ -399,8 +399,20 @@
             XmlTypeName arrayName = scratch.getXmlName();
             XmlTypeName itemName = arrayName.getOuterComponent();
             Scratch itemScratch = scratchForXmlName(itemName);
  -          resolveJavaName(itemScratch);
  -          scratch.setJavaName(JavaTypeName.forArray(itemScratch.getJavaName(), arrayName.getNumber()));
  +          JavaTypeName itemJavaName = null;
  +          if (itemScratch == null) {
  +              itemJavaName = getTypeNameFromLoader(itemName);
  +              if (itemJavaName == null) {
  +                logError("Could not find reference to type \"" +
  +                  itemName.getQName() + "\"", null, scratch.getSchemaType());
  +                itemJavaName = JavaTypeName.forString("unknown");
  +              }
  +          }
  +          else {
  +              resolveJavaName(itemScratch);
  +              itemJavaName = itemScratch.getJavaName();
  +          }
  +          scratch.setJavaName(JavaTypeName.forArray(itemJavaName, arrayName.getNumber()));
             return;
           }
   
  @@ -515,7 +527,10 @@
           break;
   
         case Scratch.SOAPARRAY:
  -        throw new UnsupportedOperationException();
  +        WrappedArrayType soapArray = new WrappedArrayType(btName);
  +        scratch.setBindingType(soapArray);
  +        bindingFile.addBindingType(soapArray, shouldBeFromJavaDefault(btName), false);
  +        break;
   
         default:
           throw new IllegalStateException("Unrecognized category");
  @@ -698,7 +713,8 @@
     private void resolveJavaArray(Scratch scratch)
     {
       if (scratch.getCategory() != Scratch.LITERALARRAY_TYPE &&
  -        scratch.getCategory() != Scratch.LIST_TYPE)
  +        scratch.getCategory() != Scratch.LIST_TYPE &&
  +        scratch.getCategory() != Scratch.SOAPARRAY)
         return;
   
       if (scratch.isStructureResolved())
  @@ -709,6 +725,38 @@
       BindingType scratchBindingType = scratch.getBindingType();
       if (scratchBindingType instanceof WrappedArrayType) {
         WrappedArrayType bType = (WrappedArrayType) scratchBindingType;
  +      // todo: fix this
  +      if (scratch.getCategory() == Scratch.SOAPARRAY) {
  +        XmlTypeName typexName = scratch.getXmlName();
  +        XmlTypeName itemxName = typexName.getOuterComponent();
  +        Scratch itemxScratch = scratchForXmlName(itemxName);
  +        BindingType itemxType;
  +        if (itemxScratch == null)
  +          itemxType = mLoader.getBindingType(mLoader.lookupPojoFor(itemxName));
  +        else
  +          itemxType = itemxScratch.getBindingType();
  +        // The rule is: if the soap array type looks like a literal array
  +        // then the name and nillability are the same as for literal arrays
  +        // Otherwise, the name is not significant and nillability is false
  +        if (getLiteralArrayItemType(scratch.getSchemaType()) == null) {
  +          bType.setItemName(new QName("", "foo"));
  +          bType.setItemNillable(false);
  +        }
  +        else {
  +          SchemaProperty prop = scratch.getSchemaType().getProperties()[0];
  +          bType.setItemName(prop.getName());
  +          bType.setItemNillable(prop.hasNillable() != SchemaProperty.NEVER);
  +        }
  +
  +        if (itemxType != null) {
  +          if (bType.isItemNillable())
  +            itemxType = findBoxedType(itemxType);
  +          bType.setItemType(itemxType.getName());
  +        }
  +        else
  +          bType.setItemType(bType.getName());
  +        return;
  +      }
         JavaTypeName itemName = scratch.getJavaName().getArrayItemType(1);
         assert(itemName != null);
         SchemaType sType = getLiteralArrayItemType(scratch.getSchemaType());
  @@ -1122,16 +1170,15 @@
      * if it cannot find the type
      */
     private JavaTypeName getTypeNameFromLoader(SchemaType sType) {
  +    return getTypeNameFromLoader(XmlTypeName.forSchemaType(sType));
  +  }
  +
  +  private JavaTypeName getTypeNameFromLoader(XmlTypeName typeName) {
       BindingType bType = mLoader.getBindingType(mLoader.
  -      lookupPojoFor(XmlTypeName.forSchemaType(sType)));
  +      lookupPojoFor(typeName));
       if (bType != null)
         return bType.getName().getJavaName();
  -    else if (sType.isBuiltinType())
  -      logError("Bultin type " + sType.getName() + " is not supported",
  -        null, sType);
  -    else
  -      throw new IllegalStateException(sType.getName().toString()+
  -        " type is not on mLoader");
  +
       return null;
     }
   
  
  
  
  1.3       +21 -1     xml-xmlbeans/v2/test/cases/schema/typesonly/typesonly.xsd
  
  Index: typesonly.xsd
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/schema/typesonly/typesonly.xsd,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- typesonly.xsd	28 Oct 2003 17:51:27 -0000	1.2
  +++ typesonly.xsd	27 Mar 2004 23:59:41 -0000	1.3
  @@ -35,6 +35,26 @@
     </xs:complexType>
   
     <xs:element name="record" type="mt:person"/>
  -    
  +  
  +  <xs:simpleType name="State">
  +    <xs:restriction base="xs:string">
  +      <xs:enumeration value="AK"/>
  +      <xs:enumeration value="AL"/>
  +      <xs:enumeration value="AS"/>
  +      <xs:enumeration value="AZ"/>
  +    </xs:restriction>
  +  </xs:simpleType>
  +
  +  <xs:simpleType name="ListOfStates">
  +    <xs:list itemType="mt:State"/>
  +  </xs:simpleType>
  +  
  +  <xs:complexType name="candidate">
  +    <xs:sequence>
  +      <xs:element name="name" type="xs:string"/>
  +      <xs:element name="states" type="mt:ListOfStates"/>
  +    </xs:sequence>
  +  </xs:complexType>
  +  
   </xs:schema>
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org