ws-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Webster Mudge <wmu...@cloudera.com>
Subject NPE walking Purchase Order example
Date Fri, 07 Sep 2018 18:15:16 GMT
Hello all,

I’m running into a NPE when I try to walk a XSD using the xmlschema-walker module.  I have
been able to use the walker module to go through other schemas, but most fail with this error.
 Any pointers to what I am doing wrong?

Thanks,
Webster

== Test code

Run as Junit test within IDEA.

XmlSchemaCollection collection = new XmlSchemaCollection();
XmlSchema xmlSchema = collection.read(new InputStreamReader(PO_SCHEMA));

XmlSchemaVisitor xmlSchemaVisitor = new XmlSchemaVisitor() { // … noop };

XmlSchemaWalker walker = new XmlSchemaWalker(collection);
walker.addVisitor(xmlSchemaVisitor);

XmlSchemaElement root = xmlSchema.getElementByName("purchaseOrder");

walker.walk(root);

== Stacktrace

java.lang.NullPointerException
	at org.apache.ws.commons.schema.utils.XmlSchemaNamedImpl.setName(XmlSchemaNamedImpl.java:125)
	at org.apache.ws.commons.schema.utils.XmlSchemaNamedWithFormImpl.setName(XmlSchemaNamedWithFormImpl.java:113)
	at org.apache.ws.commons.schema.XmlSchemaAttribute$2.run(XmlSchemaAttribute.java:146)
	at org.apache.ws.commons.schema.utils.CollectionFactory.withSchemaModifiable(CollectionFactory.java:123)
	at org.apache.ws.commons.schema.XmlSchemaAttribute.setName(XmlSchemaAttribute.java:140)
	at org.apache.ws.commons.schema.walker.XmlSchemaScope.getAttribute(XmlSchemaScope.java:607)
	at org.apache.ws.commons.schema.walker.XmlSchemaScope.createAttributeMap(XmlSchemaScope.java:637)
	at org.apache.ws.commons.schema.walker.XmlSchemaScope.walk(XmlSchemaScope.java:316)
	at org.apache.ws.commons.schema.walker.XmlSchemaScope.walk(XmlSchemaScope.java:151)
	at org.apache.ws.commons.schema.walker.XmlSchemaScope.<init>(XmlSchemaScope.java:112)
	at org.apache.ws.commons.schema.walker.XmlSchemaWalker.walk(XmlSchemaWalker.java:224)

== Schema

Cut from the XML Schema spec:

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:annotation>
    <xsd:documentation xml:lang="en">
      Purchase order schema for Example.com.
      Copyright 2000 Example.com. All rights reserved.
    </xsd:documentation>
  </xsd:annotation>

  <xsd:element name="purchaseOrder" type="PurchaseOrderType"/>

  <xsd:element name="comment" type="xsd:string"/>

  <xsd:complexType name="PurchaseOrderType">
    <xsd:sequence>
      <xsd:element name="shipTo" type="USAddress"/>
      <xsd:element name="billTo" type="USAddress"/>
      <xsd:element ref="comment" minOccurs="0"/>
      <xsd:element name="items"  type="Items"/>
    </xsd:sequence>
    <xsd:attribute name="orderDate" type="xsd:date"/>
  </xsd:complexType>

  <xsd:complexType name="USAddress">
    <xsd:sequence>
      <xsd:element name="name"   type="xsd:string"/>
      <xsd:element name="street" type="xsd:string"/>
      <xsd:element name="city"   type="xsd:string"/>
      <xsd:element name="state"  type="xsd:string"/>
      <xsd:element name="zip"    type="xsd:decimal"/>
    </xsd:sequence>
    <xsd:attribute name="country" type="xsd:NMTOKEN"
                   fixed="US"/>
  </xsd:complexType>

  <xsd:complexType name="Items">
    <xsd:sequence>
      <xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="productName" type="xsd:string"/>
            <xsd:element name="quantity">
              <xsd:simpleType>
                <xsd:restriction base="xsd:positiveInteger">
                  <xsd:maxExclusive value="100"/>
                </xsd:restriction>
              </xsd:simpleType>
            </xsd:element>
            <xsd:element name="USPrice"  type="xsd:decimal"/>
            <xsd:element ref="comment"   minOccurs="0"/>
            <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
          </xsd:sequence>
          <xsd:attribute name="partNum" type="SKU" use="required"/>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>

  <!-- Stock Keeping Unit, a code for identifying products -->
  <xsd:simpleType name="SKU">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\d{3}-[A-Z]{2}"/>
    </xsd:restriction>
  </xsd:simpleType>

</xsd:schema>
Mime
View raw message