1 17 package org.apache.ws.jaxme.junit; 18 19 import java.io.StringReader ; 20 import java.math.BigInteger ; 21 import java.util.ArrayList ; 22 import java.util.Calendar ; 23 24 import org.apache.ws.jaxme.generator.Generator; 25 import org.apache.ws.jaxme.generator.impl.GeneratorImpl; 26 import org.apache.ws.jaxme.generator.sg.AttributeSG; 27 import org.apache.ws.jaxme.generator.sg.ComplexContentSG; 28 import org.apache.ws.jaxme.generator.sg.ComplexTypeSG; 29 import org.apache.ws.jaxme.generator.sg.Facet; 30 import org.apache.ws.jaxme.generator.sg.GroupSG; 31 import org.apache.ws.jaxme.generator.sg.ListTypeSG; 32 import org.apache.ws.jaxme.generator.sg.ObjectSG; 33 import org.apache.ws.jaxme.generator.sg.ParticleSG; 34 import org.apache.ws.jaxme.generator.sg.SGFactory; 35 import org.apache.ws.jaxme.generator.sg.SchemaSG; 36 import org.apache.ws.jaxme.generator.sg.SimpleContentSG; 37 import org.apache.ws.jaxme.generator.sg.SimpleTypeSG; 38 import org.apache.ws.jaxme.generator.sg.TypeSG; 39 import org.apache.ws.jaxme.generator.sg.UnionTypeSG; 40 import org.apache.ws.jaxme.generator.sg.impl.JAXBSGFactory; 41 import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaReader; 42 import org.apache.ws.jaxme.generator.sg.impl.SGFactoryImpl; 43 import org.apache.ws.jaxme.js.JavaQNameImpl; 44 import org.apache.ws.jaxme.xs.XSAttributable; 45 import org.apache.ws.jaxme.xs.XSAttribute; 46 import org.apache.ws.jaxme.xs.XSComplexType; 47 import org.apache.ws.jaxme.xs.XSElement; 48 import org.apache.ws.jaxme.xs.XSParser; 49 import org.apache.ws.jaxme.xs.XSSchema; 50 import org.apache.ws.jaxme.xs.jaxb.JAXBAttribute; 51 import org.apache.ws.jaxme.xs.jaxb.JAXBJavaType; 52 import org.apache.ws.jaxme.xs.jaxb.impl.JAXBParser; 53 import org.apache.ws.jaxme.xs.types.XSID; 54 import org.apache.ws.jaxme.xs.xml.XsQName; 55 import org.xml.sax.InputSource ; 56 import org.xml.sax.SAXException ; 57 58 59 64 public class ParserTest extends BaseTestCase { 65 public ParserTest(String arg) { super(arg); } 66 67 protected SchemaSG parse(String pSchema, String pSystemId) throws Exception { 68 JAXBSchemaReader r = getSchemaReader(); 69 InputSource isource = new InputSource (new StringReader (pSchema)); 70 isource.setSystemId(pSystemId); 71 return r.parse(isource); 72 } 73 74 protected JAXBSchemaReader getSchemaReader() { 75 Generator generator = new GeneratorImpl(); 76 JAXBSchemaReader r = new JAXBSchemaReader(); 77 generator.setSchemaReader(r); 78 r.setGenerator(generator); 79 return r; 80 } 81 82 public void testSimpleTypes() throws Exception { 83 final String schema = 84 "<?xml version='1.0'?>\n" + 85 "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" + 86 " <xs:simpleType name='a'>\n" + 87 " <xs:restriction base='xs:string'>\n" + 88 " <xs:minLength value='3'/>\n" + 89 " </xs:restriction>\n" + 90 " </xs:simpleType>\n" + 91 "\n" + 92 " <xs:simpleType name='b'>\n" + 93 " <xs:list itemType='xs:int'/>\n" + 94 " </xs:simpleType>\n" + 95 "\n" + 96 " <xs:simpleType name='c'>\n" + 97 " <xs:union memberTypes='a b'/>\n" + 98 " </xs:simpleType>\n" + 99 "</xs:schema>\n"; 100 101 SchemaSG schemaSG = parse(schema, "testSimpleTypes.xsd"); 102 103 TypeSG[] st = schemaSG.getTypes(); 104 assertEquals(3, st.length); 105 106 TypeSG st1 = st[0]; 107 assertTrue(!st1.isComplex()); 108 SimpleTypeSG sst1 = st1.getSimpleTypeSG(); 109 assertTrue(sst1.isAtomic()); 110 assertTrue(!sst1.isList()); 111 assertTrue(!sst1.isUnion()); 112 assertEquals(sst1.getRuntimeType(), JavaQNameImpl.getInstance(String .class)); 113 114 TypeSG st2 = st[1]; 115 assertTrue(!st2.isComplex()); 116 SimpleTypeSG sst2 = st2.getSimpleTypeSG(); 117 assertTrue(!sst2.isAtomic()); 118 assertTrue(sst2.isList()); 119 assertTrue(!sst2.isUnion()); 120 ListTypeSG lt = sst2.getListType(); 121 assertNotNull(lt.getItemType()); 122 TypeSG sst = lt.getItemType(); 123 assertTrue(!sst.isComplex()); 124 SimpleTypeSG it = sst.getSimpleTypeSG(); 125 assertEquals(JavaQNameImpl.INT, it.getRuntimeType()); 126 127 TypeSG st3 = st[2]; 128 assertEquals(false, st3.isComplex()); 129 SimpleTypeSG sst3 = st3.getSimpleTypeSG(); 130 assertEquals(false, sst3.isAtomic()); 131 assertEquals(false, sst3.isList()); 132 assertEquals(true, sst3.isUnion()); 133 UnionTypeSG ut = sst3.getUnionType(); 134 TypeSG[] uTypes = ut.getMemberTypes(); 135 assertEquals(2, uTypes.length); 136 } 137 138 public void testAttributes() throws Exception { 139 final String schema = 140 "<?xml version='1.0'?>\n" + 141 "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" + 142 " <xs:annotation><xs:appinfo>\n" + 143 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 144 " <jaxb:package name='parsertest.testattributes'/>\n" + 145 " </jaxb:schemaBindings>\n" + 146 " </xs:appinfo></xs:annotation>\n" + 147 " <xs:attribute name='a' type='xs:string'/>\n" + 148 "\n" + 149 " <xs:attribute name='b'>\n" + 150 " <xs:simpleType>\n" + 151 " <xs:restriction base='xs:int'/>\n" + 152 " </xs:simpleType>\n" + 153 " </xs:attribute>\n" + 154 "\n" + 155 " <xs:complexType name='attributesOwner'>\n" + 156 " <xs:attribute ref='a'/>\n" + 157 " <xs:attribute ref='b'/>\n" + 158 " <xs:attribute name='c' type='xs:int'/>\n" + 159 " </xs:complexType>\n" + 160 "</xs:schema>\n"; 161 162 SchemaSG jschema = parse(schema, "testAttributes.xsd"); 163 164 TypeSG[] types = jschema.getTypes(); 165 assertEquals(1, types.length); 166 assertTrue(types[0].isComplex()); 167 168 AttributeSG[] attr = types[0].getComplexTypeSG().getAttributes(); 169 assertEquals(3, attr.length); 170 171 AttributeSG attr1 = attr[0]; 172 assertTrue(!attr1.getTypeSG().isComplex()); 173 SimpleTypeSG sst1 = attr1.getTypeSG().getSimpleTypeSG(); 174 assertTrue(sst1.isAtomic()); 175 assertEquals(JavaQNameImpl.getInstance(String .class), sst1.getRuntimeType()); 176 177 AttributeSG attr2 = attr[1]; 178 assertTrue(!attr2.getTypeSG().isComplex()); 179 SimpleTypeSG sst2 = attr2.getTypeSG().getSimpleTypeSG(); 180 assertTrue(sst2.isAtomic()); 181 assertEquals(JavaQNameImpl.INT, sst2.getRuntimeType()); 182 183 AttributeSG attr3 = attr[2]; 184 assertTrue(!attr3.getTypeSG().isComplex()); 185 SimpleTypeSG sst3 = attr3.getTypeSG().getSimpleTypeSG(); 186 assertTrue(sst3.isAtomic()); 187 assertEquals(JavaQNameImpl.INT, sst3.getRuntimeType()); 188 } 189 190 public void testAttributeGroups() throws Exception { 191 final String schema = 192 "<?xml version='1.0'?>\n" + 193 "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" + 194 " <xs:annotation><xs:appinfo>\n" + 195 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 196 " <jaxb:package name='parsertest.testattributegroups'/>\n" + 197 " </jaxb:schemaBindings>\n" + 198 " </xs:appinfo></xs:annotation>\n" + 199 " <xs:attribute name='a' type='xs:string'/>\n" + 200 " <xs:attribute name='b' type='xs:int'/>\n" + 201 "\n" + 202 " <xs:attributeGroup name='c'>\n" + 203 " <xs:attribute name='d' type='xs:dateTime'/>\n" + 204 " <xs:attribute name='e' type='xs:float'/>\n" + 205 " <xs:attribute ref='a'/>\n" + 206 " </xs:attributeGroup>\n" + 207 "\n" + 208 " <xs:attributeGroup name='f'>\n" + 209 " <xs:attribute name='g' type='xs:double'/>\n" + 210 " <xs:attributeGroup ref='c'/>\n" + 211 " <xs:attribute ref='b'/>\n" + 212 " </xs:attributeGroup>\n" + 213 "\n" + 214 " <xs:element name='ea'>\n" + 215 " <xs:complexType>\n" + 216 " <xs:attributeGroup ref='c'/>\n" + 217 " </xs:complexType>\n" + 218 " </xs:element>\n" + 219 "\n" + 220 " <xs:element name='eb'>\n" + 221 " <xs:complexType>\n" + 222 " <xs:attributeGroup ref='f'/>\n" + 223 " </xs:complexType>\n" + 224 " </xs:element>\n" + 225 "</xs:schema>\n"; 226 227 SchemaSG jschema = parse(schema, "testAttributeGroups.xsd"); 228 229 ObjectSG[] elements = jschema.getElements(); 230 assertNotNull(elements); 231 assertEquals(2, elements.length); 232 233 ObjectSG ea = elements[0]; 234 assertTrue(ea.getTypeSG().isComplex()); 235 ComplexTypeSG eact = ea.getTypeSG().getComplexTypeSG(); 236 AttributeSG[] eactAttr = eact.getAttributes(); 237 assertEquals(3, eactAttr.length); 238 assertEquals(new XsQName((String ) null, "d"), eactAttr[0].getName()); 239 assertEquals(eactAttr[0].getTypeSG().getSimpleTypeSG().getRuntimeType(), JavaQNameImpl.getInstance(Calendar .class)); 240 assertEquals(new XsQName((String ) null, "e"), eactAttr[1].getName()); 241 assertEquals(eactAttr[1].getTypeSG().getSimpleTypeSG().getRuntimeType(), JavaQNameImpl.getInstance(float.class)); 242 assertEquals(new XsQName((String ) null, "a"), eactAttr[2].getName()); 243 assertEquals(eactAttr[2].getTypeSG().getSimpleTypeSG().getRuntimeType(), JavaQNameImpl.getInstance(String .class)); 244 245 ObjectSG eb = elements[1]; 246 assertTrue(eb.getTypeSG().isComplex()); 247 ComplexTypeSG ebct = eb.getTypeSG().getComplexTypeSG(); 248 AttributeSG[] ebctAttr = ebct.getAttributes(); 249 assertEquals(5, ebctAttr.length); 250 assertEquals(new XsQName((String ) null, "g"), ebctAttr[0].getName()); 251 assertEquals(ebctAttr[0].getTypeSG().getSimpleTypeSG().getRuntimeType(), JavaQNameImpl.getInstance(double.class)); 252 assertEquals(new XsQName((String ) null, "d"), ebctAttr[1].getName()); 253 assertEquals(ebctAttr[1].getTypeSG().getSimpleTypeSG().getRuntimeType(), JavaQNameImpl.getInstance(Calendar .class)); 254 assertEquals(ebctAttr[2].getTypeSG().getSimpleTypeSG().getRuntimeType(), JavaQNameImpl.getInstance(float.class)); 255 assertEquals(ebctAttr[3].getTypeSG().getSimpleTypeSG().getRuntimeType(), JavaQNameImpl.getInstance(String .class)); 256 assertEquals(ebctAttr[4].getTypeSG().getSimpleTypeSG().getRuntimeType(), JavaQNameImpl.getInstance(int.class)); 257 } 258 259 public void testElements() throws Exception { 260 final String schema = 261 "<?xml version='1.0'?>\n" + 262 "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" + 263 " <xs:annotation><xs:appinfo>\n" + 264 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 265 " <jaxb:package name='parsertest.testelements'/>\n" + 266 " </jaxb:schemaBindings>\n" + 267 " </xs:appinfo></xs:annotation>\n" + 268 " <xs:element name='a' type='xs:string'/>\n" + 269 "\n" + 270 " <xs:element name='b'>\n" + 271 " <xs:simpleType>\n" + 272 " <xs:restriction base='xs:float'/>\n" + 273 " </xs:simpleType>\n" + 274 " </xs:element>\n" + 275 "\n" + 276 " <xs:element name='c'>\n" + 277 " <xs:complexType>\n" + 278 " <xs:annotation>\n" + 279 " <xs:documentation>\n" + 280 " The type of 'c'.\n" + 281 " </xs:documentation>\n" + 282 " </xs:annotation>\n" + 283 " <xs:sequence>\n" + 284 " <xs:element ref='a'/>\n" + 285 " <xs:element name='d' type='xs:double'>\n" + 286 " <xs:annotation>\n" + 287 " <xs:documentation>\n" + 288 " The element 'd'.\n" + 289 " </xs:documentation>\n" + 290 " </xs:annotation>\n" + 291 " </xs:element>\n" + 292 " </xs:sequence>\n" + 293 " <xs:attribute name='e' type='xs:int'>\n" + 294 " <xs:annotation>\n" + 295 " <xs:documentation>\n" + 296 " The attribute 'e'.\n" + 297 " </xs:documentation>\n" + 298 " </xs:annotation>\n" + 299 " </xs:attribute>\n" + 300 " </xs:complexType>\n" + 301 " </xs:element>\n" + 302 "\n" + 303 " <xs:element name='f'>\n" + 304 " <xs:complexType>\n" + 305 " <xs:simpleContent>\n" + 306 " <xs:extension base='xs:int'>\n" + 307 " <xs:attribute name='g' type='xs:boolean'/>\n" + 308 " </xs:extension>\n" + 309 " </xs:simpleContent>\n" + 310 " </xs:complexType>\n" + 311 " </xs:element>\n" + 312 "</xs:schema>\n"; 313 314 System.err.println("testElements: ->"); 315 SchemaSG jschema = parse(schema, "testElements.xsd"); 316 317 ObjectSG[] elements = jschema.getElements(); 318 assertEquals(4, elements.length); 319 320 ObjectSG e1 = elements[0]; 321 assertEquals(new XsQName((String ) null, "a"), e1.getName()); 322 TypeSG t1 = e1.getTypeSG(); 323 assertTrue(!t1.isComplex()); 324 assertTrue(t1.getSimpleTypeSG().isAtomic()); 325 assertEquals(t1.getSimpleTypeSG().getRuntimeType(), JavaQNameImpl.getInstance(String .class)); 326 327 ObjectSG e2 = elements[1]; 328 assertEquals(new XsQName((String ) null, "b"), e2.getName()); 329 TypeSG t2 = e2.getTypeSG(); 330 assertTrue(!t2.isComplex()); 331 SimpleTypeSG st2 = t2.getSimpleTypeSG(); 332 assertTrue(st2.isAtomic()); 333 assertEquals(JavaQNameImpl.getInstance(float.class), st2.getRuntimeType()); 334 335 ObjectSG e3 = elements[2]; 336 assertEquals(new XsQName((String ) null, "c"), e3.getName()); 337 TypeSG t3 = e3.getTypeSG(); 338 assertTrue(t3.isComplex()); 339 ComplexTypeSG ct3 = t3.getComplexTypeSG(); 340 assertTrue(!ct3.hasSimpleContent()); 341 ComplexContentSG cct3 = ct3.getComplexContentSG(); 342 ParticleSG[] childs = cct3.getRootParticle().getGroupSG().getParticles(); 343 assertEquals(2, childs.length); 344 assertTrue(childs[0].isElement()); 345 ObjectSG child1 = childs[0].getObjectSG(); 346 assertEquals(new XsQName((String ) null, "a"), child1.getName()); 347 assertTrue(childs[1].isElement()); 348 ObjectSG child2 = childs[1].getObjectSG(); 349 assertEquals(new XsQName((String ) null, "d"), child2.getName()); 350 assertTrue(!child2.getTypeSG().isComplex()); 351 SimpleTypeSG st4 = child2.getTypeSG().getSimpleTypeSG(); 352 assertEquals(JavaQNameImpl.getInstance(double.class), st4.getRuntimeType()); 353 AttributeSG[] attributes = ct3.getAttributes(); 354 assertEquals(1, attributes.length); 355 assertEquals(new XsQName((String ) null, "e"), attributes[0].getName()); 356 assertTrue(!attributes[0].getTypeSG().isComplex()); 357 358 ObjectSG e4 = elements[3]; 359 assertTrue(e4.getTypeSG().isComplex()); 360 ComplexTypeSG ct4 = e4.getTypeSG().getComplexTypeSG(); 361 assertTrue(ct4.hasSimpleContent()); 362 SimpleContentSG sct4 = ct4.getSimpleContentSG(); 363 assertTrue(!sct4.getContentTypeSG().isComplex()); 364 assertEquals(JavaQNameImpl.getInstance(int.class), sct4.getContentTypeSG().getRuntimeType()); 365 assertEquals(1, ct4.getAttributes().length); 366 assertEquals(new XsQName((String ) null, "g"), ct4.getAttributes()[0].getName()); 367 assertEquals(JavaQNameImpl.getInstance(boolean.class), ct4.getAttributes()[0].getTypeSG().getRuntimeType()); 368 } 369 370 public void testFacets() throws Exception { 371 final String schema = 372 "<?xml version='1.0'?>\n" + 373 "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" + 374 " <xs:annotation><xs:appinfo>\n" + 375 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 376 " <jaxb:package name='parsertest.testfacets'/>\n" + 377 " </jaxb:schemaBindings>\n" + 378 " </xs:appinfo></xs:annotation>\n" + 379 " <xs:simpleType name='USState'>\n" + 380 " <xs:restriction base='xs:string'>\n" + 381 " <xs:enumeration value='AK'/>\n" + 382 " <xs:enumeration value='AL'/>\n" + 383 " <xs:enumeration value='AR'/>\n" + 384 " <!-- and so on ... -->\n" + 385 " </xs:restriction>\n" + 386 " </xs:simpleType>\n" + 387 " <xs:element name='a' type='USState'/>\n" + 388 "</xs:schema>\n"; 389 390 SchemaSG jschema = parse(schema, "testFacets.xsd"); 391 392 ObjectSG[] elements = jschema.getElements(); 393 assertEquals(1, elements.length); 394 ObjectSG se1 = elements[0]; 395 assertEquals(new XsQName((String ) null, "a"), se1.getName()); 396 assertTrue(!se1.getTypeSG().isComplex()); 397 SimpleTypeSG sst1 = se1.getTypeSG().getSimpleTypeSG(); 398 assertEquals(JavaQNameImpl.getInstance(String .class), sst1.getRuntimeType()); 399 Facet facet = sst1.getFacet(Facet.ENUMERATION); 400 assertNotNull(facet); 401 String [] values = facet.getValues(); 402 assertNotNull(values); 403 assertEquals(3, values.length); 404 assertEquals("AK", values[0]); 405 assertEquals("AL", values[1]); 406 assertEquals("AR", values[2]); 407 } 408 409 public void testGlobalBindingsDefaults() throws Exception { 410 final String schema = 413 "<?xml version='1.0'?>\n" + 414 "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'/>\n"; 415 416 SchemaSG jschema = parse(schema, "testGlobalBindingsDefaults.xsd"); 417 418 String collectionType = jschema.getCollectionType(); 419 assertEquals(ArrayList .class.getName(), collectionType); 420 JAXBJavaType[] javaTypes = jschema.getJAXBJavaTypes(); 421 assertNotNull(javaTypes); 422 assertEquals(0, javaTypes.length); 423 XsQName[] typesafeEnumBase = jschema.getTypesafeEnumBase(); 424 assertNotNull(typesafeEnumBase); 425 assertEquals(1, typesafeEnumBase.length); 426 assertEquals(new XsQName(XSParser.XML_SCHEMA_URI, "NCName"), typesafeEnumBase[0]); 427 boolean isBindingStyleModelGroup = jschema.isBindingStyleModelGroup(); 428 assertTrue(!isBindingStyleModelGroup); 429 boolean choiceContentProperty = jschema.isChoiceContentProperty(); 430 assertTrue(!choiceContentProperty); 431 boolean enableFailFastCheck = jschema.isFailFastCheckEnabled(); 432 assertTrue(!enableFailFastCheck); 433 boolean isJavaNamingConventionsEnabled = jschema.isJavaNamingConventionsEnabled(); 434 assertTrue(isJavaNamingConventionsEnabled); 435 boolean isFixedAttributeConstantProperty = jschema.isFixedAttributeConstantProperty(); 436 assertTrue(!isFixedAttributeConstantProperty); 437 boolean generatingIsSetMethod = jschema.isGeneratingIsSetMethod(); 438 assertTrue(!generatingIsSetMethod); 439 boolean underscoreWordSeparator = jschema.isUnderscoreWordSeparator(); 440 assertTrue(underscoreWordSeparator); 441 } 442 443 444 public void testGlobalBindings() throws Exception { 445 final String schema = 446 "<?xml version='1.0'?>\n" + 447 "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" + 448 " <xs:annotation>\n" + 449 " <xs:appinfo>\n" + 450 " <jaxb:globalBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'\n" + 451 " collectionType='indexed'\n" + 452 " typesafeEnumBase='xs:String xs:NCName'\n" + 453 " bindingStyle='modelGroupBinding'\n" + 454 " choiceContentProperty='true'\n" + 455 " enableFailFastCheck='1'\n" + 456 " enableJavaNamingConventions='false'\n" + 457 " fixedAttributeAsConstantProperty='true'\n" + 458 " generateIsSetMethod='1'\n" + 459 " underscoreBinding='asCharInWord'/>\n" + 460 " </xs:appinfo\n>" + 461 " </xs:annotation>\n" + 462 "</xs:schema>"; 463 464 SchemaSG jschema = parse(schema, "testGlobalBindingsDefaults.xsd"); 465 466 String collectionType = jschema.getCollectionType(); 467 assertEquals("indexed", collectionType); 468 XsQName[] typesafeEnumBase = jschema.getTypesafeEnumBase(); 469 assertNotNull(typesafeEnumBase); 470 assertEquals(2, typesafeEnumBase.length); 471 assertEquals(new XsQName(XSParser.XML_SCHEMA_URI, "String"), typesafeEnumBase[0]); 472 assertEquals(new XsQName(XSParser.XML_SCHEMA_URI, "NCName"), typesafeEnumBase[1]); 473 474 boolean isBindingStyleModelGroup = jschema.isBindingStyleModelGroup(); 475 assertTrue(isBindingStyleModelGroup); 476 477 boolean isChoiceContentProperty = jschema.isChoiceContentProperty(); 478 assertTrue(isChoiceContentProperty); 479 480 boolean enableFailFastCheck = jschema.isFailFastCheckEnabled(); 481 assertTrue(enableFailFastCheck); 482 483 boolean isJavaNamingConventionsEnabled = jschema.isJavaNamingConventionsEnabled(); 484 assertTrue(!isJavaNamingConventionsEnabled); 485 486 boolean fixedAttributeConstantProperty = jschema.isFixedAttributeConstantProperty(); 487 assertTrue(fixedAttributeConstantProperty); 488 489 boolean generatingIsSetMethod = jschema.isGeneratingIsSetMethod(); 490 assertTrue(generatingIsSetMethod); 491 492 boolean isUnderscoreWordSeparator = jschema.isUnderscoreWordSeparator(); 493 assertTrue(!isUnderscoreWordSeparator); 494 495 JAXBJavaType[] javaTypes = jschema.getJAXBJavaTypes(); 496 assertNotNull(javaTypes); 497 assertEquals(0, javaTypes.length); 498 } 499 500 586 587 public void testPurchaseOrder() throws Exception { 588 597 598 final String schema = 599 "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> \n" + 600 " \n" + 601 " <xsd:annotation> \n" + 602 " <xsd:documentation xml:lang='en'> \n" + 603 " Purchase order schema for Example.com. \n" + 604 " Copyright 2000 Example.com. All rights reserved. \n" + 605 " </xsd:documentation> \n" + 606 " <xsd:appinfo>\n" + 607 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 608 " <jaxb:package name='parsertest.testpurchaseorder'/>\n" + 609 " </jaxb:schemaBindings>\n" + 610 " </xsd:appinfo>\n" + 611 " </xsd:annotation> \n" + 612 " \n" + 613 " <xsd:element name='comment' type='xsd:string'/> \n" + 614 " \n" + 615 " <xsd:simpleType name='SKU'> \n" + 616 " <xsd:restriction base='xsd:string'> \n" + 617 " <xsd:pattern value='\\d{3}-[A-Z]{2}'/> \n" + 618 " </xsd:restriction> \n" + 619 " </xsd:simpleType> \n" + 620 " \n" + 621 " <xsd:complexType name='USAddress'> \n" + 622 " <xsd:sequence> \n" + 623 " <xsd:element name='name' type='xsd:string'/> \n" + 624 " <xsd:element name='street' type='xsd:string'/> \n" + 625 " <xsd:element name='city' type='xsd:string'/> \n" + 626 " <xsd:element name='state' type='xsd:string'/> \n" + 627 " <xsd:element name='zip' type='xsd:integer'/> \n" + 628 " </xsd:sequence> \n" + 629 " <xsd:attribute name='country' type='xsd:string' fixed='US'/> \n" + 630 " </xsd:complexType> \n" + 631 " \n" + 632 " <xsd:complexType name='Items'> \n" + 633 " <xsd:sequence> \n" + 634 " <xsd:element name='item' minOccurs='0' maxOccurs='unbounded'> \n" + 635 " <xsd:complexType> \n" + 636 " <xsd:sequence> \n" + 637 " <xsd:element name='productName' type='xsd:string'/> \n" + 638 " <xsd:element name='quantity'> \n" + 639 " <xsd:simpleType> \n" + 640 " <xsd:restriction base='xsd:positiveInteger'> \n" + 641 " <xsd:maxExclusive value='100'/> \n" + 642 " </xsd:restriction> \n" + 643 " </xsd:simpleType> \n" + 644 " </xsd:element> \n" + 645 " <xsd:element name='USPrice' type='xsd:decimal'/> \n" + 646 " <xsd:element ref='comment' minOccurs='0'/> \n" + 647 " <xsd:element name='shipDate' type='xsd:date' minOccurs='0'/> \n" + 648 " </xsd:sequence> \n" + 649 " <xsd:attribute name='partNum' type='SKU' use='required'/> \n" + 650 " </xsd:complexType> \n" + 651 " </xsd:element> \n" + 652 " </xsd:sequence> \n" + 653 " </xsd:complexType> \n" + 654 " \n" + 655 " <xsd:complexType name='PurchaseOrderType'> \n" + 656 " <xsd:sequence> \n" + 657 " <xsd:element name='shipTo' type='USAddress'/> \n" + 658 " <xsd:element name='billTo' type='USAddress'/> \n" + 659 " <xsd:element ref='comment' minOccurs='0'/> \n" + 660 " <xsd:element name='items' type='Items'/> \n" + 661 " </xsd:sequence> \n" + 662 " <xsd:attribute name='orderDate' type='xsd:date'/> \n" + 663 " </xsd:complexType> \n" + 664 " \n" + 665 " <xsd:element name='purchaseOrder' type='PurchaseOrderType'/> \n" + 666 " \n" + 667 "</xsd:schema> \n"; 668 669 SchemaSG jschema = parse(schema, "testPurchaseOrder.xsd"); 670 671 TypeSG[] schemaTypes = jschema.getTypes(); 672 assertNotNull(schemaTypes); 673 assertEquals(4, schemaTypes.length); 674 675 TypeSG sku = schemaTypes[0]; 677 assertEquals(new XsQName((String ) null, "SKU"), sku.getName()); 678 assertTrue(sku.isGlobalType()); 679 assertTrue(!sku.isComplex()); 680 assertTrue(sku.isRestriction()); 681 assertEquals(new XsQName(XSParser.XML_SCHEMA_URI, "string"), sku.getRestrictedType().getName()); 682 683 TypeSG usAddress = schemaTypes[1]; 687 assertEquals(new XsQName((String ) null, "USAddress"), usAddress.getName()); 688 assertTrue(usAddress.isGlobalType()); 689 assertTrue(usAddress.isComplex()); 690 assertTrue(usAddress.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().isSequence()); 691 AttributeSG [] usAddressAttributes = usAddress.getComplexTypeSG().getAttributes(); 695 assertEquals(1, usAddressAttributes.length); 696 AttributeSG country = usAddressAttributes[0]; 697 assertEquals(new XsQName((String ) null, "country"), country.getName()); 698 assertEquals(JavaQNameImpl.getInstance(String .class), country.getTypeSG().getRuntimeType()); 699 String [] nameShouldBe = {"name", "street", "city", "state", "zip"}; 701 ParticleSG [] usAddressChildren = usAddress.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().getParticles(); 702 assertEquals(5, usAddressChildren.length); 703 for (int i = 0; i < usAddressChildren.length; i++) { 704 ParticleSG child = usAddressChildren[i]; 705 assertTrue(child.isElement()); 706 assertEquals(new XsQName((String ) null, nameShouldBe[i]), child.getObjectSG().getName()); 707 assertTrue(!child.getObjectSG().getTypeSG().isComplex()); 708 Class childRuntimeClass = "zip".equals(nameShouldBe[i]) ? BigInteger .class : String .class; 709 assertEquals(JavaQNameImpl.getInstance(childRuntimeClass), child.getObjectSG().getTypeSG().getRuntimeType()); 710 } 711 712 TypeSG items = schemaTypes[2]; 714 assertEquals(new XsQName((String ) null, "Items"), items.getName()); 715 assertTrue(items.isGlobalType()); 716 assertTrue(items.isComplex()); 717 ComplexTypeSG itemsComplex = items.getComplexTypeSG(); 718 assertTrue(!itemsComplex.hasSimpleContent()); 719 ComplexContentSG itemsComplexContent = itemsComplex.getComplexContentSG(); 720 GroupSG group = itemsComplexContent.getRootParticle().getGroupSG(); 721 assertTrue(group.isSequence()); 722 ParticleSG[] itemsChildren = group.getParticles(); 724 assertEquals(1, itemsChildren.length); 725 ParticleSG item = itemsChildren[0]; 726 assertTrue(item.isElement()); 727 assertEquals(new XsQName((String ) null, "item"), item.getObjectSG().getName()); 728 assertEquals(0, item.getMinOccurs()); 729 assertEquals(-1, item.getMaxOccurs()); 730 TypeSG itemST = item.getObjectSG().getTypeSG(); 731 assertTrue(itemST.isComplex()); 732 assertTrue(!itemST.getComplexTypeSG().hasSimpleContent()); 733 assertTrue(itemST.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().isSequence()); 734 AttributeSG[] itemAttributes = itemST.getComplexTypeSG().getAttributes(); 737 assertEquals(1, itemAttributes.length); 738 AttributeSG partNum = itemAttributes[0]; 739 assertEquals(new XsQName((String ) null, "partNum"), partNum.getName()); 740 assertTrue(partNum.isRequired()); 741 ParticleSG[] itemChildren = itemST.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().getParticles(); 744 assertEquals(5, itemChildren.length); 745 ParticleSG usPrice = itemChildren[2]; 746 assertTrue(usPrice.isElement()); 747 assertEquals(new XsQName((String ) null,"USPrice"), usPrice.getObjectSG().getName()); 748 TypeSG usPriceSST = usPrice.getObjectSG().getTypeSG(); 749 assertTrue(!usPrice.getObjectSG().getTypeSG().isComplex()); 750 assertTrue(usPriceSST.getSimpleTypeSG().isAtomic()); 751 assertEquals(java.math.BigDecimal .class.getName(), usPriceSST.getRuntimeType().toString()); 752 ParticleSG comment = itemChildren[3]; 755 assertTrue(comment.isElement()); 756 assertEquals(new XsQName((String ) null, "comment"), comment.getObjectSG().getName()); 757 assertEquals(0, comment.getMinOccurs()); 758 TypeSG commentSST = comment.getObjectSG().getTypeSG(); 759 assertTrue(!commentSST.isComplex()); 760 assertTrue(commentSST.getSimpleTypeSG().isAtomic()); 761 assertEquals(JavaQNameImpl.getInstance(String .class), commentSST.getRuntimeType()); 762 ParticleSG productName = itemChildren[0]; 765 assertTrue(productName.isElement()); 766 assertEquals(new XsQName((String ) null, "productName"), productName.getObjectSG().getName()); 767 TypeSG productNameSST = productName.getObjectSG().getTypeSG(); 768 assertTrue(!productNameSST.isComplex()); 769 assertTrue(productNameSST.getSimpleTypeSG().isAtomic()); 770 assertEquals(JavaQNameImpl.getInstance(String .class), productNameSST.getRuntimeType()); 771 ParticleSG quantity = itemChildren[1]; 773 assertTrue(quantity.isElement()); 774 assertEquals(new XsQName((String ) null, "quantity"), quantity.getObjectSG().getName()); 775 TypeSG quantitySST = quantity.getObjectSG().getTypeSG(); 776 assertTrue(!quantitySST.isComplex()); 777 assertTrue(quantitySST.getSimpleTypeSG().isAtomic()); 778 assertEquals(JavaQNameImpl.getInstance(java.math.BigInteger .class), quantitySST.getRuntimeType()); 779 ParticleSG shipDate = itemChildren[4]; 782 assertTrue(shipDate.isElement()); 783 assertEquals(new XsQName((String ) null, "shipDate"), shipDate.getObjectSG().getName()); 784 TypeSG shipDateSST = shipDate.getObjectSG().getTypeSG(); 785 assertTrue(!shipDateSST.isComplex()); 786 assertEquals(0, shipDate.getMinOccurs()); 787 assertTrue(shipDateSST.getSimpleTypeSG().isAtomic()); 788 assertEquals(Calendar .class.getName(), shipDateSST.getRuntimeType().toString()); 789 790 TypeSG purchaseOrderType = schemaTypes[3]; 792 assertEquals(new XsQName((String ) null, "PurchaseOrderType"), purchaseOrderType.getName()); 793 assertTrue(purchaseOrderType.isGlobalType()); 794 assertTrue(purchaseOrderType.isComplex()); 795 assertTrue(purchaseOrderType.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().isSequence()); 796 AttributeSG [] potAttributes = purchaseOrderType.getComplexTypeSG().getAttributes(); 799 assertEquals(1, potAttributes.length); 800 AttributeSG orderDate = potAttributes[0]; 801 assertEquals(new XsQName((String ) null, "orderDate"), orderDate.getName()); 802 assertEquals(JavaQNameImpl.getInstance(Calendar .class), 803 orderDate.getTypeSG().getSimpleTypeSG().getRuntimeType()); 804 ParticleSG [] potChildren = purchaseOrderType.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().getParticles(); 805 assertEquals(4, potChildren.length); 806 ParticleSG shipTo = potChildren[0]; 809 assertTrue(shipTo.isElement()); 810 assertEquals(new XsQName((String ) null, "shipTo"), shipTo.getObjectSG().getName()); 811 TypeSG shipToST = shipTo.getObjectSG().getTypeSG(); 812 assertTrue(shipToST.isComplex()); 813 assertEquals(new XsQName((String ) null, "USAddress"), shipToST.getName()); 814 assertTrue(shipToST.isComplex()); 815 ParticleSG billTo = potChildren[1]; 818 assertTrue(billTo.isElement()); 819 assertEquals(new XsQName((String ) null, "billTo"), billTo.getObjectSG().getName()); 820 TypeSG billToST = billTo.getObjectSG().getTypeSG(); 821 assertTrue(billToST.isComplex()); 822 assertEquals(new XsQName((String ) null, "USAddress"), billToST.getName()); 823 assertTrue(billToST.isComplex()); 824 ParticleSG potComment = potChildren[2]; 827 assertTrue(potComment.isElement()); 828 assertEquals(new XsQName((String ) null, "comment"), comment.getObjectSG().getName()); 829 assertEquals(0, comment.getMinOccurs()); 830 TypeSG potCommentST = potComment.getObjectSG().getTypeSG(); 831 assertTrue(!potCommentST.isComplex()); 832 assertEquals(JavaQNameImpl.getInstance(String .class), potCommentST.getRuntimeType()); 833 ParticleSG potItems = potChildren[3]; 836 assertTrue(potItems.isElement()); 837 assertEquals(new XsQName((String ) null, "items"), potItems.getObjectSG().getName()); 838 assertTrue(potItems.getObjectSG().getTypeSG().isComplex()); 839 840 ObjectSG[] elements = jschema.getElements(); 843 assertNotNull(elements); 844 assertEquals(2, elements.length); 845 ObjectSG purchaseOrder = elements[1]; 846 assertEquals(new XsQName((String ) null, "purchaseOrder"), purchaseOrder.getName()); 847 assertTrue(purchaseOrder.getTypeSG().isComplex()); 848 assertTrue(purchaseOrder.getTypeSG().isGlobalType()); 849 assertEquals(new XsQName((String ) null, "PurchaseOrderType"), purchaseOrder.getTypeSG().getName()); 850 } 851 852 853 public void testRestrictionMaxExclusive() throws Exception { 854 final String schema = 855 "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> \n" + 856 " <xsd:annotation><xsd:appinfo>\n" + 857 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 858 " <jaxb:package name='parsertest.testrestrictionmaxexclusive'/>\n" + 859 " </jaxb:schemaBindings>\n" + 860 " </xsd:appinfo></xsd:annotation>\n" + 861 " <xsd:element name='quantity'> \n" + 862 " <xsd:simpleType> \n" + 863 " <xsd:restriction base='xsd:decimal'> \n" + 864 " <xsd:maxExclusive value='100'/> \n" + 865 " </xsd:restriction> \n" + 866 " </xsd:simpleType> \n" + 867 " </xsd:element> \n" + 868 "</xsd:schema> \n"; 869 870 SchemaSG jschema = parse(schema, "testRestrictionMaxExclusive.xsd"); 871 ObjectSG[] elements = jschema.getElements(); 872 assertEquals(1, elements.length); 873 ObjectSG quantity = elements[0]; 874 String maxExclusive = quantity.getTypeSG().getSimpleTypeSG().getAtomicType().getMaxExclusive(); 875 assertNotNull(maxExclusive); 876 assertEquals("100", maxExclusive); 877 } 878 879 880 public void testNonPositiveInteger() throws Exception { 881 final String schema = 882 "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> \n" + 883 " <xsd:annotation><xsd:appinfo>\n" + 884 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 885 " <jaxb:package name='parsertest.testnonpositiveinteger'/>\n" + 886 " </jaxb:schemaBindings>\n" + 887 " </xsd:appinfo></xsd:annotation>\n" + 888 " <xsd:element name='non-positive-integer' type='xsd:nonPositiveInteger'/> \n" + 889 "</xsd:schema> \n"; 890 891 SchemaSG jschema = parse(schema, "testNonPositiveInteger.xsd"); 892 893 TypeSG npi = jschema.getElements()[0].getTypeSG(); 895 assertTrue(!npi.isComplex()); 896 SimpleTypeSG npis = npi.getSimpleTypeSG(); 897 assertTrue(npis.isAtomic()); 898 assertTrue(!npis.isList()); 899 assertTrue(!npis.isUnion()); 900 assertEquals(new Long (0), npis.getAtomicType().getFractionDigits()); 901 assertEquals("0", npis.getAtomicType().getMaxInclusive()); 902 assertEquals("1", npis.getAtomicType().getMaxExclusive()); 903 } 904 905 906 public void testNegativeInteger() throws Exception { 907 final String schema = 908 "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> \n" + 909 " <xsd:annotation><xsd:appinfo>\n" + 910 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 911 " <jaxb:package name='parsertest.testnegativeinteger'/>\n" + 912 " </jaxb:schemaBindings>\n" + 913 " </xsd:appinfo></xsd:annotation>\n" + 914 " <xsd:element name='negative-integer' type='xsd:negativeInteger'/> \n" + 915 "</xsd:schema> \n"; 916 917 SchemaSG jschema = parse(schema, "testNegativeInteger.xsd"); 918 919 TypeSG ni = jschema.getElements()[0].getTypeSG(); 921 assertTrue(!ni.isComplex()); 922 SimpleTypeSG nis = ni.getSimpleTypeSG(); 923 assertTrue(nis.isAtomic()); 924 assertTrue(!nis.isList()); 925 assertTrue(!nis.isUnion()); 926 assertEquals(new Long (0), nis.getAtomicType().getFractionDigits()); 927 assertEquals("-1", nis.getAtomicType().getMaxInclusive()); 928 assertEquals("0", nis.getAtomicType().getMaxExclusive()); 929 } 930 931 public void testNonNegativeIntegerType() throws Exception { 932 final String schema = 933 "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> \n" + 934 " <xsd:annotation><xsd:appinfo>\n" + 935 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 936 " <jaxb:package name='parsertest.testnonnegativeinteger'/>\n" + 937 " </jaxb:schemaBindings>\n" + 938 " </xsd:appinfo></xsd:annotation>\n" + 939 " <xsd:element name='non-negative-integer' type='xsd:nonNegativeInteger'/> \n" + 940 "</xsd:schema> \n"; 941 942 SchemaSG jschema = parse(schema, "testNonNegativeIntegerType.xsd"); 943 944 TypeSG nni = jschema.getElements()[0].getTypeSG(); 946 assertTrue(!nni.isComplex()); 947 SimpleTypeSG nnis = nni.getSimpleTypeSG(); 948 assertTrue(nnis.isAtomic()); 949 assertTrue(!nnis.isList()); 950 assertTrue(!nnis.isUnion()); 951 assertEquals(new Long (0), nnis.getAtomicType().getFractionDigits()); 952 assertEquals("-1", nnis.getAtomicType().getMinExclusive()); 953 assertEquals("0", nnis.getAtomicType().getMinInclusive()); 954 } 955 956 public void testPositiveIntegerType() throws Exception { 957 final String schema = 958 "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> \n" + 959 " <xsd:annotation><xsd:appinfo>\n" + 960 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 961 " <jaxb:package name='parsertest.testpositiveinteger'/>\n" + 962 " </jaxb:schemaBindings>\n" + 963 " </xsd:appinfo></xsd:annotation>\n" + 964 " <xsd:element name='positive-integer' type='xsd:positiveInteger'/> \n" + 965 "</xsd:schema> \n"; 966 967 SchemaSG jschema = parse(schema, "testPositiveIntegerType.xsd"); 968 969 TypeSG pi = jschema.getElements()[0].getTypeSG(); 971 assertTrue(!pi.isComplex()); 972 SimpleTypeSG pis = pi.getSimpleTypeSG(); 973 assertTrue(pis.isAtomic()); 974 assertTrue(!pis.isList()); 975 assertTrue(!pis.isUnion()); 976 assertEquals(new Long (0), pis.getAtomicType().getFractionDigits()); 977 assertEquals("0", pis.getAtomicType().getMinExclusive()); 978 assertEquals("1", pis.getAtomicType().getMinInclusive()); 979 } 980 981 982 public void testIntegerType() throws Exception { 983 final String schema = 984 "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'> \n" + 985 " <xsd:annotation><xsd:appinfo>\n" + 986 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 987 " <jaxb:package name='parsertest.testintegertype'/>\n" + 988 " </jaxb:schemaBindings>\n" + 989 " </xsd:appinfo></xsd:annotation>\n" + 990 " <xsd:element name='integer' type='xsd:integer'/> \n" + 991 "</xsd:schema> \n"; 992 993 SchemaSG jschema = parse(schema, "testIntegerType.xsd"); 994 995 ObjectSG[] elements = jschema.getElements(); 997 TypeSG i = elements[0].getTypeSG(); 998 assertTrue(!i.isComplex()); 999 SimpleTypeSG is = i.getSimpleTypeSG(); 1000 assertTrue(is.isAtomic()); 1001 assertTrue(!is.isList()); 1002 assertTrue(!is.isUnion()); 1003 assertEquals(JavaQNameImpl.getInstance(BigInteger .class), is.getRuntimeType()); 1004 assertEquals(new Long (0), is.getAtomicType().getFractionDigits()); 1005 } 1006 1007 1008 public void testNmTokensType() throws Exception { 1009 final String schema = 1010 "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'> \n" + 1011 " <xs:annotation><xs:appinfo>\n" + 1012 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 1013 " <jaxb:package name='parsertest.testnmtokenstype'/>\n" + 1014 " </jaxb:schemaBindings>\n" + 1015 " </xs:appinfo></xs:annotation>\n" + 1016 " <xs:element name='some-nmtokens' type='xs:NMTOKENS'/> \n" + 1017 "</xs:schema> \n"; 1018 1019 SchemaSG jschema = parse(schema, "testNmTokensType.xsd"); 1020 1021 ObjectSG[] elements = jschema.getElements(); 1023 assertEquals(1, elements.length); 1024 TypeSG nmts = elements[0].getTypeSG(); 1025 assertTrue(!nmts.isComplex()); 1026 SimpleTypeSG nmtss = nmts.getSimpleTypeSG(); 1027 assertTrue(!nmtss.isAtomic()); 1028 assertTrue(nmtss.isList()); 1029 assertTrue(!nmtss.isUnion()); 1030 ListTypeSG nmtsl = nmtss.getListType(); 1031 assertEquals(new Long (1), nmtsl.getMinLength()); 1032 } 1033 1034 1036 public void testJira46() throws Exception { 1037 final String uri = "http://www.cnipa.it/schemas/2003/eGovIT/Busta1_0/"; 1038 final String schemaSpec = 1039 "<xs:schema targetNamespace='" + uri + "'\n" + 1040 " xmlns:eGov_IT='" + uri + "'\n" + 1041 " xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n" + 1042 " <xs:element name='Riferimento'>\n" + 1043 " <xs:complexType>\n" + 1044 " <xs:sequence/>\n" + 1045 " <xs:attribute ref='eGov_IT:id' use='required'/>\n" + 1046 " </xs:complexType>\n" + 1047 " </xs:element>\n" + 1048 " <xs:attribute name='id' type='xs:ID'/>\n" + 1049 "</xs:schema>\n"; 1050 1051 InputSource isource = new InputSource (new StringReader (schemaSpec)); 1052 isource.setSystemId("jira46.xsd"); 1053 JAXBSchemaReader r = getSchemaReader(); 1054 XSParser parser = r.getSGFactory().newXSParser(); 1055 parser.setValidating(false); 1056 XSSchema schema = parser.parse(isource); 1057 XSAttribute[] attrs = schema.getAttributes(); 1058 assertEquals(1, attrs.length); 1059 XSAttribute idAttr = attrs[0]; 1060 assertTrue(idAttr instanceof JAXBAttribute); 1061 assertEquals(new XsQName(uri, "id"), idAttr.getName()); 1062 assertEquals(XSID.getInstance(), idAttr.getType()); 1063 assertTrue(idAttr.isOptional()); 1064 XSElement[] elements = schema.getElements(); 1065 assertEquals(1, elements.length); 1066 XSElement rifElem = elements[0]; 1067 assertFalse(rifElem.getType().isSimple()); 1068 XSComplexType ct = rifElem.getType().getComplexType(); 1069 XSAttributable[] rifAttrs = ct.getAttributes(); 1070 assertEquals(1, rifAttrs.length); 1071 XSAttribute idRef = (XSAttribute) rifAttrs[0]; 1072 assertTrue(idRef instanceof JAXBAttribute); 1073 assertFalse(idRef.equals(idAttr)); 1074 assertEquals(new XsQName(uri, "id"), idAttr.getName()); 1075 assertEquals(XSID.getInstance(), idAttr.getType()); 1076 assertFalse(idRef.isOptional()); 1077 } 1078 1079 1082 public void testMultipleGroupRejected() throws Exception { 1083 final String schemaSpec = 1084 "<xs:schema\n" + 1085 " xmlns:xs='http://www.w3.org/2001/XMLSchema'\n" + 1086 " elementFormDefault='qualified'\n" + 1087 " xmlns:jaxb='http://java.sun.com/xml/ns/jaxb'\n" + 1088 " jaxb:version='1.0'>\n" + 1089 " <xs:annotation><xs:appinfo>\n" + 1090 " <jaxb:schemaBindings xmlns:jaxb='" + JAXBParser.JAXB_SCHEMA_URI + "'>\n" + 1091 " <jaxb:package name='parsertest.testmultiplegroupsrejected'/>\n" + 1092 " </jaxb:schemaBindings>\n" + 1093 " </xs:appinfo></xs:annotation>\n" + 1094 " <xs:element name='DIAGJOBS'>\n" + 1095 " <xs:complexType>\n" + 1096 " <xs:choice maxOccurs='unbounded'>\n" + 1097 " <xs:element name='DIAGJOB' type='xs:string'/>\n" + 1098 " <xs:sequence>\n" + 1099 " <xs:element name='DJREF' type='xs:long'/>\n" + 1100 " <xs:element name='DESCRIPTIONS' type='xs:string' minOccurs='0'/>\n" + 1101 " </xs:sequence>\n" + 1102 " </xs:choice>\n" + 1103 " </xs:complexType>\n" + 1104 " </xs:element>\n" + 1105 "</xs:schema>\n"; 1106 SchemaSG schema = parse(schemaSpec, "testMultipleGroupRejected.xsd"); 1107 try { 1108 schema.generate(); 1109 fail("Expected an exception"); 1110 } catch (SAXException e) { 1111 assertTrue(e.getMessage().indexOf("Model groups with maxOccurs > 1 are not yet supported.") != -1); 1112 } 1113 } 1114} 1115 | Popular Tags |