1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package tests;
21
22 import junit.framework.TestCase;
23 import org.apache.ws.commons.schema.*;
24
25 import javax.xml.namespace.QName;
26 import javax.xml.transform.stream.StreamSource;
27 import java.io.FileInputStream;
28 import java.io.InputStream;
29 import java.util.HashSet;
30 import java.util.Set;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class AnyTest extends TestCase {
50
51
52
53
54
55
56 public void testAny() throws Exception {
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
79 "department");
80 InputStream is = new FileInputStream(Resources.asURI("any.xsd"));
81 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
82 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
83
84 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
85 assertNotNull(elem);
86 assertEquals("department", elem.getName());
87 assertEquals(new QName("http://soapinterop.org/types", "department"),
88 elem.getQName());
89
90 XmlSchemaComplexType type =
91 (XmlSchemaComplexType)elem.getSchemaType();
92 assertNotNull(type);
93
94 XmlSchemaSequence xss = (XmlSchemaSequence)type.getParticle();
95 assertNotNull(xss);
96
97 XmlSchemaObjectCollection c = xss.getItems();
98 assertEquals(3, c.getCount());
99
100 Set s = new HashSet();
101 s.add("id");
102 s.add("name");
103 Object o = null;
104 for (int i = 0; i < c.getCount(); i++) {
105 o = c.getItem(i);
106 if (o instanceof XmlSchemaElement) {
107 String name = ((XmlSchemaElement)o).getName();
108 if (name.equals("id")) {
109 assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
110 "integer"),
111 ((XmlSchemaElement)o).getSchemaTypeName());
112 } else if (name.equals("name")) {
113 assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
114 "string"),
115 ((XmlSchemaElement)o).getSchemaTypeName());
116 }
117 s.remove(name);
118 } else if (o instanceof XmlSchemaAny) {
119 XmlSchemaContentProcessing xscp =
120 ((XmlSchemaAny)o).getProcessContent();
121 assertEquals("none", xscp.toString());
122 assertEquals(5L, ((XmlSchemaAny)o).getMinOccurs());
123 assertEquals(10L, ((XmlSchemaAny)o).getMaxOccurs());
124 }
125 }
126
127 assertTrue("The set should have been empty, but instead contained: "
128 + s + ".",
129 s.isEmpty());
130
131 }
132
133 }