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

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


    LocalJavaField element = result.newJavaField(elementInterface);
    element.addLine("(", elementInterface, ") result");
    result.addSwitch(getEndElementState());
    for (int i = 0;  i < particles.length;  i++) {
      result.addCase(new Integer(getState(i)));
      ParticleSG particle = particles[i];
      handleEndElementState(result, element, particle);
    }
    result.addDefault();
    result.addThrowNew(IllegalStateException.class,
               JavaSource.getQuoted("Illegal state: "), " + ",
View Full Code Here


        sep = "Choice";
      }
      int num = 0;
      ParticleSG[] groupParticles = pGroup.getParticles();
      for (int i = 0;  i < groupParticles.length;  i++) {
        ParticleSG particle = groupParticles[i];
        if (particle.isElement()) {
          if (num++ > 0) {
            sb.append(sep);
          }
          String f = particle.getPropertySG().getPropertyName();
          sb.append(Character.toUpperCase(f.charAt(0)) + f.substring(1));
          if (num == 3) {
            break;
          }
        }
View Full Code Here

   */
  private void generateCreateMethods(JavaSource pJs, ParticleSG[] pParticles,
                     String pName, Set pContextSet)
      throws SAXException {
    for (int i = 0;  i < pParticles.length;  i++) {
      ParticleSG particle = pParticles[i];
      if (particle.isGroup()) {
        GroupSG group = particle.getGroupSG();
        generateCreateMethods(pJs, group.getParticles(), pName, pContextSet);
      } else if (particle.isElement()) {
        ObjectSG oSG = particle.getObjectSG();
        if (oSG.isGlobal()) {
          continue// Will be generated elsewhere
        }
        TypeSG tSG = oSG.getTypeSG();
        if (tSG.isGlobalType()) {
          continue// Will be generated elsewhere
        }
        generateCreateMethod(pJs, pContextSet, tSG, pName);
      } else if (particle.isWildcard()) {
        throw new IllegalStateException("TODO: Add support for wildcards here.");
      } else {
        throw new IllegalStateException("Invalid class type");
      }
    }
View Full Code Here

    // 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);
View Full Code Here

    jc.addLine("If the same child occurs again, and the childs boolean");
    jc.addLine("value is true, then an exception is thrown.");
    jc.addLine("These are the indices, to which the child elements are");
    jc.addLine("mapped:");
    for (int i = 0;  i < particles.length;  i++) {
      ParticleSG particle = particles[i];
      if (particle.isGroup()) {
        GroupSG group = particle.getGroupSG();
        if (group.isGlobal()) {
          jc.addLine(" " + i + " = The nested group " + group.getName());
        } else {
          jc.addLine(" " + i + " = An anonymous nested group.");
        }
      } else if (particle.isElement()) {
        jc.addLine(" " + i + " = 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

   * @throws SAXException Walking over the groups particles failed.
   */
  private void walkParticles(GroupSG pGroup) throws SAXException {
    ParticleSG[] particles = pGroup.getParticles();
    for (int i = 0;  i < particles.length;  i++) {
      ParticleSG particle = particles[i];
      if (particle.isElement()) {
        TypeSG type = particle.getObjectSG().getTypeSG();
        if (type.isComplex()) {
          visitor.complexElementParticle(pGroup, particle);
        } else {
          visitor.simpleElementParticle(pGroup, particle);
        }
      } else if (particle.isGroup()) {
        walkGroup(particle.getGroupSG());
      } else if (particle.isWildcard()) {
        visitor.wildcardParticle(particle);
      } else {
        throw new IllegalStateException("Invalid particle type");
      }
    }
View Full Code Here

    }
  }

  private void findGroups(ParticleSG[] pParticles) throws SAXException {
    for (int i = 0;  i < pParticles.length;  i++) {
      ParticleSG particle = pParticles[i];
      if (particle.isGroup()) {
        GroupSG group = particle.getGroupSG();
        if (!groups.containsKey(group)) {
          GroupHandlerSG handler = newGroupHandlerSG(particle);
          groups.put(group, handler);
        }
      } else if (particle.isElement()) {
        TypeSG tSG = particle.getObjectSG().getTypeSG();
        if (tSG.isComplex()  &&  !tSG.isGlobalClass()) {
          tSG.getComplexTypeSG().getXMLHandler(outerHandler.getJavaSource());
        }
      }
    }
View Full Code Here

    if (pFrom < ||  pFrom >= particles.length  ||
        pTo < ||  pTo >= particles.length  ||  pTo < pFrom) {
      return;
    }
    for (int i = pFrom;  i <= pTo;  i++) {
      ParticleSG particle = particles[i];
      if (particle.isElement()) {
        ObjectSG oSG = particle.getObjectSG();
        XsQName name = oSG.getName();
        Object uriCondition;
        if ("".equals(name.getNamespaceURI())) {
          uriCondition = new Object[]{"(", getParamNamespaceURI(),
              " == null  ||  ",
              getParamNamespaceURI(),
          ".length() == 0)"};
        } else {
          uriCondition = new Object[]{JavaSource.getQuoted(name.getNamespaceURI()),
              ".equals(", getParamNamespaceURI(), ")"};
        }
        pJm.addIf(i == pFrom, uriCondition, "  &&  ",
              JavaSource.getQuoted(name.getLocalName()),
              ".equals(", getParamLocalName(), ")");
        acceptParticle(pJm, i);
        handleStartOfChildElement(pUnmarshallerHandler, pJm, particle);
        pJm.addLine("return true;");
      } else if (particle.isGroup()) {
        GroupSG gSG = particle.getGroupSG();
        GroupHandlerSG handlerSG = getGroupHandlerSG(gSG);
        pJm.addIf(i == pFrom,
              pUnmarshallerHandler, ".testGroupParser(new ",
              handlerSG.getJavaSource().getQName(), "(), ",
              getParamNamespaceURI(), ", ", getParamLocalName(),
              ", ", getParamQName(), ", ", getParamAttrs(), ")");
        acceptParticle(pJm, i);
        pJm.addLine("return true;");
      } else if (particle.isWildcard()) {
        throw new IllegalStateException("TODO: Add support for wildcards");
      } else {
        throw new IllegalStateException("Invalid particle type");
      }
    }
View Full Code Here

    LocalJavaField element = result.newJavaField(elementInterface);
    element.addLine("(", elementInterface, ") result");
    result.addSwitch(getEndElementState());
    for (int i = 0;  i < particles.length;  i++) {
      result.addCase(new Integer(getState(i)));
      ParticleSG particle = particles[i];
      handleEndElementState(result, element, particle);
    }
    result.addDefault();
    result.addThrowNew(IllegalStateException.class,
               JavaSource.getQuoted("Illegal state: "), " + ",
View Full Code Here

        sep = "Choice";
      }
      int num = 0;
      ParticleSG[] groupParticles = pGroup.getParticles();
      for (int i = 0;  i < groupParticles.length;  i++) {
        ParticleSG particle = groupParticles[i];
        if (particle.isElement()) {
          if (num++ > 0) {
            sb.append(sep);
          }
          String f = particle.getPropertySG().getPropertyName();
          sb.append(Character.toUpperCase(f.charAt(0)) + f.substring(1));
          if (num == 3) {
            break;
          }
        }
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.