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.ByteArrayOutputStream;
9   import java.io.FileInputStream;
10  import java.io.InputStream;
11  import java.util.Iterator;
12  /*
13   * Copyright 2004,2007 The Apache Software Foundation.
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 TestElementRefs extends TestCase {
29      public void testElementRefs() throws Exception {
30          QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
31                  "attTests");
32          InputStream is = new FileInputStream(Resources.asURI("elementreferences.xsd"));
33          XmlSchemaCollection schemaCol = new XmlSchemaCollection();
34          XmlSchema schema = schemaCol.read(new StreamSource(is), null);
35  
36          XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
37  
38          assertNotNull(elem);
39  
40          XmlSchemaComplexType cmplxType = (XmlSchemaComplexType)elem.getSchemaType();
41          XmlSchemaObjectCollection items = ((XmlSchemaSequence)cmplxType.getParticle()).getItems();
42  
43          Iterator it = items.getIterator();
44          while (it.hasNext()) {
45              XmlSchemaElement innerElement =  (XmlSchemaElement)it.next();
46              assertNotNull(innerElement.getRefName());
47          }
48  
49          // test writing
50          ByteArrayOutputStream bos = new ByteArrayOutputStream();
51          schema.write(bos);
52      }
53  
54  }