예제 #1
0
  protected Entity addItem(Entity parentEntity, Integer qtyValue, Double priceValue) {
    EntityDefinition rootEntityDefn = parentEntity.getDefinition();
    EntityDefinition itemDefn = (EntityDefinition) rootEntityDefn.getChildDefinition("item");
    Entity item = (Entity) itemDefn.createNode();

    if (qtyValue != null) {
      NodeDefinition qtyDefn = itemDefn.getChildDefinition("qty");
      IntegerAttribute qty = (IntegerAttribute) qtyDefn.createNode();
      qty.setValue(new IntegerValue(qtyValue, null));
      item.add(qty);
    }
    if (priceValue != null) {
      NumericAttributeDefinition priceDefn =
          (NumericAttributeDefinition) itemDefn.getChildDefinition("price");
      RealAttribute price = (RealAttribute) priceDefn.createNode();
      price.setValue(new RealValue(priceValue, null));
      item.add(price);
    }
    NumberAttributeDefinition totalDefn =
        (NumberAttributeDefinition) itemDefn.getChildDefinition("total");
    RealAttribute total = (RealAttribute) totalDefn.createNode();
    item.add(total);

    NumberAttributeDefinition discountDefn =
        (NumberAttributeDefinition) itemDefn.getChildDefinition("discount_percent");
    IntegerAttribute discount = (IntegerAttribute) discountDefn.createNode();
    item.add(discount);

    parentEntity.add(item);
    return item;
  }
 @Override
 protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
   super.onStartDefinition();
   String typeStr = getAttribute(TYPE, false);
   NumericAttributeDefinition defn = (NumericAttributeDefinition) getDefinition();
   try {
     Type type = typeStr == null ? Type.REAL : Type.valueOf(typeStr.toUpperCase());
     defn.setType(type);
   } catch (IllegalArgumentException e) {
     throw new XmlParseException(getParser(), "unknown type " + typeStr);
   }
 }