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

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


    element.addLine("(", elementInterface, ") ", pElement);
   
    AttributeSG[] myAttributes = pController.getAttributes();
    XMLSerializerAttributeSGlet sgLet = new XMLSerializerAttributeSGlet(result, pData);
    for (int i = 0;  i < attributes.length;  i++) {
      AttributeSG attribute = myAttributes[i];
      if (attribute.isWildcard()) {
          LocalJavaField anyAttributes = jm.newJavaField(WildcardAttribute[].class);
          anyAttributes.addLine(element, ".", attribute.getPropertySG().getXMLGetMethodName() + "Array", "()");
          DirectAccessible index = jm.addForArray(anyAttributes);
          LocalJavaField wildcardAttribute = jm.newJavaField(WildcardAttribute.class);
          wildcardAttribute.addLine(anyAttributes, "[", index, "]");
        LocalJavaField qName = jm.newJavaField(QName.class);
        qName.addLine(wildcardAttribute, ".getName()");
        LocalJavaField uri = jm.newJavaField(String.class);
        uri.addLine(qName, ".getNamespaceURI()");
        LocalJavaField localPart = jm.newJavaField(String.class);
        localPart.addLine(qName, ".getLocalPart()");
        jm.addLine(result, ".addAttribute(", uri, ", ", localPart,
               ", getAttributeQName(pData, ", uri, ", ", localPart,
                           "), \"CDATA\", ", wildcardAttribute, ".getValue());");
        jm.addEndFor();
      } else {
        sgLet.setAttribute(attribute);
        attribute.forAllNonNullValues(jm, element, sgLet);
      }
    }
    jm.addLine("return ", result, ";");
  }
View Full Code Here


  }

  private Set createSetOfExplicitURIs(AttributeSG[] pAttributes) {
    Set result = new HashSet();
    for (int i = 0;  i < pAttributes.length;  i++) {
      AttributeSG attr = pAttributes[i];
      if (attr.isWildcard()) {
        continue;
      }
      String uri = attr.getName().getNamespaceURI();
      if (uri == null) { uri = ""; }

      result.add(uri);
    }
    return result;
View Full Code Here

      String uri = (String) iter.next();
      jm.addIf(first, JavaSource.getQuoted(uri), ".equals(", pURI, ")");
      first = false;
        boolean firstInNamespace = true;
      for (int i = 0;  i < myAttributes.length;  i++) {
        AttributeSG attr = myAttributes[i];
        if (attr.isWildcard()) {
          continue;
        }
        String jUri = attr.getName().getNamespaceURI();
        if (jUri == null) { jUri = ""; }
        if (!uri.equals(jUri)) {
          continue;
        }
       
        jm.addIf(firstInNamespace, JavaSource.getQuoted(attr.getName().getLocalName()), ".equals(", pLocalName, ")");
        firstInNamespace = false;
        Object v = myAttributes[i].getTypeSG().getSimpleTypeSG().getCastFromString(jm, pValue, "getData()");
        attr.getPropertySG().setValue(jm, result, v, null);
        jm.addLine("return;");
      }
      if (!firstInNamespace) {
          jm.addEndIf();
      }
    }
    if (!first) {
      jm.addEndIf();
    }

    AttributeSG wildcard = null;
    for (int i = 0;  i < myAttributes.length;  i++) {
        if (myAttributes[i].isWildcard()) {
            wildcard = myAttributes[i];
            break;
        }
    }
    if (wildcard == null) {
        jm.addLine("super.addAttribute(", pURI, ", ", pLocalName, ", ", pValue, ");");
    } else {
        jm.addTry();
        jm.addLine(result, ".", wildcard.getPropertySG().getXMLSetMethodName(), "(new ",
                QName.class, "(", pURI, ", ", pLocalName, "), ", pValue, ");");
        jm.addCatch(IllegalArgumentException.class);
        jm.addLine("validationEvent(", ValidationEvent.class, ".ERROR, ",
                JavaSource.getQuoted("Invalid namespace for anyAttribute: '"),
                " + ", pURI, " + ", JavaSource.getQuoted("', attribute name is '"),
View Full Code Here

  /** Returns the set of namespace URI's in <code>pAttributes</code>.
   */
  private Set createSetOfExplicitURIs(AttributeSG[] pAttributes) {
    Set result = new HashSet();
    for (int i = 0;  i < pAttributes.length;  i++) {
      AttributeSG attr = pAttributes[i];
      if (!attr.isWildcard()) {
        String uri = attr.getName().getNamespaceURI();
        if (uri == null) { uri = ""; }
        result.add(uri);
      }
    }
    return result;
View Full Code Here

      String uri = (String) iter.next();
      jm.addIf(first, JavaSource.getQuoted(uri), ".equals(", pURI, ")");
      first = false;
      boolean firstInNamespace = true;
      for (int i = 0;  i < myAttributes.length;  i++) {
        AttributeSG attr = myAttributes[i];
        if (attr.isWildcard()) {
          continue;
        }
        String jUri = attr.getName().getNamespaceURI();
        if (jUri == null) { jUri = ""; }
        if (!uri.equals(jUri)) {
          continue;
        }
       
        jm.addIf(firstInNamespace, JavaSource.getQuoted(attr.getName().getLocalName()), ".equals(", pLocalName, ")");
        firstInNamespace = false;
        TypedValue v = createSimpleTypeConversion(jm, myAttributes[i].getTypeSG(), pValue, "@" + myAttributes[i].getName());
        attr.getPropertySG().setValue(jm, result, v, null);
        jm.addLine("return;");
      }
      if (!firstInNamespace) {
        jm.addEndIf();
      }
    }
    if (!first) {
      jm.addEndIf();
    }
   
    AttributeSG wildcard = null;
    for (int i = 0;  i < myAttributes.length;  i++) {
      if (myAttributes[i].isWildcard()) {
        wildcard = myAttributes[i];
        break;
      }
    }
    if (wildcard == null) {
      jm.addLine("super.addAttribute(", pURI, ", ", pLocalName, ", ", pValue, ");");
    } else {
      jm.addTry();
      jm.addLine(result, ".", wildcard.getPropertySG().getXMLSetMethodName(), "(new ",
          QName.class, "(", pURI, ", ", pLocalName, "), ", pValue, ");");
      jm.addCatch(IllegalArgumentException.class);
      jm.addLine("getHandler().validationEvent(", ValidationEvent.class, ".ERROR, ",
          JavaSource.getQuoted("Invalid namespace for anyAttribute: '"),
          " + ", pURI, " + ", JavaSource.getQuoted("', attribute name is '"),
View Full Code Here

      if (tSG.isComplex()) {
        inheritedAttributes = tSG.getComplexTypeSG().getAttributes();
      }
    }
    for (int i = 0;  i < myAttributes.length;  i++) {
      AttributeSG attr = myAttributes[i];
      if (!isInheritedAttribute(attr, inheritedAttributes)) {
        attr.getPropertySG().generate(js);
      }
    }
  }
View Full Code Here

    protected void addAttribute(TypeSG pComplexTypeSG, XSType pParent,
                XsQName pName, XSType pType, String pPropertyName)
        throws SAXException {
        AttributeSG[] attrs = pComplexTypeSG.getComplexTypeSG().getAttributes();
        for (int i = 0;  i < attrs.length;  i++) {
            AttributeSG attr = attrs[i];
            if (attr.isWildcard()) {
                continue;
            }
      XsQName qName = attr.getName();
      if (qName.equals(pName)) {
          return;
            }
        }

        XSAttribute attribute = new InoAttribute(pParent, pName, pType, pPropertyName);
        AttributeSGChain chain = (AttributeSGChain) pComplexTypeSG.getComplexTypeSG().newAttributeSG(attribute);
        AttributeSG attributeSG = new AttributeSGImpl(chain);
        pComplexTypeSG.getComplexTypeSG().addAttributeSG(attributeSG);
    }
View Full Code Here

    assertTrue(types[0].isComplex());

    AttributeSG[] attr = types[0].getComplexTypeSG().getAttributes();
    assertEquals(3, attr.length);

    AttributeSG attr1 = attr[0];
    assertTrue(!attr1.getTypeSG().isComplex());
    SimpleTypeSG sst1 = attr1.getTypeSG().getSimpleTypeSG();
    assertTrue(sst1.isAtomic());
    assertEquals(JavaQNameImpl.getInstance(String.class), sst1.getRuntimeType());

    AttributeSG attr2 = attr[1];
    assertTrue(!attr2.getTypeSG().isComplex());
    SimpleTypeSG sst2 = attr2.getTypeSG().getSimpleTypeSG();
    assertTrue(sst2.isAtomic());
    assertEquals(JavaQNameImpl.INT, sst2.getRuntimeType());

    AttributeSG attr3 = attr[2];
    assertTrue(!attr3.getTypeSG().isComplex());
    SimpleTypeSG sst3 = attr3.getTypeSG().getSimpleTypeSG();
    assertTrue(sst3.isAtomic());
    assertEquals(JavaQNameImpl.INT, sst3.getRuntimeType());
  }
View Full Code Here

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

      if (tSG.isComplex()) {
        inheritedAttributes = tSG.getComplexTypeSG().getAttributes();
      }
    }
    for (int i = 0;  i < myAttributes.length;  i++) {
      AttributeSG attr = myAttributes[i];
      if (!isInheritedAttribute(attr, inheritedAttributes)) {
        attr.getPropertySG().generate(js);
      }
    }
  }
View Full Code Here

TOP

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

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.