1   package tests;
2   
3   import junit.framework.TestCase;
4   import org.apache.ws.commons.schema.*;
5   import org.w3c.dom.Document;
6   
7   import javax.xml.namespace.QName;
8   import javax.xml.parsers.DocumentBuilderFactory;
9   import java.util.Iterator;
10  /*
11   * Copyright 2004,2007 The Apache Software Foundation.
12   *
13   * Licensed under the Apache License, Version 2.0 (the "License");
14   * you may not use this file except in compliance with the License.
15   * You may obtain a copy of the License at
16   *
17   *      http://www.apache.org/licenses/LICENSE-2.0
18   *
19   * Unless required by applicable law or agreed to in writing, software
20   * distributed under the License is distributed on an "AS IS" BASIS,
21   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22   * See the License for the specific language governing permissions and
23   * limitations under the License.
24   */
25  
26  public class TestUnqualifiedSchema extends TestCase {
27  
28  
29      public void testUnqualifiedSchemas() throws Exception {
30          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
31          documentBuilderFactory.setNamespaceAware(true);
32          Document doc = documentBuilderFactory.newDocumentBuilder().
33                  parse(Resources.asURI("unqualifiedTypes.xsd"));
34          XmlSchemaCollection schemaCol = new XmlSchemaCollection();
35          XmlSchema s = schemaCol.read(doc.getDocumentElement());
36  
37          assertNotNull(s);
38  
39          XmlSchemaElement e=s.getElementByName(new QName("http://soapinterop.org/xsd","complexElt") );
40          XmlSchemaComplexType t  =(XmlSchemaComplexType)e.getSchemaType();
41          assertNotNull(t);
42  
43          XmlSchemaSequence seq = (XmlSchemaSequence)t.getParticle();
44          XmlSchemaObjectCollection items = seq.getItems();
45          Iterator iterator = items.getIterator();
46          while (iterator.hasNext()) {
47              XmlSchemaElement elt2 = (XmlSchemaElement) iterator.next();
48              System.out.println(elt2.getQName());
49              XmlSchemaType schemaType2 = elt2.getSchemaType();
50  
51              assertNotNull(schemaType2);
52          }
53  
54  
55  
56      }
57  
58  
59  }