1   /*
2    * Copyright 2004,2007 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package tests;
17  
18  import junit.framework.TestCase;
19  import org.apache.ws.commons.schema.*;
20  import org.w3c.dom.Document;
21  
22  import javax.xml.namespace.QName;
23  import javax.xml.parsers.DocumentBuilderFactory;
24  
25  
26  public class AnyAttTest extends TestCase {
27  
28      protected void setUp() throws Exception {
29  
30      }
31  
32      public void testAnyAtt() throws Exception{
33            //create a DOM document
34          DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
35          documentBuilderFactory.setNamespaceAware(true);
36          Document doc = documentBuilderFactory.newDocumentBuilder().
37                  parse(Resources.asURI("anyAttTest.xsd"));
38  
39          XmlSchemaCollection schemaCol = new XmlSchemaCollection();
40          XmlSchema s = schemaCol.read(doc.getDocumentElement());
41  
42          //get the element
43          XmlSchemaElement elt = s.getElementByName(new QName("http://unqualified-elements.example.com","AnyAttContainer"));
44          assertNotNull("Element \"AnyAttContainer\" is missing! ",elt);
45  
46          XmlSchemaType schemaType = elt.getSchemaType();
47          assertNotNull("Relevant schema type is missing!",schemaType);
48  
49          XmlSchemaComplexType xmlSchemaComplexType = ((XmlSchemaComplexType) schemaType);
50          XmlSchemaParticle particle = xmlSchemaComplexType.getParticle();
51          assertNotNull(particle);
52  
53          XmlSchemaAnyAttribute anyAttribute = xmlSchemaComplexType.getAnyAttribute();
54          assertNotNull("Any attribute is missing",anyAttribute);
55  
56  
57      }
58  
59  }