KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > junit > JAXBParserTest


1 /*
2  * Copyright 2003, 2004 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  */

17 package org.apache.ws.jaxme.xs.junit;
18
19 import java.io.StringReader JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 import org.apache.ws.jaxme.xs.XSAttributable;
23 import org.apache.ws.jaxme.xs.XSComplexType;
24 import org.apache.ws.jaxme.xs.XSElement;
25 import org.apache.ws.jaxme.xs.XSEnumeration;
26 import org.apache.ws.jaxme.xs.XSGroup;
27 import org.apache.ws.jaxme.xs.XSParticle;
28 import org.apache.ws.jaxme.xs.XSSimpleType;
29 import org.apache.ws.jaxme.xs.XSType;
30 import org.apache.ws.jaxme.xs.jaxb.JAXBAttribute;
31 import org.apache.ws.jaxme.xs.jaxb.JAXBClass;
32 import org.apache.ws.jaxme.xs.jaxb.JAXBElement;
33 import org.apache.ws.jaxme.xs.jaxb.JAXBEnumeration;
34 import org.apache.ws.jaxme.xs.jaxb.JAXBGlobalBindings;
35 import org.apache.ws.jaxme.xs.jaxb.JAXBGroup;
36 import org.apache.ws.jaxme.xs.jaxb.JAXBJavaType;
37 import org.apache.ws.jaxme.xs.jaxb.JAXBJavadoc;
38 import org.apache.ws.jaxme.xs.jaxb.JAXBProperty;
39 import org.apache.ws.jaxme.xs.jaxb.JAXBSchema;
40 import org.apache.ws.jaxme.xs.jaxb.JAXBSchemaBindings;
41 import org.apache.ws.jaxme.xs.jaxb.JAXBSimpleType;
42 import org.apache.ws.jaxme.xs.jaxb.JAXBType;
43 import org.apache.ws.jaxme.xs.jaxb.JAXBTypesafeEnumClass;
44 import org.apache.ws.jaxme.xs.jaxb.JAXBTypesafeEnumMember;
45 import org.apache.ws.jaxme.xs.jaxb.impl.JAXBParser;
46 import org.apache.ws.jaxme.xs.types.XSDateTime;
47 import org.apache.ws.jaxme.xs.types.XSNCName;
48 import org.apache.ws.jaxme.xs.types.XSString;
49 import org.apache.ws.jaxme.xs.xml.XsQName;
50 import org.xml.sax.InputSource JavaDoc;
51 import org.xml.sax.SAXException JavaDoc;
52
53 /**
54  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
55  */

56 public class JAXBParserTest extends ParserTest {
57   public JAXBParserTest(String JavaDoc pName) { super(pName); }
58
59   public void testJAXBGlobalBindingsDefaults() throws Exception JavaDoc {
60     // Parse a schema without globalBindings; it should have the default
61
// settings.
62
final String JavaDoc schemaSource =
63       "<?xml version='1.0'?>\n" +
64       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'/>\n";
65     
66     JAXBParser parser = newJAXBParser();
67     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
68     isource.setSystemId("testGlobalBindingsDefaults.xsd");
69     JAXBSchema schema = (JAXBSchema) parser.parse(isource);
70     JAXBGlobalBindings globalBindings = schema.getJAXBGlobalBindings();
71     String JavaDoc collectionType = globalBindings.getCollectionType();
72     assertNull(collectionType);
73     JAXBJavaType[] javaTypes = globalBindings.getJavaType();
74     assertNotNull(javaTypes);
75     assertEquals(0, javaTypes.length);
76     XsQName[] typesafeEnumBase = globalBindings.getTypesafeEnumBase();
77     assertNotNull(typesafeEnumBase);
78     assertEquals(1, typesafeEnumBase.length);
79     XsQName qName = typesafeEnumBase[0];
80     assertEquals(XSNCName.getInstance().getName(), qName);
81     boolean bindingStyleModelGroup = globalBindings.isBindingStyleModelGroup();
82     assertTrue(!bindingStyleModelGroup);
83     boolean choiceContentProperty = globalBindings.isChoiceContentProperty();
84     assertTrue(!choiceContentProperty);
85     boolean enableFailFastCheck = globalBindings.isEnableFailFastCheck();
86     assertTrue(!enableFailFastCheck);
87     boolean enableJavaNamingConventions = globalBindings.isEnableJavaNamingConventions();
88     assertTrue(enableJavaNamingConventions);
89     boolean fixedAttributeAsConstantProperty = globalBindings.isFixedAttributeAsConstantProperty();
90     assertTrue(!fixedAttributeAsConstantProperty);
91     boolean generateIsSetMethod = globalBindings.isGenerateIsSetMethod();
92     assertTrue(!generateIsSetMethod);
93     JAXBGlobalBindings.UnderscoreBinding underscoreBinding = globalBindings.getUnderscoreBinding();
94     assertEquals(JAXBGlobalBindings.UnderscoreBinding.AS_WORD_SEPARATOR, underscoreBinding);
95   }
96
97   public void testJAXBGlobalBindings() throws Exception JavaDoc {
98     // Parse a schema with globalBindings
99
final String JavaDoc schemaSource =
100       "<?xml version='1.0'?>\n" +
101       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
102       " <xs:annotation>\n" +
103       " <xs:appinfo>\n" +
104       " <jaxb:globalBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'\n" +
105       " collectionType='java.util.ArrayList'\n" +
106       " typesafeEnumBase='xs:string xs:NCName'\n" +
107       " bindingStyle='modelGroupBinding'\n" +
108       " choiceContentProperty='true'\n" +
109       " enableFailFastCheck='1'\n" +
110       " enableJavaNamingConventions='false'\n" +
111       " fixedAttributeAsConstantProperty='true'\n" +
112       " generateIsSetMethod='1'\n" +
113       " underscoreBinding='asCharInWord'/>\n" +
114       " </xs:appinfo\n>" +
115       " </xs:annotation>\n" +
116       "</xs:schema>";
117     
118     JAXBParser parser = newJAXBParser();
119     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
120     isource.setSystemId("testGlobalBindingsDefaults.xsd");
121     JAXBSchema schema = (JAXBSchema) parser.parse(isource);
122     JAXBGlobalBindings globalBindings = schema.getJAXBGlobalBindings();
123     String JavaDoc collectionType = globalBindings.getCollectionType();
124     assertEquals("java.util.ArrayList", collectionType);
125   
126     XsQName[] typesafeEnumBase = globalBindings.getTypesafeEnumBase();
127     assertNotNull(typesafeEnumBase);
128     assertEquals(2, typesafeEnumBase.length);
129     XsQName qName = typesafeEnumBase[0];
130     assertEquals(qName, XSString.getInstance().getName());
131     qName = typesafeEnumBase[1];
132     assertEquals(qName, XSNCName.getInstance().getName());
133   
134     boolean bindingStyleModelGroup = globalBindings.isBindingStyleModelGroup();
135     assertTrue(bindingStyleModelGroup);
136   
137     boolean choiceContentProperty = globalBindings.isChoiceContentProperty();
138     assertTrue(choiceContentProperty);
139   
140     boolean enableFailFastCheck = globalBindings.isEnableFailFastCheck();
141     assertTrue(enableFailFastCheck);
142   
143     boolean enableJavaNamingConventions = globalBindings.isEnableJavaNamingConventions();
144     assertTrue(!enableJavaNamingConventions);
145   
146     boolean fixedAttributeAsConstantProperty = globalBindings.isFixedAttributeAsConstantProperty();
147     assertTrue(fixedAttributeAsConstantProperty);
148   
149     boolean generateIsSetMethod = globalBindings.isGenerateIsSetMethod();
150     assertTrue(generateIsSetMethod);
151   
152     JAXBGlobalBindings.UnderscoreBinding underscoreBinding = globalBindings.getUnderscoreBinding();
153     assertEquals(JAXBGlobalBindings.UnderscoreBinding.AS_CHAR_IN_WORD, underscoreBinding);
154   
155     JAXBJavaType[] javaTypes = globalBindings.getJavaType();
156     assertNotNull(javaTypes);
157     assertEquals(0, javaTypes.length);
158   }
159
160   public void testJAXBSchemaBindingsDefaults() throws Exception JavaDoc {
161     // Parse a schema without schemaBindings; it should have the default
162
// settings.
163
final String JavaDoc schemaSource =
164       "<?xml version='1.0'?>\n" +
165       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
166       " <xs:complexType name='a'>\n" +
167       " <xs:sequence>\n" +
168       " <xs:element name='b' type='xs:string'/>\n" +
169       " </xs:sequence>\n" +
170       " </xs:complexType>\n" +
171       "</xs:schema>";
172     
173     JAXBParser parser = newJAXBParser();
174     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
175     isource.setSystemId("testSchemaBindingsDefaults.xsd");
176     JAXBSchema schema = (JAXBSchema) parser.parse(isource);
177     JAXBType a = (JAXBType) schema.getType(new XsQName((String JavaDoc) null, "a"));
178     assertNotNull(a);
179     assertComplexType(a);
180   
181     JAXBSchemaBindings schemaBindings = a.getJAXBSchemaBindings();
182     JAXBSchemaBindings.NameXmlTransform[] nameXmlTransforms = schemaBindings.getNameXmlTransform();
183     assertNotNull(nameXmlTransforms);
184     assertEquals(0, nameXmlTransforms.length);
185     assertNull(schemaBindings.getPackage());
186   }
187
188   public void testJAXBSchemaBindings() throws Exception JavaDoc {
189     final String JavaDoc myPackageName = "org.apache.ws.jaxme.somepackage";
190   
191     final String JavaDoc schemaSource =
192       "<?xml version='1.0'?>\n" +
193       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" +
194       " <xs:annotation>\n" +
195       " <xs:appinfo>\n" +
196       " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" +
197       " <jaxb:package name='" + myPackageName + "'>\n" +
198       " <jaxb:javadoc>Test documentation</jaxb:javadoc>\n" +
199       " </jaxb:package>\n" +
200       " <jaxb:nameXmlTransform>\n" +
201       " <jaxb:typeName prefix='b' suffix='a'/>\n" +
202       " </jaxb:nameXmlTransform>\n" +
203       " </jaxb:schemaBindings>\n" +
204       " </xs:appinfo>\n" +
205       " </xs:annotation>\n" +
206       " <xs:complexType name='a'>\n" +
207       " <xs:sequence>\n" +
208       " <xs:element name='x' type='xs:int'/>\n" +
209       " </xs:sequence>\n" +
210       " <xs:attribute name='y' type='xs:string'/>\n" +
211       " </xs:complexType>\n" +
212       " <xs:element name='b' type='a'/>\n" +
213       "</xs:schema>";
214     
215     JAXBParser parser = newJAXBParser();
216     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
217     isource.setSystemId("testSchemaBindings.xsd");
218     JAXBSchema schema = (JAXBSchema) parser.parse(isource);
219     JAXBType a = (JAXBType) schema.getType(new XsQName((String JavaDoc) null, "a"));
220     JAXBSchemaBindings schemaBindings = a.getJAXBSchemaBindings();
221   
222     JAXBSchemaBindings.Package schemaPackage = schemaBindings.getPackage();
223     assertNotNull(schemaPackage);
224     assertEquals(myPackageName, schemaPackage.getName());
225     JAXBJavadoc javadoc = schemaPackage.getJavadoc();
226     assertNotNull(javadoc);
227     assertEquals("Test documentation", javadoc.getText());
228   
229     JAXBSchemaBindings.NameXmlTransform[] nameXmlTransforms = schemaBindings.getNameXmlTransform();
230     assertNotNull(nameXmlTransforms);
231     assertEquals(1, nameXmlTransforms.length);
232     JAXBSchemaBindings.NameXmlTransform nameXmlTransform = nameXmlTransforms[0];
233     assertNotNull(nameXmlTransform);
234     JAXBSchemaBindings.NameTransformation transformation = nameXmlTransform.getTypeName();
235     assertEquals("a", transformation.getSuffix());
236     assertEquals("b", transformation.getPrefix());
237   }
238
239   public void testJAXBClass() throws Exception JavaDoc {
240     {
241       final String JavaDoc schemaSource =
242         "<?xml version='1.0'?>\n" +
243         "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
244         " xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" +
245         " <xs:complexType name='a'>\n" +
246         " <xs:annotation>\n" +
247         " <xs:appinfo>\n" +
248         " <jaxb:class name='b' implClass='com.b.c'/>\n" +
249         " </xs:appinfo>\n" +
250         " </xs:annotation>\n" +
251         " <xs:sequence>\n" +
252         " <xs:element name='x' type='xs:int'/>\n" +
253         " <xs:element name='f' type='xs:string'>\n" +
254         " <xs:annotation><xs:appinfo>\n" +
255         " <jaxb:class name='x'/>\n" +
256         " </xs:appinfo></xs:annotation>\n" +
257         " </xs:element>\n" +
258         " </xs:sequence>\n" +
259         " <xs:attribute name='y' type='xs:string'/>\n" +
260         " </xs:complexType>\n" +
261         " <xs:element name='g' type='xs:string'/>\n" +
262         " <xs:group name='m'>\n" +
263         " <xs:annotation>\n" +
264         " <xs:appinfo>\n" +
265         " <jaxb:class name='k' implClass='com.b.i'/>\n" +
266         " </xs:appinfo>\n" +
267         " </xs:annotation>\n" +
268         " <xs:sequence>\n" +
269         " <xs:element name='n' type='xs:float'/>\n" +
270         " </xs:sequence>\n" +
271         " </xs:group>\n" +
272         "</xs:schema>";
273   
274       JAXBParser parser = newJAXBParser();
275       InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
276       isource.setSystemId("testClass1.xsd");
277       JAXBSchema schema = (JAXBSchema) parser.parse(isource);
278       JAXBType a = (JAXBType) schema.getType(new XsQName((String JavaDoc) null, "a"));
279       assertNotNull(a);
280       JAXBClass jaxbClass = a.getJAXBClass();
281       assertNotNull(jaxbClass);
282       assertEquals("b", jaxbClass.getName());
283       assertEquals("com.b.c", jaxbClass.getImplClass());
284       XSParticle p1 = assertComplexContent(assertComplexType(a));
285       XSGroup group = assertGroup(p1);
286       XSParticle[] particles = group.getParticles();
287       assertEquals(2, particles.length);
288       JAXBElement f = (JAXBElement) assertElement(particles[1]);
289       jaxbClass = f.getJAXBClass();
290       assertNotNull(jaxbClass);
291       assertEquals("x", jaxbClass.getName());
292       assertNull(jaxbClass.getImplClass());
293
294
295       JAXBElement g = (JAXBElement) schema.getElement(new XsQName((String JavaDoc) null, "g"));
296       assertNotNull(g);
297       assertNull(g.getJAXBClass());
298
299       JAXBGroup m = (JAXBGroup) schema.getGroup(new XsQName((String JavaDoc) null, "m"));
300       jaxbClass = m.getJAXBClass();
301       assertNotNull(jaxbClass);
302       assertEquals("k", jaxbClass.getName());
303       assertEquals("com.b.i", jaxbClass.getImplClass());
304     }
305
306     {
307       final String JavaDoc schemaSource =
308         "<?xml version='1.0'?>\n" +
309         "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
310         " xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" +
311         " <xs:complexType name='d'>\n" +
312         " <xs:sequence>\n" +
313         " <xs:element name='e'>\n" +
314         " <xs:complexType name='a'>\n" +
315         " <xs:annotation>\n" +
316         " <xs:appinfo>\n" +
317         " <jaxb:class name='b'/>\n" +
318         " </xs:appinfo>\n" +
319         " </xs:annotation>\n" +
320         " <xs:sequence>\n" +
321         " <xs:element name='x' type='xs:int'/>\n" +
322         " </xs:sequence>\n" +
323         " <xs:attribute name='y' type='xs:string'/>\n" +
324         " </xs:complexType>\n" +
325         " </xs:element>\n" +
326         " <xs:element name='f' type='xs:string'>\n" +
327         " <xs:annotation>\n" +
328         " <xs:appinfo>\n" +
329         " <jaxb:class name='x'/>\n" +
330         " </xs:appinfo>\n" +
331         " </xs:annotation>\n" +
332         " </xs:element>\n" +
333         " <xs:element name='g' type='xs:string'/>\n" +
334         " </xs:sequence>\n" +
335         " </xs:complexType>\n" +
336         "</xs:schema>";
337   
338       JAXBParser parser = newJAXBParser();
339       InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
340       isource.setSystemId("testJAXBClass2.xsd");
341       JAXBSchema schema = (JAXBSchema) parser.parse(isource);
342       JAXBType d = (JAXBType) schema.getType(new XsQName((String JavaDoc) null, "d"));
343       assertNotNull(d);
344       XSGroup dGroup = assertGroup(assertComplexContent(assertComplexType(d)));
345       assertSequence(dGroup);
346       XSParticle[] particles = dGroup.getParticles();
347       assertEquals(3, particles.length);
348       JAXBElement e = (JAXBElement) assertElement(particles[0]);
349       JAXBType a = (JAXBType) e.getType();
350       JAXBClass jaxbClass = a.getJAXBClass();
351       assertNotNull(jaxbClass);
352       assertEquals("b", jaxbClass.getName());
353       assertNull(jaxbClass.getImplClass());
354
355       JAXBElement f = (JAXBElement) assertElement(particles[1]);
356       assertEquals(new XsQName((String JavaDoc) null, "f"), f.getName());
357       assertNotNull(f);
358       jaxbClass = f.getJAXBClass();
359       assertNotNull(jaxbClass);
360       assertEquals("x", jaxbClass.getName());
361       assertNull(jaxbClass.getImplClass());
362
363       JAXBElement g = (JAXBElement) assertElement(particles[2]);
364       assertEquals(new XsQName((String JavaDoc) null, "g"), g.getName());
365       assertNotNull(g);
366       assertNull(g.getJAXBClass());
367     }
368
369     {
370       final String JavaDoc schemaSource =
371         "<?xml version='1.0'?>\n" +
372         "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
373         " xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" +
374         " <xs:element name='x'>\n" +
375         " <xs:annotation><xs:appinfo>\n" +
376         " <jaxb:class name='b' implClass='com.b.c'/>\n" +
377         " </xs:appinfo></xs:annotation>\n" +
378         " <xs:complexType>\n" +
379         " <xs:sequence>\n" +
380         " <xs:element name='e'>\n" +
381         " <xs:complexType>\n" +
382         " <xs:sequence>\n" +
383         " <xs:element name='x' type='xs:int'/>\n" +
384         " </xs:sequence>\n" +
385         " <xs:attribute name='y' type='xs:string'/>\n" +
386         " </xs:complexType>\n" +
387         " </xs:element>\n" +
388         " </xs:sequence>\n" +
389         " </xs:complexType>\n" +
390         " </xs:element>\n" +
391         "</xs:schema>";
392   
393       JAXBParser parser = newJAXBParser();
394       InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
395       isource.setSystemId("testJAXBClass3.xsd");
396       boolean haveException = false;
397       try {
398         parser.parse(isource);
399       } catch (SAXException JavaDoc e) {
400         haveException = true;
401         assertTrue(e.getMessage().indexOf("[JAXB 6.7.3.4]") >= 0);
402       }
403       assertTrue(haveException);
404     }
405   }
406
407   public void testJAXBProperty1() throws Exception JavaDoc {
408     final String JavaDoc schemaSource =
409       "<?xml version='1.0'?>\n" +
410       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
411       " xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" +
412       " <xs:complexType name='ct'>\n" +
413       " <xs:sequence>\n" +
414       " </xs:sequence>\n" +
415       " <xs:attribute name='a' type='xs:dateTime'>\n" +
416       " <xs:annotation><xs:appinfo>\n" +
417       " <jaxb:property name='ap' collectionType='indexed'\n" +
418       " fixedAttributeAsConstantProperty='true'\n" +
419       " generateIsSetMethod='false'\n" +
420       " enableFailFastCheck='1'>\n" +
421       " <jaxb:baseType>\n" +
422       " <jaxb:javaType name='java.math.BigDecimal'\n" +
423       " parseMethod='javax.xml.bind.DatatypeConverter.parseInteger'\n" +
424       " printMethod='javax.xml.bind.DatatypeConverter.printInteger'/>\n" +
425       " </jaxb:baseType>\n" +
426       " </jaxb:property>\n" +
427       " </xs:appinfo></xs:annotation>\n" +
428       " </xs:attribute>" +
429       " </xs:complexType>\n" +
430       "</xs:schema>\n";
431
432     JAXBParser parser = newJAXBParser();
433     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
434     isource.setSystemId("testJAXBProperty1.xsd");
435     JAXBSchema schema = (JAXBSchema) parser.parse(isource);
436     XSType type = schema.getType(new XsQName((String JavaDoc) null, "ct"));
437     XSComplexType complexType = assertComplexType(type);
438     XSAttributable[] attributes = complexType.getAttributes();
439     assertNotNull(attributes);
440     assertEquals(1, attributes.length);
441     JAXBAttribute a1 = (JAXBAttribute) attributes[0];
442     assertEquals(XSDateTime.getInstance(), a1.getType());
443     JAXBProperty ap1 = a1.getJAXBProperty();
444     assertNotNull(ap1);
445     assertEquals("ap", ap1.getName());
446     assertEquals("indexed", ap1.getCollectionType());
447     Boolean JavaDoc b = ap1.isFixedAttributeAsConstantProperty();
448     assertTrue(b != null && b.booleanValue());
449     b = ap1.isGenerateIsSetMethod();
450     assertTrue(b != null && !b.booleanValue());
451     b = ap1.isEnableFailFastCheck();
452     assertTrue(b != null && b.booleanValue());
453     JAXBProperty.BaseType apbt1 = ap1.getBaseType();
454     assertNotNull(apbt1);
455     JAXBJavaType apjt1 = apbt1.getJavaType();
456     assertNotNull(apjt1);
457     assertEquals("java.math.BigDecimal", apjt1.getName());
458     assertEquals("javax.xml.bind.DatatypeConverter.parseInteger", apjt1.getParseMethod());
459     assertEquals("javax.xml.bind.DatatypeConverter.printInteger", apjt1.getPrintMethod());
460   }
461
462   public void testJAXBProperty2() throws Exception JavaDoc {
463     final String JavaDoc schemaSource =
464       "<?xml version='1.0'?>\n" +
465       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
466       " xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" +
467       " <xs:attribute name='a' type='xs:dateTime'>\n" +
468       " <xs:annotation><xs:appinfo>\n" +
469       " <jaxb:property name='ap' collectionType='indexed'\n" +
470       " fixedAttributeAsConstantProperty='true'\n" +
471       " generateIsSetMethod='false'\n" +
472       " enableFailFastCheck='1'>\n" +
473       " <jaxb:baseType>\n" +
474       " <jaxb:javaType name='java.math.BigDecimal'\n" +
475       " parseMethod='javax.xml.bind.DatatypeConverter.parseInteger'\n" +
476       " printMethod='javax.xml.bind.DatatypeConverter.printInteger'/>\n" +
477       " </jaxb:baseType>\n" +
478       " </jaxb:property>\n" +
479       " </xs:appinfo></xs:annotation>\n" +
480       " </xs:attribute>" +
481       "</xs:schema>\n";
482
483     JAXBParser parser = newJAXBParser();
484     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
485     isource.setSystemId("testJAXBProperty2.xsd");
486     boolean haveException = false;
487     try {
488       parser.parse(isource);
489     } catch (SAXException JavaDoc e) {
490       haveException = true;
491       assertTrue(e.getMessage().indexOf("[JAXB 6.8.1.2.1]") >= 0);
492     }
493     assertTrue(haveException);
494   }
495
496   public void testJAXBProperty3() throws Exception JavaDoc {
497     final String JavaDoc schemaSource =
498       "<?xml version='1.0'?>\n" +
499       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
500       " xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" +
501       " <xs:attribute name='a' type='xs:dateTime'>\n" +
502       " <xs:annotation><xs:appinfo>\n" +
503       " <jaxb:property name='ap' collectionType='indexed'\n" +
504       " fixedAttributeAsConstantProperty='true'\n" +
505       " generateIsSetMethod='false'\n" +
506       " enableFailFastCheck='1'>\n" +
507       " </jaxb:property>\n" +
508       " </xs:appinfo></xs:annotation>\n" +
509       " </xs:attribute>" +
510       " <xs:complexType name='ct'>\n" +
511       " <xs:sequence>\n" +
512       " </xs:sequence>\n" +
513       " <xs:attribute ref='a'/>\n" +
514       " </xs:complexType>\n" +
515       "</xs:schema>\n";
516
517     JAXBParser parser = newJAXBParser();
518     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
519     isource.setSystemId("testJAXBProperty1.xsd");
520     JAXBSchema schema = (JAXBSchema) parser.parse(isource);
521     XSAttributable[] outerAttr = schema.getAttributes();
522     assertEquals(1, outerAttr.length);
523     JAXBAttribute outerA = (JAXBAttribute) outerAttr[0];
524     
525     XSType ct = schema.getType(new XsQName((String JavaDoc) null, "ct"));
526     XSAttributable[] attributes = assertComplexType(ct).getAttributes();
527     assertNotNull(attributes);
528     assertEquals(1, attributes.length);
529     JAXBAttribute a1 = (JAXBAttribute) attributes[0];
530     assertEquals(XSDateTime.getInstance(), a1.getType());
531     JAXBProperty ap1 = a1.getJAXBProperty();
532     assertEquals(ap1, outerA.getJAXBProperty());
533     assertNotNull(ap1);
534     assertEquals("ap", ap1.getName());
535     assertEquals("indexed", ap1.getCollectionType());
536     Boolean JavaDoc b = ap1.isFixedAttributeAsConstantProperty();
537     assertTrue(b != null && b.booleanValue());
538     b = ap1.isGenerateIsSetMethod();
539     assertTrue(b != null && !b.booleanValue());
540     b = ap1.isEnableFailFastCheck();
541     assertTrue(b != null && b.booleanValue());
542     assertNull(ap1.getBaseType());
543   }
544
545   public void testJAXBJavaType1() throws Exception JavaDoc {
546     final String JavaDoc schemaSource =
547       "<?xml version='1.0'?>\n" +
548       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
549       " xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" +
550       " <xs:simpleType name='a'>\n" +
551       " <xs:annotation><xs:appinfo>\n" +
552       " <jaxb:javaType name='java.math.BigDecimal'\n" +
553       " hasNsContext='0'\n" +
554       " parseMethod='javax.xml.bind.DatatypeConverter.parseInteger'\n" +
555       " printMethod='javax.xml.bind.DatatypeConverter.printInteger'/>\n" +
556       " </xs:appinfo></xs:annotation>\n" +
557       " <xs:restriction base='xs:string'/>\n" +
558       " </xs:simpleType>\n" +
559       " <xs:element name='b'>\n" +
560       " <xs:simpleType>\n" +
561       " <xs:restriction base='a'/>\n" +
562       " </xs:simpleType>\n" +
563       " </xs:element>\n" +
564       " <xs:element name='c'>\n" +
565       " <xs:simpleType>\n" +
566       " <xs:annotation><xs:appinfo>\n" +
567       " <jaxb:javaType name='java.math.BigInteger'\n" +
568       " hasNsContext='true'\n" +
569       " parseMethod='javax.xml.bind.DatatypeConverter.parseInt'\n" +
570       " printMethod='javax.xml.bind.DatatypeConverter.printInt'/>\n" +
571       " </xs:appinfo></xs:annotation>\n" +
572       " <xs:restriction base='a'/>\n" +
573       " </xs:simpleType>\n" +
574       " </xs:element>\n" +
575       "</xs:schema>\n";
576
577     JAXBParser parser = newJAXBParser();
578     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
579     isource.setSystemId("testJAXBJavaType1.xsd");
580     JAXBSchema schema = (JAXBSchema) parser.parse(isource);
581     XSType a = schema.getType(new XsQName((String JavaDoc) null, "a"));
582     JAXBSimpleType ast = (JAXBSimpleType) assertSimpleType(a);
583     JAXBJavaType ajjt = ast.getJAXBJavaType();
584     assertEquals("java.math.BigDecimal", ajjt.getName());
585     assertEquals("javax.xml.bind.DatatypeConverter.parseInteger", ajjt.getParseMethod());
586     assertEquals("javax.xml.bind.DatatypeConverter.printInteger", ajjt.getPrintMethod());
587     assertTrue(!ajjt.hasNsContext());
588
589     XSElement b = schema.getElement(new XsQName((String JavaDoc) null, "b"));
590     XSType bt = b.getType();
591     JAXBSimpleType bst = (JAXBSimpleType) assertSimpleType(bt);
592     assertEquals(a, assertRestriction(bst));
593     assertNull(bst.getJAXBJavaType());
594
595     XSElement c = schema.getElement(new XsQName((String JavaDoc) null, "c"));
596     XSType ct = c.getType();
597     JAXBSimpleType cst = (JAXBSimpleType) assertSimpleType(ct);
598     assertEquals(a, assertRestriction(cst));
599     JAXBJavaType cjjt = cst.getJAXBJavaType();
600     assertEquals("java.math.BigInteger", cjjt.getName());
601     assertEquals("javax.xml.bind.DatatypeConverter.parseInt", cjjt.getParseMethod());
602     assertEquals("javax.xml.bind.DatatypeConverter.printInt", cjjt.getPrintMethod());
603     assertTrue(cjjt.hasNsContext());
604   }
605
606   private void checkJAXBTypesafeEnumClass1AType(XSType pType) throws SAXException JavaDoc {
607     JAXBSimpleType ast = (JAXBSimpleType) assertSimpleType(pType);
608     JAXBTypesafeEnumClass aec = ast.getJAXBTypesafeEnumClass();
609     assertEquals("USStateAbbr", aec.getName());
610     assertTrue(!aec.getTypesafeEnumMember().hasNext());
611     XSEnumeration[] enumerations = ast.getEnumerations();
612     assertEquals(2, enumerations.length);
613     JAXBEnumeration e1 = (JAXBEnumeration) enumerations[0];
614     assertEquals("AK", e1.getValue());
615     JAXBTypesafeEnumMember m1 = e1.getJAXBTypesafeEnumMember();
616     assertEquals("STATE_AK", m1.getName());
617     JAXBEnumeration e2 = (JAXBEnumeration) enumerations[1];
618     JAXBTypesafeEnumMember m2 = e2.getJAXBTypesafeEnumMember();
619     assertEquals("STATE_AL", m2.getName());
620     assertEquals("AL", e2.getValue());
621   }
622
623   private void checkJAXBTypesafeEnumClass1BType(XSType pType) throws SAXException JavaDoc {
624     JAXBSimpleType bst = (JAXBSimpleType) assertSimpleType(pType);
625     JAXBTypesafeEnumClass bec = bst.getJAXBTypesafeEnumClass();
626     assertEquals("USStateAbbr2", bec.getName());
627     Iterator JavaDoc iter = bec.getTypesafeEnumMember();
628     assertTrue(iter.hasNext());
629     JAXBTypesafeEnumMember iem = (JAXBTypesafeEnumMember) iter.next();
630     assertEquals("STATE2_AK", iem.getName());
631     assertEquals("AK", iem.getValue());
632     assertTrue(iter.hasNext());
633     iem = (JAXBTypesafeEnumMember) iter.next();
634     assertEquals("STATE2_AL", iem.getName());
635     assertEquals("AL", iem.getValue());
636     assertTrue(!iter.hasNext());
637     XSEnumeration[] enumerations = bst.getEnumerations();
638     assertEquals(2, enumerations.length);
639     JAXBEnumeration be1 = (JAXBEnumeration) enumerations[0];
640     assertEquals("AK", be1.getValue());
641     assertNull(be1.getJAXBTypesafeEnumMember());
642     JAXBEnumeration be2 = (JAXBEnumeration) enumerations[1];
643     assertEquals("AL", be2.getValue());
644     assertNull(be2.getJAXBTypesafeEnumMember());
645   }
646
647   public void testJAXBTypesafeEnumClass1() throws Exception JavaDoc {
648     final String JavaDoc schemaSource =
649       "<?xml version='1.0'?>\n" +
650       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
651       " xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" +
652       " <xs:simpleType name='a'>\n" +
653       " <xs:annotation><xs:appinfo>\n" +
654       " <jaxb:typesafeEnumClass name='USStateAbbr'/>\n" +
655       " </xs:appinfo></xs:annotation>\n" +
656       " <xs:restriction base='xs:NCName'>\n" +
657       " <xs:enumeration value='AK'>\n" +
658       " <xs:annotation><xs:appinfo>\n" +
659       " <jaxb:typesafeEnumMember name='STATE_AK'/>\n" +
660       " </xs:appinfo></xs:annotation>\n" +
661       " </xs:enumeration>\n" +
662       " <xs:enumeration value='AL'>\n" +
663       " <xs:annotation><xs:appinfo>\n" +
664       " <jaxb:typesafeEnumMember name='STATE_AL'/>\n" +
665       " </xs:appinfo></xs:annotation>\n" +
666       " </xs:enumeration>\n" +
667       " </xs:restriction>\n" +
668       " </xs:simpleType>\n" +
669       " <xs:simpleType name='b'>\n" +
670       " <xs:annotation><xs:appinfo>\n" +
671       " <jaxb:typesafeEnumClass name='USStateAbbr2'>\n" +
672       " <jaxb:typesafeEnumMember name='STATE2_AK' value='AK'/>\n" +
673       " <jaxb:typesafeEnumMember name='STATE2_AL' value='AL'/>\n" +
674       " </jaxb:typesafeEnumClass>\n" +
675       " </xs:appinfo></xs:annotation>\n" +
676       " <xs:restriction base='xs:NCName'>\n" +
677       " <xs:enumeration value='AK'/>\n" +
678       " <xs:enumeration value='AL'/>\n" +
679       " </xs:restriction>\n" +
680       " </xs:simpleType>\n" +
681       "\n" +
682       " <xs:element name='allTypes'>\n" +
683       " <xs:complexType>\n" +
684       " <xs:sequence>\n" +
685       " <xs:element name='aElement' type='a'/>\n" +
686       " <xs:element name='bElement' type='b'/>\n" +
687       " </xs:sequence>\n" +
688       " </xs:complexType>\n" +
689       " </xs:element>\n" +
690       "</xs:schema>\n";
691
692     JAXBParser parser = newJAXBParser();
693     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
694     isource.setSystemId("testJAXBJavaTypesafeEnumClass1.xsd");
695     JAXBSchema schema = (JAXBSchema) parser.parse(isource);
696     XSType a = schema.getType(new XsQName((String JavaDoc) null, "a"));
697     checkJAXBTypesafeEnumClass1AType(a);
698
699     XSType b = schema.getType(new XsQName((String JavaDoc) null, "b"));
700     checkJAXBTypesafeEnumClass1BType(b);
701
702     XSElement[] elements = schema.getElements();
703     assertEquals(1, elements.length);
704     XSElement allTypesElement = elements[0];
705     XSGroup allTypesGroup = assertGroup(assertComplexContent(assertComplexType(allTypesElement.getType())));
706     assertSequence(allTypesGroup);
707     XSParticle[] allTypesChilds = allTypesGroup.getParticles();
708     assertEquals(2, allTypesChilds.length);
709     checkJAXBTypesafeEnumClass1AType(assertElement(allTypesChilds[0]).getType());
710     checkJAXBTypesafeEnumClass1BType(assertElement(allTypesChilds[1]).getType());
711   }
712
713   public void testJAXBTypesafeEnumClass2() throws Exception JavaDoc {
714     final String JavaDoc schemaSource =
715       "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xml:lang='EN'\n" +
716       " targetNamespace='http://ws.apache.org/jaxme/examples/misc/enumeration'\n" +
717       " xmlns:ex='http://ws.apache.org/jaxme/examples/misc/enumeration'\n" +
718       " xmlns:jaxb='http://java.sun.com/xml/ns/jaxb'\n" +
719       " elementFormDefault='qualified'\n" +
720       " attributeFormDefault='unqualified'>\n" +
721       " <xs:annotation>\n" +
722       " <xs:documentation>\n" +
723       " Demonstration of a complex type with all sorts of enumeration values\n" +
724       " </xs:documentation>\n" +
725       " <xs:appinfo>\n" +
726       " <jaxb:globalBindings typesafeEnumBase='xs:string xs:int xs:long xs:short xs:double xs:float'/>\n" +
727       " </xs:appinfo>\n" +
728       " </xs:annotation>\n" +
729       "\n" +
730       " <!-- In this example the typesafeEnumMember instances are part of the\n" +
731       " typesafeEnumClass. -->\n" +
732       " <xs:simpleType name='StringType'>\n" +
733       " <xs:annotation>\n" +
734       " <xs:appinfo>\n" +
735       " <jaxb:typesafeEnumClass name='MyStringTypeClass'>\n" +
736       " <jaxb:typesafeEnumMember name='FOO' value='FOO'/>\n" +
737       " <jaxb:typesafeEnumMember name='BAR' value='BAR'/>\n" +
738       " </jaxb:typesafeEnumClass>\n" +
739       " </xs:appinfo>\n" +
740       " </xs:annotation>\n" +
741       " <xs:restriction base='xs:string'>\n" +
742       " <xs:enumeration value='FOO'/>\n" +
743       " <xs:enumeration value='BAR'/>\n" +
744       " </xs:restriction>\n" +
745       " </xs:simpleType>\n" +
746       "\n" +
747       " <!-- Here's another case: The typesafeEnumMember instances are part\n" +
748       " of their respective values. Choose your own style. -->\n" +
749       " <xs:simpleType name='IntType'>\n" +
750       " <xs:annotation><xs:appinfo>\n" +
751       " <jaxb:typesafeEnumClass name='MyIntTypeClass'/>\n" +
752       " </xs:appinfo></xs:annotation>\n" +
753       " <xs:restriction base='xs:int'>\n" +
754       " <xs:enumeration value='3'>\n" +
755       " <xs:annotation><xs:appinfo>\n" +
756       " <jaxb:typesafeEnumMember name='INT3'/>\n" +
757       " </xs:appinfo></xs:annotation>\n" +
758       " </xs:enumeration>\n" +
759       " <xs:enumeration value='0'>\n" +
760       " <xs:annotation><xs:appinfo>\n" +
761       " <jaxb:typesafeEnumMember name='INT0'/>\n" +
762       " </xs:appinfo></xs:annotation>\n" +
763       " </xs:enumeration>\n" +
764       " <xs:enumeration value='-7'>\n" +
765       " <xs:annotation><xs:appinfo>\n" +
766       " <jaxb:typesafeEnumMember name='INT_7'/>\n" +
767       " </xs:appinfo></xs:annotation>\n" +
768       " </xs:enumeration>\n" +
769       " </xs:restriction>\n" +
770       " </xs:simpleType>\n" +
771       "\n" +
772       " <!-- I personally prefer the former style, for shortness. So we\n" +
773       " revert to this style. -->\n" +
774       " <xs:simpleType name='LongType'>\n" +
775       " <xs:annotation><xs:appinfo>\n" +
776       " <jaxb:typesafeEnumClass name='MyLongTypeClass'>\n" +
777       " <jaxb:typesafeEnumMember name='LONG_POSITIVE' value='987298379879887'/>\n" +
778       " <jaxb:typesafeEnumMember name='LONG_ZERO' value='0'/>\n" +
779       " <jaxb:typesafeEnumMember name='LONG_NEGATIVE' value='-23987982739273989'/>\n" +
780       " </jaxb:typesafeEnumClass>\n" +
781       " </xs:appinfo></xs:annotation>\n" +
782       " <xs:restriction base='xs:long'>\n" +
783       " <xs:enumeration value='987298379879887'/>\n" +
784       " <xs:enumeration value='0'/>\n" +
785       " <xs:enumeration value='-23987982739273989'/>\n" +
786       " </xs:restriction>\n" +
787       " </xs:simpleType>\n" +
788       "\n" +
789       " <xs:simpleType name='ShortType'>\n" +
790       " <xs:annotation><xs:appinfo>\n" +
791       " <jaxb:typesafeEnumClass name='MyShortTypeClass'>\n" +
792       " <jaxb:typesafeEnumMember name='SHORT_POSITIVE' value='3468'/>\n" +
793       " <jaxb:typesafeEnumMember name='SHORT_ZERO' value='0'/>\n" +
794       " <jaxb:typesafeEnumMember name='SHORT_NEGATIVE' value='-23'/>\n" +
795       " </jaxb:typesafeEnumClass>\n" +
796       " </xs:appinfo></xs:annotation>\n" +
797       " <xs:restriction base='xs:short'>\n" +
798       " <xs:enumeration value='3468'/>\n" +
799       " <xs:enumeration value='0'/>\n" +
800       " <xs:enumeration value='-23'/>\n" +
801       " </xs:restriction>\n" +
802       " </xs:simpleType>\n" +
803       "\n" +
804       " <xs:simpleType name='DoubleType'>\n" +
805       " <xs:annotation><xs:appinfo>\n" +
806       " <jaxb:typesafeEnumClass name='MyDoubleTypeClass'>\n" +
807       " <jaxb:typesafeEnumMember name='DOUBLE_POSITIVE' value='3249239847982.234'/>\n" +
808       " <jaxb:typesafeEnumMember name='DOUBLE_ZERO' value='0'/>\n" +
809       " <jaxb:typesafeEnumMember name='DOUBLE_NEGATIVE' value='-324234.234'/>\n" +
810       " </jaxb:typesafeEnumClass>\n" +
811       " </xs:appinfo></xs:annotation>\n" +
812       " <xs:restriction base='xs:double'>\n" +
813       " <xs:enumeration value='3249239847982.234'/>\n" +
814       " <xs:enumeration value='0'/>\n" +
815       " <xs:enumeration value='-324234.234'/>\n" +
816       " </xs:restriction>\n" +
817       " </xs:simpleType>\n" +
818       "\n" +
819       " <xs:simpleType name='FloatType'>\n" +
820       " <xs:annotation><xs:appinfo>\n" +
821       " <jaxb:typesafeEnumClass name='MyFloatTypeClass'>\n" +
822       " <jaxb:typesafeEnumMember name='FLOAT_POSITIVE' value='47982.234'/>\n" +
823       " <jaxb:typesafeEnumMember name='FLOAT_ZERO' value='0'/>\n" +
824       " <jaxb:typesafeEnumMember name='FLOAT_NEGATIVE' value='-24234.234'/>\n" +
825       " </jaxb:typesafeEnumClass>\n" +
826       " </xs:appinfo></xs:annotation>\n" +
827       " <xs:restriction base='xs:float'>\n" +
828       " <xs:enumeration value='47982.234'/>\n" +
829       " <xs:enumeration value='0'/>\n" +
830       " <xs:enumeration value='-24234.234'/>\n" +
831       " </xs:restriction>\n" +
832       " </xs:simpleType>\n" +
833       "\n" +
834       " <xs:complexType name='AllSimpleTypes'>\n" +
835       " <xs:sequence>\n" +
836       " <xs:element name='StringElem' type='ex:StringType'/>\n" +
837       " <xs:element name='IntElem' type='ex:IntType'/>\n" +
838       " <xs:element name='LongElem' type='ex:LongType'/>\n" +
839       " <xs:element name='ShortElem' type='ex:ShortType'/>\n" +
840       " <xs:element name='DoubleElem' type='ex:DoubleType'/>\n" +
841       " <xs:element name='FloatElem' type='ex:FloatType'/>\n" +
842       " <xs:element name='DateTimeElem' minOccurs='0'>\n" +
843       " <xs:simpleType>\n" +
844       " <xs:restriction base='xs:dateTime'>\n" +
845       " <xs:enumeration value='2002-12-17T12:23:11'/>\n" +
846       " <xs:enumeration value='2002-12-16T12:00:11'/>\n" +
847       " </xs:restriction>\n" +
848       " </xs:simpleType>\n" +
849       " </xs:element>\n" +
850       " <xs:element name='DateElem' minOccurs='0'>\n" +
851       " <xs:simpleType>\n" +
852       " <xs:restriction base='xs:date'>\n" +
853       " <xs:enumeration value='2002-12-17'/>\n" +
854       " <xs:enumeration value='2002-12-16'/>\n" +
855       " </xs:restriction>\n" +
856       " </xs:simpleType>\n" +
857       " </xs:element>\n" +
858       " <xs:element name='TimeElem' minOccurs='0'>\n" +
859       " <xs:simpleType>\n" +
860       " <xs:restriction base='xs:time'>\n" +
861       " <xs:enumeration value='12:23:11'/>\n" +
862       " <xs:enumeration value='12:00:11'/>\n" +
863       " </xs:restriction>\n" +
864       " </xs:simpleType>\n" +
865       " </xs:element>\n" +
866       " </xs:sequence>\n" +
867       " </xs:complexType>\n" +
868       "\n" +
869       " <xs:element name='AllTypesElement'>\n" +
870       " <xs:complexType>\n" +
871       " <xs:sequence>\n" +
872       " <xs:element type='ex:AllSimpleTypes' name='AllSimpleTypesElement'/>\n" +
873       " </xs:sequence>\n" +
874       " </xs:complexType>\n" +
875       " </xs:element>\n" +
876       "</xs:schema>\n";
877
878     JAXBParser parser = newJAXBParser();
879     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(schemaSource));
880     isource.setSystemId("testJAXBJavaTypesafeEnumClass2.xsd");
881     JAXBSchema schema = (JAXBSchema) parser.parse(isource);
882
883     XSType[] types = schema.getTypes();
884     assertEquals(7, types.length);
885
886
887     XSType stringType = types[0];
888     checkJAXBTypesafeEnumClass2StringType(stringType);
889
890     XSElement[] elements = schema.getElements();
891     assertEquals(1, elements.length);
892
893     XSElement allTypesElement = elements[0];
894     XSParticle allTypesElementParticle = assertComplexContent(assertComplexType(allTypesElement.getType()));
895     XSGroup group = allTypesElementParticle.getGroup();
896     assertSequence(group);
897     XSParticle[] allTypesElementsChilds = group.getParticles();
898     assertEquals(1, allTypesElementsChilds.length);
899     XSElement allSimpleTypesElement = assertElement(allTypesElementsChilds[0]);
900     XSParticle allSimpleTypesElementParticle = assertComplexContent(assertComplexType(allSimpleTypesElement.getType()));
901     XSGroup allSimpleTypesElementGroup = allSimpleTypesElementParticle.getGroup();
902     assertSequence(allSimpleTypesElementGroup);
903     XSParticle[] allSimpleTypesElementChilds = allSimpleTypesElementGroup.getParticles();
904     assertEquals(9, allSimpleTypesElementChilds.length);
905
906     XSElement stringTypeElement = assertElement(allSimpleTypesElementChilds[0]);
907     checkJAXBTypesafeEnumClass2StringType(stringTypeElement.getType());
908   }
909
910   private void checkJAXBTypesafeEnumClass2StringType(XSType pType) throws SAXException JavaDoc {
911     XSSimpleType stStringType = assertSimpleType(pType);
912     assertEquals(XSString.getInstance(), assertRestriction(stStringType));
913     assertTrue(stStringType instanceof JAXBSimpleType);
914     JAXBSimpleType jaxbStringType = (JAXBSimpleType) stStringType;
915     JAXBTypesafeEnumClass typesafeEnumClass = jaxbStringType.getJAXBTypesafeEnumClass();
916     assertNotNull(typesafeEnumClass);
917     assertEquals("MyStringTypeClass", typesafeEnumClass.getName());
918   }
919 }
920
Popular Tags