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
14
15
16
17
18
19
20
21
22
23
24
25
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
50 ByteArrayOutputStream bos = new ByteArrayOutputStream();
51 schema.write(bos);
52 }
53
54 }