1   package tests;
2   
3   import junit.framework.TestCase;
4   import org.apache.ws.commons.schema.XmlSchemaCollection;
5   import org.apache.ws.commons.schema.XmlSchemaElement;
6   import org.w3c.dom.Document;
7   import org.w3c.dom.Element;
8   import org.w3c.dom.Node;
9   import org.w3c.dom.NodeList;
10  
11  import javax.xml.namespace.QName;
12  import javax.xml.parsers.DocumentBuilderFactory;
13  /*
14   * Copyright 2004,2007 The Apache Software Foundation.
15   *
16   * Licensed under the Apache License, Version 2.0 (the "License");
17   * you may not use this file except in compliance with the License.
18   * You may obtain a copy of the License at
19   *
20   *      http://www.apache.org/licenses/LICENSE-2.0
21   *
22   * Unless required by applicable law or agreed to in writing, software
23   * distributed under the License is distributed on an "AS IS" BASIS,
24   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25   * See the License for the specific language governing permissions and
26   * limitations under the License.
27   */
28  
29  public class TwoSchemasRefTest extends TestCase {
30  
31      public void testTwoSchemas() throws Exception{
32          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
33          documentBuilderFactory.setNamespaceAware(true);
34          Document doc = documentBuilderFactory.newDocumentBuilder().
35                  parse(Resources.asURI("twoSchemas-ref.wsdl"));
36  
37          XmlSchemaCollection schemaCol = new XmlSchemaCollection();
38  		NodeList schemaNodes = doc.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema","schema");
39          for (int j = 0; j < schemaNodes.getLength(); j++) {
40          	Node schemaNode = schemaNodes.item(j);
41          	if("schema".equals(schemaNode.getLocalName())){
42          		schemaCol.read((Element)schemaNode);
43          	}
44          }
45  
46          XmlSchemaElement elementByQName = schemaCol.getElementByQName(new QName("http://tns.demo.org", "elem1"));
47          assertNotNull(elementByQName);
48          
49      }
50  }