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

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


  protected int getState(int pParticleNum) { return pParticleNum; }

  protected void acceptParticle(JavaMethod pJm, int pNum) throws SAXException {
    pJm.addIf(getStateField());
    ParticleSG particle = particles[pNum];
    pJm.addIf(getChildNumField(), " != " + pNum);
    pJm.addLine("getHandler().validationEvent(", ValidationEvent.class, ".WARNING, ",
          JavaSource.getQuoted("Multiple different particles present in a choive group."),
          ", ", ValidationEvents.class, ".EVENT_CHOICE_GROUP_REUSE, null);");
    if (!particles[pNum].isMultiple()) {
      pJm.addElse();
      if (particle.isElement()) {
        pJm.addLine("getHandler().validationEvent(", ValidationEvent.class, ".WARNING, ",
              JavaSource.getQuoted("The element " + particle.getObjectSG().getName() +
                           " has already been defined."),
              ", ", ValidationEvents.class, ".EVENT_CHOICE_GROUP_REUSE, null);");
      } else if (particle.isGroup()) {
        pJm.addLine("getHandler().validationEvent(", ValidationEvent.class, ".WARNING, ",
              JavaSource.getQuoted("The group " + GroupUtil.getGroupName(particle.getGroupSG()) +
                         " has already been defined."),
                ", ", ValidationEvents.class, ".EVENT_CHOICE_GROUP_REUSE, null);");
      } else if (particle.isWildcard()) {
        throw new IllegalStateException("TODO: Add support for wildcards.");
      } else {
        throw new IllegalStateException("Invalid particle type");
      }
    }
View Full Code Here


    return getChildNumField();
  }

  protected void acceptParticle(JavaMethod pJm, int pNum) throws SAXException {
    pJm.addIf(getStateField(), "[" + pNum, "]");
    ParticleSG particle = particles[pNum];
    if (particle.isElement()) {
      pJm.addLine("getHandler().validationEvent(", ValidationEvent.class, ".WARNING, ",
            JavaSource.getQuoted("The element " + particle.getObjectSG().getName() +
                         " has already been defined."),
              ", ", ValidationEvents.class, ".EVENT_ALL_GROUP_REUSE, null);");
    } else if (particle.isGroup()) {
      pJm.addLine("getHandler().validationEvent(", ValidationEvent.class, ".WARNING, ",
            JavaSource.getQuoted("The group " + GroupUtil.getGroupName(particle.getGroupSG()) +
                       " has already been defined."),
              ", ", ValidationEvents.class, ".EVENT_ALL_GROUP_REUSE, null);");
    } else if (particle.isWildcard()) {
      throw new IllegalStateException("TODO: Add support for wildcards.");
    } else {
      throw new IllegalStateException("Invalid particle type");
    }
    pJm.addEndIf();
View Full Code Here

         * corrected via customization.
         */
        elementParticleArray = (Particle[]) elementParticles.toArray(new Particle[elementParticles.size()]);
        for (int i = 0;  i < elementParticleArray.length;  i++) {
            Particle pParticle = elementParticleArray[i];
            ParticleSG p = pParticle.getParticleSG();
            String name = p.getPropertySG().getXMLFieldName();
            for (int j = i+1;  j < elementParticles.size();  j++) {
                Particle qParticle = elementParticleArray[j];
                ParticleSG q = qParticle.getParticleSG();
                if (name.equals(q.getPropertySG().getXMLFieldName())) {
                    ObjectSG pObject = p.getObjectSG();
                    ObjectSG qObject = q.getObjectSG();
                    if (!pObject.isGlobal()  ||  !qObject.isGlobal()  ||
                        pObject != qObject) {
                        throw new SAXParseException("Multiple element particles named " + name
                                                    + ", which aren't references to "
                                                    + " a common global element, are present in a common"
View Full Code Here

    JavaField jf = getJavaSource().newJavaField("__state", int.class, JavaSource.PRIVATE);
    JavaComment jc = jf.newComment();
    jc.addLine("The current state. The following values are valid states:");
    jc.addLine(" 0 = Before parsing the element");
    for (int i = 0;  i < particles.length;  i++) {
      ParticleSG particle = particles[i];
      if (particle.isGroup()) {
        GroupSG group = particle.getGroupSG();
        if (group.isGlobal()) {
          jc.addLine(" " + getState(i) + " = While parsing the nested group " + group.getName());
        } else {
          jc.addLine(" " + getState(i) + " = While parsing the nested group " + GroupUtil.getGroupName(group));
        }
      } else if (particle.isElement()) {
        jc.addLine(" " + getState(i) + " = While or after parsing the child element " + particle.getObjectSG().getName());
      } else if (particle.isWildcard()) {
        throw new IllegalStateException("TODO: Add support for wildcards.");
      } else {
        throw new IllegalStateException("Invalid particle type.");
      }
    }
View Full Code Here

  private int getFirstValidParticle(int pState) {
    if (pState == 0) {
      return 0;
    } else {
      int i = fromState(pState);
      ParticleSG particle = particles[i];
      if (particle.isMultiple()) {
        return i;
      } else if (i+1 < particles.length) {
        return i+1;
      } else {
        return -1;
View Full Code Here

      if (lastParticle >= particles.length) {
        return fromState(pState);
      }
    }
    while (lastParticle < particles.length-1) {
      ParticleSG particle = particles[lastParticle];
      if (isRequiredParticle(particle)) {
        break;
      } else {
        ++lastParticle;
      }
View Full Code Here

  public JavaMethod newIsFinishedMethod() throws SAXException {
    JavaMethod result = super.newIsFinishedMethod();
    result.addSwitch(getStateField());
    boolean allOptional = true;
    for (int i = particles.length-1;  i >= 0;  i--) {
      ParticleSG particle = particles[i];
      result.addCase(new Integer(getState(i)));
      if (isRequiredParticle(particle)) {
        allOptional = false;
        break;
      }
View Full Code Here

    }
    ComplexContentSG ccSG = ctSG.getComplexContentSG();
    if (ccSG.isEmpty()) {
      return;
    }
    ParticleSG particle = ccSG.getRootParticle();
    generateCreateMethods(pJs, particle, pName, pContextSet);
  }
View Full Code Here

    if (particles == null) {
      XSParticle[] xsParticles = ((XSGroup) getXSObject()).getParticles();
      particles = new ParticleSG[xsParticles.length];
      for (int i = 0;  i < xsParticles.length;  i++) {
        ParticleSGChain chain = (ParticleSGChain) pController.newParticleSG(xsParticles[i]);
        ParticleSG particle = new ParticleSGImpl(chain);
        particle.init();
        particles[i] = particle;
      }
    }
    return particles;
  }
View Full Code Here

    // USAddress children
    String [] nameShouldBe = {"name", "street", "city""state", "zip"};
    ParticleSG [] usAddressChildren = usAddress.getComplexTypeSG().getComplexContentSG().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.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().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().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().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().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);
View Full Code Here

TOP

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

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.