1   package tests;
2   
3   import junit.framework.TestCase;
4   import org.apache.ws.commons.schema.*;
5   
6   import javax.xml.namespace.QName;
7   import javax.xml.transform.stream.StreamSource;
8   import java.io.FileInputStream;
9   import java.io.InputStream;
10  
11  /*
12   * Copyright 2004,2007 The Apache Software Foundation.
13   * Copyright 2006 International Business Machines Corp.
14   *
15   * Licensed under the Apache License, Version 2.0 (the "License");
16   * you may not use this file except in compliance with the License.
17   * You may obtain a copy of the License at
18   *
19   *      http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing, software
22   * distributed under the License is distributed on an "AS IS" BASIS,
23   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24   * See the License for the specific language governing permissions and
25   * limitations under the License.
26   *
27   */
28  public class ListTest extends TestCase {
29  
30      /**
31       * This method will test the list.
32       *
33       * @throws Exception Any exception encountered
34       */
35      public void testList() throws Exception {
36  
37          /*
38           <schema xmlns="http://www.w3.org/2001/XMLSchema"
39                   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
40                   xmlns:tns="http://soapinterop.org/types"
41                   targetNamespace="http://soapinterop.org/types">
42          
43             <element name="workDays">
44               <simpleType>
45                 <restriction base="tns:daysInWeek">
46                   <length value="5"/>
47                 </restriction>
48               </simpleType>
49             </element>
50  
51             <simpleType name="daysInWeek">
52               <list itemType="xsd:integer"/>
53             </simpleType>
54    
55           </schema>
56          */
57  
58          QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
59                  "workDays");
60          InputStream is = new FileInputStream(Resources.asURI("list.xsd"));
61          XmlSchemaCollection schemaCol = new XmlSchemaCollection();
62          XmlSchema schema = schemaCol.read(new StreamSource(is), null);
63  
64          XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
65          assertNotNull(elem);
66          assertEquals("workDays", elem.getName());
67          assertEquals(new QName("http://soapinterop.org/types", "workDays"),
68                       elem.getQName());
69  
70          XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
71          assertNotNull(simpleType);
72  
73          XmlSchemaSimpleTypeRestriction r =
74              (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
75          assertNotNull(r);
76  
77          QName baseTypeName = r.getBaseTypeName();
78          assertEquals(new QName("http://soapinterop.org/types", "daysInWeek"),
79                       baseTypeName);
80          XmlSchemaType type = schemaCol.getTypeByQName(baseTypeName);
81  
82          XmlSchemaSimpleTypeContent content = ((XmlSchemaSimpleType)type).getContent();
83          assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
84                     ((XmlSchemaSimpleTypeList)content).getItemTypeName());
85  
86      }
87  
88  }