# HG changeset patch
# User wleggette
# Date 1238644343 18000
# Branch clean
# Node ID 8087234c303e87ad4a915d9b4543ae27306e5a60
# Parent  1a589b49b118349cf54ebeee8f036ac32bfbe9dc
imported patch user-types-test.patch

diff -r 1a589b49b118 -r 8087234c303e 
test/cases/xbean/usertype/averageCase/po.xsd
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/test/cases/xbean/usertype/averageCase/po.xsd      Wed Apr 01 22:52:23 
2009 -0500
@@ -0,0 +1,62 @@
+<!-- edited with XMLSPY v5 rel. 2 U (http://www.xmlspy.com) by Michael Kintzer 
(BEA Systems) -->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+xmlns:po="http://xbean.usertype/averageCase/PurchaseOrder";
+targetNamespace="http://xbean.usertype/averageCase/PurchaseOrder";
+elementFormDefault="qualified"
+>
+       <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="po:PurchaseOrderType"/>
+       <xsd:element name="comment" type="xsd:string"/>
+       <xsd:complexType name="PurchaseOrderType">
+               <xsd:sequence>
+                       <xsd:element name="shipTo" type="po:USAddress"/>
+                       <xsd:element name="billTo" type="po:USAddress"/>
+                       <xsd:element ref="po:comment" minOccurs="0"/>
+                       <xsd:element name="items" type="po: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" 
nillable="true"/>
+                       <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="po:comment" 
minOccurs="0"/>
+                                               <xsd:element name="shipDate" 
type="xsd:date" minOccurs="0"/>
+                                       </xsd:sequence>
+                                       <xsd:attribute name="partNum" 
type="po: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>
diff -r 1a589b49b118 -r 8087234c303e 
test/cases/xbean/usertype/averageCase/po.xsdconfig
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/test/cases/xbean/usertype/averageCase/po.xsdconfig        Wed Apr 01 
22:52:23 2009 -0500
@@ -0,0 +1,21 @@
+<!-- Copyright 2004 The Apache Software Foundation
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License. -->
+<xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config";
+xmlns:po="http://xbean.usertype/averageCase/PurchaseOrder";>
+
+    <xb:usertype name="po:SKU" 
javaname="xmlobject.usertype.averageCase.existing.SKU">
+        
<xb:staticHandler>xmlobject.usertype.averageCase.existing.SKUHandler</xb:staticHandler>
+    </xb:usertype>
+
+</xb:config>
\ No newline at end of file
diff -r 1a589b49b118 -r 8087234c303e 
test/cases/xbean/usertype/multipleItems/company.xsd
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/test/cases/xbean/usertype/multipleItems/company.xsd       Wed Apr 01 
22:52:23 2009 -0500
@@ -0,0 +1,40 @@
+<xsd:schema targetNamespace="http://xbean.usertype/multipleItems/company";
+       xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:company="http://xbean.usertype/multipleItems/company";>
+       <xsd:element name="company" type="company:CompanyType" />
+       <xsd:complexType name="CompanyType">
+               <xsd:sequence>
+                       <xsd:element name="departments" 
type="company:DepartmentType"
+                               maxOccurs="unbounded" />
+               </xsd:sequence>
+
+               <xsd:anyAttribute namespace="http://www.omg.org/XMI";
+                       processContents="lax" />
+       </xsd:complexType>
+       <xsd:element name="department" type="company:DepartmentType" />
+       <xsd:complexType name="DepartmentType">
+               <xsd:sequence>
+                       <xsd:element name="consultant" 
type="company:ConsultantType"
+                               maxOccurs="unbounded" />
+               </xsd:sequence>
+               <xsd:anyAttribute namespace="http://www.omg.org/XMI";
+                       processContents="lax" />
+       </xsd:complexType>
+       <xsd:complexType name="ConsultantType">
+               <xsd:sequence>
+                       <xsd:element name="room" type="company:Room" 
maxOccurs="unbounded" />
+               </xsd:sequence>
+               <xsd:attribute name="name" type="xsd:string" />
+               <xsd:attribute name="age" type="xsd:integer" />
+               <xsd:anyAttribute namespace="http://www.omg.org/XMI";
+                       processContents="lax" />
+
+
+       </xsd:complexType>
+
+
+       <xsd:simpleType name="Room">
+               <xsd:restriction base="xsd:string">
+                       <xsd:pattern value="\d{3}-[A-Z]{2}" />
+               </xsd:restriction>
+       </xsd:simpleType>
+</xsd:schema>
diff -r 1a589b49b118 -r 8087234c303e 
test/cases/xbean/usertype/multipleItems/company.xsdconfig
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/test/cases/xbean/usertype/multipleItems/company.xsdconfig Wed Apr 01 
22:52:23 2009 -0500
@@ -0,0 +1,21 @@
+<!-- Copyright 2004 The Apache Software Foundation
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License. -->
+<xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config";
+xmlns:company="http://xbean.usertype/multipleItems/company";>
+
+    <xb:usertype name="company:Room" 
javaname="xmlobject.usertype.multipleItems.existing.Room">
+        
<xb:staticHandler>xmlobject.usertype.multipleItems.existing.RoomHandler</xb:staticHandler>
+    </xb:usertype>
+
+</xb:config>
\ No newline at end of file
diff -r 1a589b49b118 -r 8087234c303e 
test/src/xmlobject/usertype/averageCase/checkin/AverageTest.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/xmlobject/usertype/averageCase/checkin/AverageTest.java  Wed Apr 
01 22:52:23 2009 -0500
@@ -0,0 +1,104 @@
+/*   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package xmlobject.usertype.averageCase.checkin;
+
+
+import java.math.BigDecimal;
+
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
+
+import usertype.xbean.averageCase.purchaseOrder.Items;
+import usertype.xbean.averageCase.purchaseOrder.PurchaseOrderDocument;
+import usertype.xbean.averageCase.purchaseOrder.PurchaseOrderType;
+import xmlobject.usertype.averageCase.existing.SKU;
+
+
+
+
+public class AverageTest extends TestCase{
+
+        public  AverageTest(String s){
+            super(s);
+        }
+
+       public void test(){
+
+         PurchaseOrderDocument poDoc ;
+
+         poDoc= PurchaseOrderDocument.Factory.newInstance();
+         PurchaseOrderType po=poDoc.addNewPurchaseOrder();
+         int LEN=20;
+
+         Items.Item[] it= new Items.Item[LEN];
+         for (int i=0; i< LEN; i++){
+                it[i]=Items.Item.Factory.newInstance();
+                it[i].setUSPrice(new BigDecimal(""+ 2 ));
+                it[i].setPartNum(new SKU(i, "AB"));
+         }
+         Items items= Items.Factory.newInstance();
+            items.setItemArray(it);
+         po.setItems(items);
+       //  System.out.println("poDoc: " + poDoc);
+
+            for (int i=0; i< LEN; i++){
+                assertEquals(i, it[i].getPartNum().getDigits());
+                assertEquals("AB", it[i].getPartNum().getLetters());
+            }
+        
+
+    }
+       
+       public void testBadInput() throws XmlException{
+        
+           StringBuffer sb = new StringBuffer();
+           sb.append("<purchaseOrder 
xmlns=\"http://xbean.usertype/averageCase/PurchaseOrder\";>");
+           sb.append("<items><item 
partNum=\"000-AB\"><USPrice>2</USPrice></item>");
+           sb.append("<item partNum=\"0013-AB\"><USPrice>2</USPrice></item>");
+           sb.append("</items></purchaseOrder>");
+           
+           PurchaseOrderDocument poDocument = 
PurchaseOrderDocument.Factory.parse(sb.toString());
+           
+           PurchaseOrderType po = poDocument.getPurchaseOrder();
+           
+           Items.Item[] it = po.getItems().getItemArray();
+           assertEquals(2, it.length);
+           
+           
+           SKU sku = it[0].getPartNum();
+           
+           assertEquals(0, sku.getDigits());
+           assertEquals("AB", sku.getLetters());
+           
+           try {
+               
+               sku = it[1].getPartNum();
+               fail("Invalid SKU format should have failed");
+               
+           } catch (XmlValueOutOfRangeException e) {
+               
+               // test passed
+           }
+           
+           
+       }
+
+
+}
diff -r 1a589b49b118 -r 8087234c303e 
test/src/xmlobject/usertype/averageCase/existing/SKU.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/xmlobject/usertype/averageCase/existing/SKU.java Wed Apr 01 
22:52:23 2009 -0500
@@ -0,0 +1,44 @@
+package xmlobject.usertype.averageCase.existing;
+
+
+public class SKU
+{
+    
+    private int digits;
+    private String letters;
+    
+    
+    public SKU()
+    {
+        
+    }
+    public SKU(int digits, String letters)
+    {
+        setDigits(digits);
+        setLetters(letters);
+    }
+    public int getDigits()
+    {
+        return digits;
+    }
+    public void setDigits(int digits)
+    {
+        if (digits > 999 || digits < 0)
+            throw new IllegalArgumentException("bad digits");
+        this.digits = digits;
+    }
+    public String getLetters()
+    {
+        return letters;
+    }
+    public void setLetters(String letters)
+    {
+        if (letters == null || letters.length() != 2)
+            throw new IllegalArgumentException("bad letters");
+        this.letters = letters;
+    }
+    
+    
+    
+
+}
diff -r 1a589b49b118 -r 8087234c303e 
test/src/xmlobject/usertype/averageCase/existing/SKUHandler.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/xmlobject/usertype/averageCase/existing/SKUHandler.java  Wed Apr 
01 22:52:23 2009 -0500
@@ -0,0 +1,42 @@
+package xmlobject.usertype.averageCase.existing;
+
+import org.apache.xmlbeans.SimpleValue;
+import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
+
+public class SKUHandler
+{
+
+    public static void encodeSKU(SKU obj, SimpleValue target)
+    {
+        String digits;
+        if (obj.getDigits() < 10)
+            digits = "00" + Integer.toString(obj.getDigits());
+        else if (obj.getDigits() < 100)
+            digits = "0" + Integer.toString(obj.getDigits());
+        else
+            digits = Integer.toString(obj.getDigits());
+        target.setStringValue(digits + "-" + obj.getLetters());
+    }
+    
+    
+    public static SKU decodeSKU(SimpleValue obj) throws 
XmlValueOutOfRangeException
+    {
+        String encoded = obj.getStringValue();
+        if (encoded.length() != 6)
+            throw new XmlValueOutOfRangeException("Invalid SKU format: " + 
encoded);
+        
+        SKU sku = new SKU();
+        try
+        {
+            sku.setDigits(Integer.parseInt(encoded.substring(0,3)));
+        } catch (NumberFormatException e) {
+            throw new XmlValueOutOfRangeException("Invalid SKU format: " + 
encoded);
+        } catch (IllegalArgumentException e) {
+            throw new XmlValueOutOfRangeException("Invalid SKU format: " + 
encoded);
+        }
+        
+        sku.setLetters(encoded.substring(4,6));
+        return sku;
+    }
+    
+}
diff -r 1a589b49b118 -r 8087234c303e 
test/src/xmlobject/usertype/multipleItems/checkin/AverageTest.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/xmlobject/usertype/multipleItems/checkin/AverageTest.java        
Wed Apr 01 22:52:23 2009 -0500
@@ -0,0 +1,224 @@
+/*   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package xmlobject.usertype.multipleItems.checkin;
+
+
+import java.math.BigInteger;
+
+import junit.framework.TestCase;
+
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
+
+import usertype.xbean.multipleItems.company.CompanyDocument;
+import usertype.xbean.multipleItems.company.CompanyType;
+import usertype.xbean.multipleItems.company.ConsultantType;
+import usertype.xbean.multipleItems.company.DepartmentType;
+import xmlobject.usertype.multipleItems.existing.Room;
+
+
+
+
+public class AverageTest extends TestCase{
+
+        public  AverageTest(String s){
+            super(s);
+        }
+        
+        public void test() {
+            
+            CompanyDocument doc;
+            
+            doc = CompanyDocument.Factory.newInstance();
+            
+            CompanyType company = doc.addNewCompany();
+            
+            DepartmentType dept = company.addNewDepartments();
+            
+            
+            ConsultantType cons = dept.addNewConsultant();
+            
+            cons.setName("Joe Smith");
+            cons.setAge(BigInteger.valueOf(100));
+            
+            int LEN=20;
+            
+            for (int i=0; i < LEN; i++) {
+                cons.addRoom(new Room(i, "AB"));
+            }
+            
+            System.out.println(doc.xmlText());
+            
+            Room[] rooms = cons.getRoomArray();
+            
+            for (int i=0; i < LEN; i++) {
+                assertEquals(i, rooms[i].getDigits());
+                assertEquals("AB", rooms[i].getLetters());
+            }
+        }
+        
+
+        public void testArrayGetSet() {
+            
+            CompanyDocument doc;
+            
+            doc = CompanyDocument.Factory.newInstance();
+            
+            CompanyType company = doc.addNewCompany();
+            
+            DepartmentType dept = company.addNewDepartments();
+            
+            
+            ConsultantType cons = dept.addNewConsultant();
+            
+            cons.setName("Joe Smith");
+            cons.setAge(BigInteger.valueOf(100));
+            
+            int LEN=20;
+            
+            Room[] rooms = new Room[LEN];
+            
+            for (int i=0; i < LEN; i++) {
+                rooms[i] = new Room(i, "AB");
+            }
+            
+            cons.setRoomArray(rooms);
+            
+            rooms = cons.getRoomArray();
+            for (int i=0; i < LEN; i++) {
+                assertEquals(i, rooms[i].getDigits());
+                assertEquals("AB", rooms[i].getLetters());
+            }
+            
+            
+        }
+
+        public void testIthGetSet() {
+            
+            CompanyDocument doc;
+            
+            doc = CompanyDocument.Factory.newInstance();
+            
+            CompanyType company = doc.addNewCompany();
+            
+            DepartmentType dept = company.addNewDepartments();
+            
+            
+            ConsultantType cons = dept.addNewConsultant();
+            
+            cons.setName("Joe Smith");
+            cons.setAge(BigInteger.valueOf(100));
+            
+            
+            int LEN=20;
+            
+            for (int i=0; i < LEN; i++) {
+                cons.addNewRoom();
+            }
+            
+            
+            for (int i=0; i < LEN; i++) {
+                cons.setRoomArray(i, new Room(i, "AB"));
+            }
+            
+            for (int i=0; i < LEN; i++) {
+                assertEquals(i, cons.getRoomArray(i).getDigits());
+                assertEquals("AB", cons.getRoomArray(i).getLetters());
+            }
+            
+            
+        }
+
+       
+       public void testBadInput() throws XmlException{
+        
+           StringBuffer sb = new StringBuffer();
+           sb.append("<com:company 
xmlns:com=\"http://xbean.usertype/multipleItems/company\";>");
+           sb.append("<departments><consultant name=\"Joe Smith\" 
age=\"100\">");
+           
sb.append("<room>000-AB</room><room>0001-AB</room><room>002-AB</room>");
+           sb.append("</consultant></departments></com:company>");
+           
+           CompanyDocument doc = CompanyDocument.Factory.parse(sb.toString());
+           
+           CompanyType company = doc.getCompany();
+           
+           ConsultantType cons = 
company.getDepartmentsArray(0).getConsultantArray(0);
+           assertEquals(3, cons.xgetRoomArray().length);
+           
+           try
+           {
+               cons.getRoomArray();
+               fail("Invalid Room format should have failed");
+           
+        } catch (XmlValueOutOfRangeException e) {
+            
+            // test passed
+        }
+           
+       }
+
+       
+
+    public void testBadInputGetIthBad() throws XmlException{
+     
+        StringBuffer sb = new StringBuffer();
+        sb.append("<com:company 
xmlns:com=\"http://xbean.usertype/multipleItems/company\";>");
+        sb.append("<departments><consultant name=\"Joe Smith\" age=\"100\">");
+        
sb.append("<room>000-AB</room><room>0001-AB</room><room>002-AB</room>");
+        sb.append("</consultant></departments></com:company>");
+        
+        CompanyDocument doc = CompanyDocument.Factory.parse(sb.toString());
+        
+        CompanyType company = doc.getCompany();
+        
+        ConsultantType cons = 
company.getDepartmentsArray(0).getConsultantArray(0);
+        assertEquals(3, cons.xgetRoomArray().length);
+        
+        try
+        {
+            cons.getRoomArray(1);
+            fail("Invalid Room format should have failed");
+        } catch (XmlValueOutOfRangeException e) {
+            
+            // test passed
+        }
+        
+    }
+    
+
+    public void testBadInputGetIthGood() throws XmlException{
+     
+        StringBuffer sb = new StringBuffer();
+        sb.append("<com:company 
xmlns:com=\"http://xbean.usertype/multipleItems/company\";>");
+        sb.append("<departments><consultant name=\"Joe Smith\" age=\"100\">");
+        
sb.append("<room>000-AB</room><room>0001-AB</room><room>002-AB</room>");
+        sb.append("</consultant></departments></com:company>");
+        
+        CompanyDocument doc = CompanyDocument.Factory.parse(sb.toString());
+        
+        CompanyType company = doc.getCompany();
+        
+        ConsultantType cons = 
company.getDepartmentsArray(0).getConsultantArray(0);
+        assertEquals(3, cons.xgetRoomArray().length);
+        
+        assertEquals(0, cons.getRoomArray(0).getDigits());
+        assertEquals("AB", cons.getRoomArray(0).getLetters());
+        assertEquals(2, cons.getRoomArray(2).getDigits());
+        assertEquals("AB", cons.getRoomArray(2).getLetters());
+        
+    }
+
+}
diff -r 1a589b49b118 -r 8087234c303e 
test/src/xmlobject/usertype/multipleItems/existing/Room.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/xmlobject/usertype/multipleItems/existing/Room.java      Wed Apr 
01 22:52:23 2009 -0500
@@ -0,0 +1,44 @@
+package xmlobject.usertype.multipleItems.existing;
+
+
+public class Room
+{
+    
+    private int digits;
+    private String letters;
+    
+    
+    public Room()
+    {
+        
+    }
+    public Room(int digits, String letters)
+    {
+        setDigits(digits);
+        setLetters(letters);
+    }
+    public int getDigits()
+    {
+        return digits;
+    }
+    public void setDigits(int digits)
+    {
+        if (digits > 999 || digits < 0)
+            throw new IllegalArgumentException("bad digits");
+        this.digits = digits;
+    }
+    public String getLetters()
+    {
+        return letters;
+    }
+    public void setLetters(String letters)
+    {
+        if (letters == null || letters.length() != 2)
+            throw new IllegalArgumentException("bad letters");
+        this.letters = letters;
+    }
+    
+    
+    
+
+}
diff -r 1a589b49b118 -r 8087234c303e 
test/src/xmlobject/usertype/multipleItems/existing/RoomHandler.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/xmlobject/usertype/multipleItems/existing/RoomHandler.java       
Wed Apr 01 22:52:23 2009 -0500
@@ -0,0 +1,42 @@
+package xmlobject.usertype.multipleItems.existing;
+
+import org.apache.xmlbeans.SimpleValue;
+import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
+
+public class RoomHandler
+{
+
+    public static void encodeRoom(Room obj, SimpleValue target)
+    {
+        String digits;
+        if (obj.getDigits() < 10)
+            digits = "00" + Integer.toString(obj.getDigits());
+        else if (obj.getDigits() < 100)
+            digits = "0" + Integer.toString(obj.getDigits());
+        else
+            digits = Integer.toString(obj.getDigits());
+        target.setStringValue(digits + "-" + obj.getLetters());
+    }
+    
+    
+    public static Room decodeRoom(SimpleValue obj) throws 
XmlValueOutOfRangeException
+    {
+        String encoded = obj.getStringValue();
+        if (encoded.length() != 6)
+            throw new XmlValueOutOfRangeException("Invalid Room format: " + 
encoded);
+        
+        Room sku = new Room();
+        try
+        {
+            sku.setDigits(Integer.parseInt(encoded.substring(0,3)));
+        } catch (NumberFormatException e) {
+            throw new XmlValueOutOfRangeException("Invalid Room format: " + 
encoded);
+        } catch (IllegalArgumentException e) {
+            throw new XmlValueOutOfRangeException("Invalid Room format: " + 
encoded);
+        }
+        
+        sku.setLetters(encoded.substring(4,6));
+        return sku;
+    }
+    
+}
diff -r 1a589b49b118 -r 8087234c303e testbuild.xml
--- a/testbuild.xml     Sun Mar 15 02:36:29 2009 -0500
+++ b/testbuild.xml     Wed Apr 01 22:52:23 2009 -0500
@@ -256,7 +256,8 @@
         ${build.dir.test.schemas}/xbean/xmlobject/store,
         ${build.dir.test.schemas}/xbean/xmltokensource,
         ${build.dir.test.schemas}/xbean/ValidatingStream,
-        ${build.dir.test.schemas}/xbean/scomp"/>
+        ${build.dir.test.schemas}/xbean/scomp,
+        ${build.dir.test.schemas}/xbean/usertype"/>
     <!-- comma separated list of directories containing schemas that *must* be 
separately
          compiled -->
     <property name="schema.standalone"
@@ -571,7 +572,7 @@
     <!-- NOTE: This target depends on build.schemas, but we do not
                explicitly put it on the depends list. -->
 
-    <target name="build.tests" depends="init, build.test.tools, 
build.xpath,extensions.build"
+    <target name="build.tests" depends="init, build.test.tools, 
build.xpath,extensions.build,usertype.build"
         description="Build the tests">
 
         <javac srcdir="${xbeans.test.src}"
@@ -646,6 +647,12 @@
                 <antcall target="extensions.build"/>
             </then>
         </if>
+        <if>
+            <isset property="compile.usertype"/>
+            <then>
+                <antcall target="usertype.build"/>
+            </then>
+        </if>
         <antcall target="build.xmlcases"/>
         <antcall target="build.xsdcases"/>
 
@@ -708,6 +715,37 @@
 
         </foreachloop>
     </target>
+    <!--User type feature-->
+    <target name="usertype.build" depends="init">
+        <echo message="Building user types"/>
+        <foreachloop
+            param="case" trim="true">
+            <path>
+                <dirset dir="${xbeans.test.src}/xmlobject/usertype/">
+                    <include name="*"/>
+                </dirset>
+            </path>
+            <loop>
+                <basename property="testcase" path="${case}"/>
+                
+                <available 
file="${build.dir.test.schemas.lib}/usertype_${testcase}.jar" 
property="usertypejar.exists"/>
+                <echo message="JAR 
${build.dir.test.schemas.lib}/usertype_${testcase}.jar, Exists: 
${usertypejar.exists}"/>
+                <if>
+                    <isfalse value="${usertypejar.exists}"/>
+                    <then>
+                        <java classname="${schema.compiler}"
+                            classpathref="build.classpath"
+                            fork="true">
+                            <arg line="-out 
${build.dir.test.schemas.lib}/usertype_${testcase}.jar
+                            ${case}/existing
+                            ${xbeans.test.cases}/xbean/usertype/${testcase}"
+                                />
+                        </java>
+                    </then>
+                </if>
+            </loop>
+        </foreachloop>
+    </target>
 
     <!--test xmlbeans task-->
     <target name="xmlbean-test" depends="init">
@@ -733,6 +771,7 @@
             
${schema.standalone}/SimpleRailCarrierWaybillInterchange_V40_LX.xsd,
             
${schema.standalone}/TerminalOperationsAndIntermodalRampActivity_V40_LX.xsd,"/>
         <property name="compile.extensions" value="true"/>
+        <property name="compile.usertype" value="true"/>
 
         <property name="includes.for.compile"
             value="**/xmlobject/**/*.java"/>
@@ -830,7 +869,7 @@
     </target>
 
     <!-- FREQ Target -->
-    <target name="build.area.checkin" depends="clean.tests,extensions.build">
+    <target name="build.area.checkin" 
depends="clean.tests,extensions.build,usertype.build">
         <property name="includes.for.compile"
             value="**/checkin/**/*.java,
                    **/common/**/*.java"/>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@xmlbeans.apache.org
For additional commands, e-mail: dev-h...@xmlbeans.apache.org

Reply via email to