Better handling of java.lang.Calendar for XML Schema types date & dateTime. BLD200301070100
authorcliffwd@netbeans.org
Mon, 06 Jan 2003 21:55:33 +0000
changeset 115839d2cd841cfc
parent 1157 09260ca2dc52
child 1159 0fc15b139528
Better handling of java.lang.Calendar for XML Schema types date & dateTime.
Element annotations from XML Schema are put into generated class.
Fix bug in merging of comments where graphManger might be null.
Added simple find by (XML Schema) key method in pure JavaBeans. It only works with simple xpath expressions.
Added XML Schema parsing of totalDigits, minInclusive, maxInclusive, fractionDigits, & length.
Fixed bug 29757. Invoice test case now added to tests.
schema2beans/test/unit/src/TestMain.java
schema2beans/test/unit/src/data/TestInvoice.java
schema2beans/test/unit/src/data/TestInvoice.xml
schema2beans/test/unit/src/data/TestInvoice.xsd
schema2beans/test/unit/src/data/TestWebApp.xsd
schema2beans/test/unit/src/data/goldenfiles/TestMain/testInvoice.pass
     1.1 --- a/schema2beans/test/unit/src/TestMain.java	Mon Jan 06 14:56:12 2003 +0000
     1.2 +++ b/schema2beans/test/unit/src/TestMain.java	Mon Jan 06 21:55:33 2003 +0000
     1.3 @@ -39,6 +39,10 @@
     1.4          generalTest("TestPurchaseOrder", true, true, true);
     1.5      }
     1.6      
     1.7 +    public void testInvoice() throws IOException, Schema2BeansException, InterruptedException {
     1.8 +        generalTest("TestInvoice", true, true, true);
     1.9 +    }
    1.10 +    
    1.11      public void testBookXMLSchema() throws IOException, Schema2BeansException, InterruptedException {
    1.12          generalTest("TestBookXMLSchema", true, false, false);
    1.13      }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/schema2beans/test/unit/src/data/TestInvoice.java	Mon Jan 06 21:55:33 2003 +0000
     2.3 @@ -0,0 +1,52 @@
     2.4 +/*
     2.5 + *	TestInvoice - test the basic features.
     2.6 + *
     2.7 + *	The following test assumes that we know the content of the
     2.8 + *	graph as we get elements, add and change them. Therefore, the TestInvoice.xml
     2.9 + *	file and this java test should be kept in sync.
    2.10 + *
    2.11 + */
    2.12 +
    2.13 +import java.io.*;
    2.14 +import java.util.*;
    2.15 +import org.w3c.dom.*;
    2.16 +
    2.17 +import invoice.*;
    2.18 +
    2.19 +
    2.20 +public class TestInvoice extends BaseTest {
    2.21 +    public static void main(String[] argv) {
    2.22 +        TestInvoice o = new TestInvoice();
    2.23 +        if (argv.length > 0)
    2.24 +            o.setDocumentDir(argv[0]);
    2.25 +        try {
    2.26 +            o.run();
    2.27 +        } catch (Exception e) {
    2.28 +            e.printStackTrace();
    2.29 +            System.exit(1);
    2.30 +        }
    2.31 +        System.exit(0);
    2.32 +    }
    2.33 +    
    2.34 +    public void run() throws Exception {
    2.35 +        Invoice invoice;
    2.36 +
    2.37 +        this.readDocument();
    2.38 +
    2.39 +        out("creating the bean graph");
    2.40 +        invoice = Invoice.read(doc);
    2.41 +	
    2.42 +        //	Check that we can read the graph an it is complete
    2.43 +        out("bean graph created");
    2.44 +        invoice.write(out);
    2.45 +
    2.46 +        out("Adding an item");
    2.47 +        Item item = new Item();
    2.48 +        item.setId("123");
    2.49 +        item.setCategory("office");
    2.50 +        item.setQuantity(new java.math.BigInteger("10"));
    2.51 +        item.setPrice(new java.math.BigDecimal("15.99"));
    2.52 +        invoice.addItem(item);
    2.53 +        invoice.write(out);
    2.54 +    }
    2.55 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/schema2beans/test/unit/src/data/TestInvoice.xml	Mon Jan 06 21:55:33 2003 +0000
     3.3 @@ -0,0 +1,26 @@
     3.4 +<?xml version='1.0' encoding='UTF-8' ?>
     3.5 +<invoice>
     3.6 +	<ship-to>
     3.7 +		<name>Cliff</name>
     3.8 +		<address>
     3.9 +			<street1>1800 Harrison St.</street1>
    3.10 +			<city>Oakland</city>
    3.11 +			<state>CA</state>
    3.12 +			<zip-code>94404</zip-code>
    3.13 +		</address>
    3.14 +		<phone>800 236-9564</phone>
    3.15 +	</ship-to>
    3.16 +    <item Id="45623" InStock="true" Category="toy">
    3.17 +		<Quantity>3</Quantity>
    3.18 +		<Price>9.99</Price>
    3.19 +	</item>
    3.20 +	<shipping-method>
    3.21 +		<carrier>FedEx</carrier>
    3.22 +		<option>Fast</option>
    3.23 +		<estimated-delivery>P1D</estimated-delivery>
    3.24 +	</shipping-method>
    3.25 +	<shipping-date>
    3.26 +		<date>2002-10-25</date>
    3.27 +		<time>10:21:00</time>
    3.28 +	</shipping-date>
    3.29 +</invoice>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/schema2beans/test/unit/src/data/TestInvoice.xsd	Mon Jan 06 21:55:33 2003 +0000
     4.3 @@ -0,0 +1,146 @@
     4.4 +<?xml version="1.0"?>
     4.5 +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
     4.6 +
     4.7 +   <xsd:annotation>
     4.8 +      <xsd:documentation>
     4.9 +         This is a test XML Schema for Castor XML.
    4.10 +      </xsd:documentation>
    4.11 +   </xsd:annotation>
    4.12 +
    4.13 +   <!--
    4.14 +       A simple representation of an invoice. This is simply an example
    4.15 +       and not meant to be an exact or even complete representation of an invoice.
    4.16 +     -->
    4.17 +   	
    4.18 +   <!-- Shipping Method -->
    4.19 +   <xsd:element name="shipping-method">
    4.20 +      <xsd:complexType>
    4.21 +      	  <xsd:sequence>
    4.22 +          	<xsd:element name="carrier" type="xsd:string"/>
    4.23 +          	<xsd:element name="option"  type="xsd:string"/>
    4.24 +          	<xsd:element name="estimated-delivery" type="xsd:duration"/>
    4.25 +      	  </xsd:sequence>
    4.26 +      </xsd:complexType>
    4.27 +   </xsd:element>
    4.28 +
    4.29 +   <!-- Shipping date -->
    4.30 +   <xsd:element name="shipping-date">
    4.31 +   		<xsd:complexType>
    4.32 +   			<xsd:sequence>
    4.33 +   				<xsd:element name="date" type="xsd:date"/>
    4.34 +   				<xsd:element name="time" type="xsd:time"/>
    4.35 +   			</xsd:sequence>
    4.36 +   		</xsd:complexType>
    4.37 +   	</xsd:element>
    4.38 +   
    4.39 +   <!-- A simple U.S. based Address structure -->
    4.40 +   <xsd:element name="address">
    4.41 +      <xsd:annotation>
    4.42 +         <xsd:documentation>
    4.43 +            Represents a U.S. Address
    4.44 +         </xsd:documentation>
    4.45 +      </xsd:annotation>
    4.46 +
    4.47 +      <xsd:complexType>
    4.48 +      	 <xsd:sequence>
    4.49 +         	<!-- street address 1 -->
    4.50 +         	<xsd:element name="street1" type="xsd:string"/>
    4.51 +         	<!-- optional street address 2 -->
    4.52 +         	<xsd:element name="street2" type="xsd:string" minOccurs="0"/>
    4.53 +         	<!-- city-->
    4.54 +         	<xsd:element name="city" type="xsd:string"/>
    4.55 +         	<!-- state code -->
    4.56 +         	<xsd:element name="state" type="stateCodeType"/>
    4.57 +         	<!-- zip-code -->
    4.58 +         	<xsd:element ref="zip-code"/>
    4.59 +      	</xsd:sequence>
    4.60 +      </xsd:complexType>
    4.61 +   </xsd:element>
    4.62 +
    4.63 +   <!-- A U.S. Zip Code -->
    4.64 +   <xsd:element name="zip-code">
    4.65 +      <xsd:simpleType>
    4.66 +         <xsd:restriction base="xsd:string">
    4.67 +        	 <xsd:pattern value="[0-9]{5}(-[0-9]{4})?"/>
    4.68 +      	 </xsd:restriction>
    4.69 +      </xsd:simpleType>
    4.70 +   </xsd:element>
    4.71 +
    4.72 +   <!-- State Code
    4.73 +        obviously not a valid state code....but this is just
    4.74 +        an example and I don't feel like creating all the valid
    4.75 +        ones.
    4.76 +    -->
    4.77 +	<xsd:simpleType name="stateCodeType">
    4.78 +		<xsd:restriction base="xsd:string">
    4.79 +      		<xsd:pattern value="[A-Z]{2}"/>
    4.80 +   		</xsd:restriction>
    4.81 +   </xsd:simpleType>
    4.82 +   
    4.83 +   <!-- Telephone Number -->
    4.84 +   <xsd:simpleType name="TelephoneNumberType">
    4.85 +   		<xsd:restriction base="xsd:string">
    4.86 +   			<xsd:length value="12"/>
    4.87 +   			<xsd:pattern value="[0-9]{3}-[0-9]{3}-[0-9]{4}"/>
    4.88 +   		</xsd:restriction>
    4.89 +   </xsd:simpleType> 
    4.90 +
    4.91 +   <!-- Cool price type -->
    4.92 +   <xsd:simpleType name="PriceType">
    4.93 +   		<xsd:restriction base="xsd:decimal">
    4.94 +   			<xsd:fractionDigits value="2"/>
    4.95 +    		        <xsd:totalDigits value="5"/>
    4.96 +    		        <xsd:minInclusive value="1"/>
    4.97 +   			<xsd:maxInclusive value="100"/>
    4.98 +   		</xsd:restriction>
    4.99 +   </xsd:simpleType>
   4.100 +
   4.101 +   <!-- The attributes for an Item -->
   4.102 +   <xsd:attributeGroup name="ItemAttributes">
   4.103 +        <xsd:attribute name="Id" type="xsd:ID" use="required"/>
   4.104 +   	<xsd:attribute name="InStock" type="xsd:boolean" default="false"/>
   4.105 +   	<xsd:attribute name="Category" type="xsd:string" use="required"/>
   4.106 +    </xsd:attributeGroup>
   4.107 +
   4.108 +   <xsd:element name="invoice">
   4.109 +      <xsd:annotation>
   4.110 +         <xsd:documentation>
   4.111 +             A simple representation of an invoice
   4.112 +         </xsd:documentation>
   4.113 +      </xsd:annotation>
   4.114 +
   4.115 +      <xsd:complexType>
   4.116 +      	 <xsd:sequence>
   4.117 +      		<xsd:element name="ship-to">
   4.118 +            	<xsd:complexType>
   4.119 +                 	<xsd:group ref="customer"/>
   4.120 +                </xsd:complexType>
   4.121 +         	</xsd:element>
   4.122 +        	<xsd:element ref="item" maxOccurs="unbounded" minOccurs="1"/>
   4.123 +        	<xsd:element ref="shipping-method"/>
   4.124 +        	<xsd:element ref="shipping-date"/>
   4.125 +      	</xsd:sequence>
   4.126 +      </xsd:complexType>
   4.127 +   </xsd:element>
   4.128 +
   4.129 +   <!-- Description of a customer -->
   4.130 +   <xsd:group name="customer">
   4.131 +        <xsd:sequence>
   4.132 +             <xsd:element name="name" type="xsd:string"/>
   4.133 +             <xsd:element ref="address"/>
   4.134 +             <xsd:element name="phone" type="TelephoneNumberType"/>
   4.135 +         </xsd:sequence>
   4.136 +	</xsd:group>
   4.137 +  
   4.138 +   <!-- Description of an item -->
   4.139 +   <xsd:element name="item">
   4.140 +   		<xsd:complexType>
   4.141 +   			<xsd:sequence>
   4.142 +   				<xsd:element name="Quantity" type="xsd:integer" minOccurs="1" maxOccurs="1"/>
   4.143 +        		<xsd:element name="Price" type="PriceType" minOccurs="1" maxOccurs="1"/>
   4.144 +    		</xsd:sequence>
   4.145 +    		<xsd:attributeGroup ref="ItemAttributes"/>
   4.146 +    	</xsd:complexType>
   4.147 +   	</xsd:element>
   4.148 +
   4.149 +</xsd:schema>
     5.1 --- a/schema2beans/test/unit/src/data/TestWebApp.xsd	Mon Jan 06 14:56:12 2003 +0000
     5.2 +++ b/schema2beans/test/unit/src/data/TestWebApp.xsd	Mon Jan 06 21:55:33 2003 +0000
     5.3 @@ -1111,7 +1111,12 @@
     5.4  
     5.5          <xsd:element name="filter"
     5.6                       type="j2ee:filterType"
     5.7 -                     minOccurs="0" maxOccurs="unbounded"/>
     5.8 +                     minOccurs="0" maxOccurs="unbounded">
     5.9 + 		   <xsd:key name="param-key">
    5.10 + 		      <xsd:selector xpath="init-param"/>
    5.11 + 		      <xsd:field xpath="param-name"/>
    5.12 + 		  </xsd:key>
    5.13 + 		</xsd:element>
    5.14          <xsd:element name="filter-mapping"
    5.15                       type="j2ee:filter-mappingType"
    5.16                       minOccurs="0"
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/schema2beans/test/unit/src/data/goldenfiles/TestMain/testInvoice.pass	Mon Jan 06 21:55:33 2003 +0000
     6.3 @@ -0,0 +1,64 @@
     6.4 +Calling GenBeans.doIt
     6.5 +Compiling
     6.6 +Finished compiling: 0
     6.7 +out: TestInvoice - creating the DOM document
     6.8 +out: TestInvoice - creating the bean graph
     6.9 +out: TestInvoice - bean graph created
    6.10 +out: <?xml version='1.0' encoding='UTF-8' ?>
    6.11 +out: <invoice>
    6.12 +out: 	<ship-to>
    6.13 +out: 		<name>Cliff</name>
    6.14 +out: 		<address>
    6.15 +out: 			<street1>1800 Harrison St.</street1>
    6.16 +out: 			<city>Oakland</city>
    6.17 +out: 			<state>CA</state>
    6.18 +out: 			<zip-code>94404</zip-code>
    6.19 +out: 		</address>
    6.20 +out: 		<phone>800 236-9564</phone>
    6.21 +out: 	</ship-to>
    6.22 +out: 	<item Id='45623' InStock='true' Category='toy'>
    6.23 +out: 		<Quantity>3</Quantity>
    6.24 +out: 		<Price>9.99</Price>
    6.25 +out: 	</item>
    6.26 +out: 	<shipping-method>
    6.27 +out: 		<carrier>FedEx</carrier>
    6.28 +out: 		<option>Fast</option>
    6.29 +out: 		<estimated-delivery>P1D</estimated-delivery>
    6.30 +out: 	</shipping-method>
    6.31 +out: 	<shipping-date>
    6.32 +out: 		<date>2002-10-25</date>
    6.33 +out: 		<time>10:21:00</time>
    6.34 +out: 	</shipping-date>
    6.35 +out: </invoice>
    6.36 +out: TestInvoice - Adding an item
    6.37 +out: <?xml version='1.0' encoding='UTF-8' ?>
    6.38 +out: <invoice>
    6.39 +out: 	<ship-to>
    6.40 +out: 		<name>Cliff</name>
    6.41 +out: 		<address>
    6.42 +out: 			<street1>1800 Harrison St.</street1>
    6.43 +out: 			<city>Oakland</city>
    6.44 +out: 			<state>CA</state>
    6.45 +out: 			<zip-code>94404</zip-code>
    6.46 +out: 		</address>
    6.47 +out: 		<phone>800 236-9564</phone>
    6.48 +out: 	</ship-to>
    6.49 +out: 	<item Id='45623' InStock='true' Category='toy'>
    6.50 +out: 		<Quantity>3</Quantity>
    6.51 +out: 		<Price>9.99</Price>
    6.52 +out: 	</item>
    6.53 +out: 	<item Id='123' InStock='false' Category='office'>
    6.54 +out: 		<Quantity>10</Quantity>
    6.55 +out: 		<Price>15.99</Price>
    6.56 +out: 	</item>
    6.57 +out: 	<shipping-method>
    6.58 +out: 		<carrier>FedEx</carrier>
    6.59 +out: 		<option>Fast</option>
    6.60 +out: 		<estimated-delivery>P1D</estimated-delivery>
    6.61 +out: 	</shipping-method>
    6.62 +out: 	<shipping-date>
    6.63 +out: 		<date>2002-10-25</date>
    6.64 +out: 		<time>10:21:00</time>
    6.65 +out: 	</shipping-date>
    6.66 +out: </invoice>
    6.67 +Finished running TestInvoice: 0