Package org.apache.ws.jaxme.generator.sg

Examples of org.apache.ws.jaxme.generator.sg.SchemaSG


      " \n" +
      " <xsd:element name='purchaseOrder' type='PurchaseOrderType'/> \n" +
      " \n" +
      "</xsd:schema> \n";

    SchemaSG jschema = parse(schema, "testPurchaseOrder.xsd");

    TypeSG[] schemaTypes = jschema.getTypes();
    assertNotNull(schemaTypes);
    assertEquals(4, schemaTypes.length);

    // SKU
    TypeSG sku = schemaTypes[0];
    assertEquals(new XsQName((String) null, "SKU"), sku.getName());
    assertTrue(sku.isGlobalType());
    assertTrue(!sku.isComplex());
    assertTrue(sku.isRestriction());
    assertEquals(new XsQName(XSParser.XML_SCHEMA_URI, "string"), sku.getRestrictedType().getName());

    // USAddress
    // <xsd:complexType name='USAddress'>
    // <xsd:sequence>
    TypeSG usAddress = schemaTypes[1];
    assertEquals(new XsQName((String) null, "USAddress"), usAddress.getName());
    assertTrue(usAddress.isGlobalType());
    assertTrue(usAddress.isComplex());
    assertTrue(usAddress.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().isSequence());
    // USAddress.country
    //  <xsd:attribute name='country' type='xsd:string' fixed='US'/>
    // ToDo: test attribute fixed='US'
    AttributeSG [] usAddressAttributes = usAddress.getComplexTypeSG().getAttributes();
    assertEquals(1, usAddressAttributes.length);
    AttributeSG country = usAddressAttributes[0];
    assertEquals(new XsQName((String) null, "country"), country.getName());
    assertEquals(JavaQNameImpl.getInstance(String.class), country.getTypeSG().getRuntimeType());
    // USAddress children
    String [] nameShouldBe = {"name", "street", "city""state", "zip"};
    ParticleSG [] usAddressChildren = usAddress.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().getParticles();
    assertEquals(5, usAddressChildren.length);
    for (int i = 0; i < usAddressChildren.length; i++) {
      ParticleSG child = usAddressChildren[i];
      assertTrue(child.isElement());
      assertEquals(new XsQName((String) null, nameShouldBe[i]), child.getObjectSG().getName());
      assertTrue(!child.getObjectSG().getTypeSG().isComplex());
      Class childRuntimeClass = "zip".equals(nameShouldBe[i]) ? BigInteger.class : String.class;
      assertEquals(JavaQNameImpl.getInstance(childRuntimeClass), child.getObjectSG().getTypeSG().getRuntimeType());
    }

    // Items
    TypeSG items = schemaTypes[2];
    assertEquals(new XsQName((String) null, "Items"), items.getName());
    assertTrue(items.isGlobalType());
    assertTrue(items.isComplex());
    ComplexTypeSG itemsComplex = items.getComplexTypeSG();
    assertTrue(!itemsComplex.hasSimpleContent());
    ComplexContentSG itemsComplexContent = itemsComplex.getComplexContentSG();
    GroupSG group = itemsComplexContent.getRootParticle().getGroupSG();
    assertTrue(group.isSequence());
    // Items.item
    ParticleSG[] itemsChildren = group.getParticles();
    assertEquals(1, itemsChildren.length);
    ParticleSG item = itemsChildren[0];
    assertTrue(item.isElement());
    assertEquals(new XsQName((String) null, "item"), item.getObjectSG().getName());
    assertEquals(0, item.getMinOccurs());
    assertEquals(-1, item.getMaxOccurs());
    TypeSG itemST = item.getObjectSG().getTypeSG();
    assertTrue(itemST.isComplex());
    assertTrue(!itemST.getComplexTypeSG().hasSimpleContent());
    assertTrue(itemST.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().isSequence());
    // Items.item.partNum
    // <xsd:attribute name='partNum' type='SKU' use='required'/>
    AttributeSG[] itemAttributes = itemST.getComplexTypeSG().getAttributes();
    assertEquals(1, itemAttributes.length);
    AttributeSG partNum = itemAttributes[0];
    assertEquals(new XsQName((String) null, "partNum"), partNum.getName());
    assertTrue(partNum.isRequired());
    // Items.item.USPrice
    // <xsd:element name='USPrice'  type='xsd:decimal'/>
    ParticleSG[] itemChildren = itemST.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().getParticles();
    assertEquals(5, itemChildren.length);
    ParticleSG usPrice = itemChildren[2];
    assertTrue(usPrice.isElement());
    assertEquals(new XsQName((String) null,"USPrice"), usPrice.getObjectSG().getName());
    TypeSG usPriceSST = usPrice.getObjectSG().getTypeSG();
    assertTrue(!usPrice.getObjectSG().getTypeSG().isComplex());
    assertTrue(usPriceSST.getSimpleTypeSG().isAtomic());
    assertEquals(java.math.BigDecimal.class.getName(), usPriceSST.getRuntimeType().toString());  
    // Items.item.comment
    // <xsd:element ref='comment'   minOccurs='0'/>
    ParticleSG comment = itemChildren[3];
    assertTrue(comment.isElement());
    assertEquals(new XsQName((String) null, "comment"), comment.getObjectSG().getName());
    assertEquals(0, comment.getMinOccurs());
    TypeSG commentSST = comment.getObjectSG().getTypeSG();
    assertTrue(!commentSST.isComplex());
    assertTrue(commentSST.getSimpleTypeSG().isAtomic());
    assertEquals(JavaQNameImpl.getInstance(String.class), commentSST.getRuntimeType());  
    // Items.item.productName
    // <xsd:element name='productName' type='xsd:string'/>
    ParticleSG productName = itemChildren[0];
    assertTrue(productName.isElement());
    assertEquals(new XsQName((String) null, "productName"), productName.getObjectSG().getName());
    TypeSG productNameSST = productName.getObjectSG().getTypeSG();
    assertTrue(!productNameSST.isComplex());
    assertTrue(productNameSST.getSimpleTypeSG().isAtomic());
    assertEquals(JavaQNameImpl.getInstance(String.class), productNameSST.getRuntimeType());  
    // Items.item.quantity
    ParticleSG quantity = itemChildren[1];
    assertTrue(quantity.isElement());
    assertEquals(new XsQName((String) null, "quantity"), quantity.getObjectSG().getName());
    TypeSG quantitySST = quantity.getObjectSG().getTypeSG();
    assertTrue(!quantitySST.isComplex());
    assertTrue(quantitySST.getSimpleTypeSG().isAtomic());
    assertEquals(JavaQNameImpl.getInstance(java.math.BigInteger.class), quantitySST.getRuntimeType());   
    // Items.item.shipDate
    // <xsd:element name='shipDate' type='xsd:date' minOccurs='0'/>
    ParticleSG shipDate = itemChildren[4];
    assertTrue(shipDate.isElement());
    assertEquals(new XsQName((String) null, "shipDate"), shipDate.getObjectSG().getName());
    TypeSG shipDateSST = shipDate.getObjectSG().getTypeSG();
    assertTrue(!shipDateSST.isComplex());
    assertEquals(0, shipDate.getMinOccurs());
    assertTrue(shipDateSST.getSimpleTypeSG().isAtomic());
    assertEquals(Calendar.class.getName(), shipDateSST.getRuntimeType().toString());   

    // PurchaseOrderType
    TypeSG purchaseOrderType = schemaTypes[3];
    assertEquals(new XsQName((String) null, "PurchaseOrderType"), purchaseOrderType.getName());
    assertTrue(purchaseOrderType.isGlobalType());
    assertTrue(purchaseOrderType.isComplex());
    assertTrue(purchaseOrderType.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().isSequence());
    // PurchaseOrderType.orderDate
    // <xsd:attribute name='orderDate' type='xsd:date'/>
    AttributeSG [] potAttributes = purchaseOrderType.getComplexTypeSG().getAttributes();
    assertEquals(1, potAttributes.length);
    AttributeSG orderDate = potAttributes[0];
    assertEquals(new XsQName((String) null, "orderDate"), orderDate.getName());
    assertEquals(JavaQNameImpl.getInstance(Calendar.class),
                 orderDate.getTypeSG().getSimpleTypeSG().getRuntimeType());
    ParticleSG [] potChildren = purchaseOrderType.getComplexTypeSG().getComplexContentSG().getRootParticle().getGroupSG().getParticles();
    assertEquals(4, potChildren.length);
    // PurchaseOrderType.shipTo
    // <xsd:element name='shipTo' type='USAddress'/>
    ParticleSG shipTo = potChildren[0];
    assertTrue(shipTo.isElement());
    assertEquals(new XsQName((String) null, "shipTo"), shipTo.getObjectSG().getName());
    TypeSG shipToST = shipTo.getObjectSG().getTypeSG();
    assertTrue(shipToST.isComplex());
    assertEquals(new XsQName((String) null, "USAddress"), shipToST.getName());
    assertTrue(shipToST.isComplex());
    // PurchaseOrderType.billTo
    // <xsd:element name='billTo' type='USAddress'/>
    ParticleSG billTo = potChildren[1];
    assertTrue(billTo.isElement());
    assertEquals(new XsQName((String) null, "billTo"), billTo.getObjectSG().getName());
    TypeSG billToST = billTo.getObjectSG().getTypeSG();
    assertTrue(billToST.isComplex());
    assertEquals(new XsQName((String) null, "USAddress"), billToST.getName());
    assertTrue(billToST.isComplex());
    // PurchaseOrderType.comment
    // <xsd:element ref='comment' minOccurs='0'/>
    ParticleSG potComment = potChildren[2];
    assertTrue(potComment.isElement());
    assertEquals(new XsQName((String) null, "comment"), comment.getObjectSG().getName());
    assertEquals(0, comment.getMinOccurs());
    TypeSG potCommentST = potComment.getObjectSG().getTypeSG();
    assertTrue(!potCommentST.isComplex());
    assertEquals(JavaQNameImpl.getInstance(String.class), potCommentST.getRuntimeType());
    // PurchaseOrderType.items
    // <xsd:element name='items'  type='Items'/>
    ParticleSG potItems = potChildren[3];
    assertTrue(potItems.isElement());
    assertEquals(new XsQName((String) null, "items"), potItems.getObjectSG().getName());
    assertTrue(potItems.getObjectSG().getTypeSG().isComplex());

    // purchaseOrder
    // <xsd:element name='purchaseOrder' type='PurchaseOrderType'/>
    ObjectSG[] elements = jschema.getElements();
    assertNotNull(elements);
    assertEquals(2, elements.length);
    ObjectSG purchaseOrder = elements[1];
    assertEquals(new XsQName((String) null, "purchaseOrder"), purchaseOrder.getName());
    assertTrue(purchaseOrder.getTypeSG().isComplex());
View Full Code Here


      "   </xsd:restriction> \n" +
      "  </xsd:simpleType> \n" +
      " </xsd:element> \n" +
      "</xsd:schema> \n";

    SchemaSG jschema = parse(schema, "testRestrictionMaxExclusive.xsd");
    ObjectSG[] elements = jschema.getElements();
    assertEquals(1, elements.length);
    ObjectSG quantity = elements[0];
    String maxExclusive = quantity.getTypeSG().getSimpleTypeSG().getAtomicType().getMaxExclusive();
    assertNotNull(maxExclusive);
    assertEquals("100", maxExclusive);
View Full Code Here

      "  </jaxb:schemaBindings>\n" +
      " </xsd:appinfo></xsd:annotation>\n" +
      " <xsd:element name='non-positive-integer' type='xsd:nonPositiveInteger'/> \n" +
      "</xsd:schema> \n";

    SchemaSG jschema = parse(schema, "testNonPositiveInteger.xsd");

    // simple, atomic, with restriction and maxExclusive and maxInclusive
    TypeSG npi = jschema.getElements()[0].getTypeSG();
    assertTrue(!npi.isComplex());
    SimpleTypeSG npis = npi.getSimpleTypeSG();
    assertTrue(npis.isAtomic());
    assertTrue(!npis.isList());
    assertTrue(!npis.isUnion());
View Full Code Here

      "  </jaxb:schemaBindings>\n" +
      " </xsd:appinfo></xsd:annotation>\n" +
      " <xsd:element name='negative-integer' type='xsd:negativeInteger'/> \n" +
      "</xsd:schema> \n";

    SchemaSG jschema = parse(schema, "testNegativeInteger.xsd");

    // simple, atomic, with restrictions on maxInclusive and MaxExclusive
    TypeSG ni = jschema.getElements()[0].getTypeSG();
    assertTrue(!ni.isComplex());
    SimpleTypeSG nis = ni.getSimpleTypeSG();
    assertTrue(nis.isAtomic());
    assertTrue(!nis.isList());
    assertTrue(!nis.isUnion());
View Full Code Here

      "  </jaxb:schemaBindings>\n" +
      " </xsd:appinfo></xsd:annotation>\n" +
      " <xsd:element name='non-negative-integer' type='xsd:nonNegativeInteger'/> \n" +
      "</xsd:schema> \n";

    SchemaSG jschema = parse(schema, "testNonNegativeIntegerType.xsd");

    // simple, atomic, with restriction on minInclusive and minExclusive
    TypeSG nni = jschema.getElements()[0].getTypeSG();
    assertTrue(!nni.isComplex());
    SimpleTypeSG nnis = nni.getSimpleTypeSG();
    assertTrue(nnis.isAtomic());
    assertTrue(!nnis.isList());
    assertTrue(!nnis.isUnion());
View Full Code Here

      "  </jaxb:schemaBindings>\n" +
      " </xsd:appinfo></xsd:annotation>\n" +
      " <xsd:element name='positive-integer' type='xsd:positiveInteger'/> \n" +
      "</xsd:schema> \n";

    SchemaSG jschema = parse(schema, "testPositiveIntegerType.xsd");

    // simple, atomic, with restriction on minInclusive and minExclusive
    TypeSG pi = jschema.getElements()[0].getTypeSG();
    assertTrue(!pi.isComplex());
    SimpleTypeSG pis = pi.getSimpleTypeSG();
    assertTrue(pis.isAtomic());
    assertTrue(!pis.isList());
    assertTrue(!pis.isUnion());
View Full Code Here

      "  </jaxb:schemaBindings>\n" +
      " </xsd:appinfo></xsd:annotation>\n" +
      " <xsd:element name='integer' type='xsd:integer'/> \n" +
      "</xsd:schema> \n";

    SchemaSG jschema = parse(schema, "testIntegerType.xsd");

    // simple, atomic, with restriction on fractionDigits
    ObjectSG[] elements = jschema.getElements();
    TypeSG i = elements[0].getTypeSG();
    assertTrue(!i.isComplex());
    SimpleTypeSG is = i.getSimpleTypeSG();
    assertTrue(is.isAtomic());
    assertTrue(!is.isList());
View Full Code Here

      "  </jaxb:schemaBindings>\n" +
      " </xs:appinfo></xs:annotation>\n" +
      " <xs:element name='some-nmtokens' type='xs:NMTOKENS'/> \n" +
      "</xs:schema> \n";

    SchemaSG jschema = parse(schema, "testNmTokensType.xsd");

    // list of one or more nmtoken's
    ObjectSG[] elements = jschema.getElements();
    assertEquals(1, elements.length);
    TypeSG nmts = elements[0].getTypeSG();
    assertTrue(!nmts.isComplex());
    SimpleTypeSG nmtss = nmts.getSimpleTypeSG();
    assertTrue(!nmtss.isAtomic());
View Full Code Here

        "        </xs:sequence>\n" +
        "      </xs:choice>\n" +
        "    </xs:complexType>\n" +
        "  </xs:element>\n" +
        "</xs:schema>\n";
        SchemaSG schema = parse(schemaSpec, "testMultipleGroupRejected.xsd");
        try {
          schema.generate();
          fail("Expected an exception");
        } catch (SAXException e) {
          assertTrue(e.getMessage().indexOf("Model groups with maxOccurs > 1 are not yet supported.") != -1);
        }
    }
View Full Code Here

      + "</xs:schema>\n";
    Generator g = new GeneratorImpl();
    SchemaReader sr = new JAXBSchemaReader();
    g.setSchemaReader(sr);
    sr.setGenerator(g);
    SchemaSG schema = g.getSchemaReader().parse(new InputSource(new StringReader(xsSchema)));
    assertEquals("Element1", JavaNamer.convert("element1", schema));
    assertEquals("Element_1", JavaNamer.convert("element_1", schema));
  }
View Full Code Here

TOP

Related Classes of org.apache.ws.jaxme.generator.sg.SchemaSG

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.