Example #1
0
 private void writeField(XmlSerializer serializer, Attribute<?, ?> attr, int fieldIdx)
     throws IOException {
   AttributeDefinition definition = attr.getDefinition();
   List<FieldDefinition<?>> fldDefns = definition.getFieldDefinitions();
   Field<?> fld = attr.getField(fieldIdx);
   if (fld.hasData()) {
     FieldDefinition<?> fldDefn = fldDefns.get(fieldIdx);
     String name = fldDefn.getName();
     serializer.startTag(null, name);
     Object val = fld.getValue();
     if (StringUtils.isNotBlank(fld.getRemarks())) {
       serializer.attribute(null, REMARKS_ATTRIBUTE, fld.getRemarks());
     }
     if (fld.getSymbol() != null) {
       serializer.attribute(null, SYMBOL_ATTRIBUTE, fld.getSymbol().toString());
     }
     State state = fld.getState();
     int stateInt = state.intValue();
     if (stateInt > 0) {
       serializer.attribute(null, STATE_ATTRIBUTE, Integer.toString(stateInt));
     }
     if (val != null) {
       String valStr = val.toString();
       serializer.text(valStr);
     }
     serializer.endTag(null, name);
   }
 }
Example #2
0
 private void writeState(XmlSerializer serializer, Node<?> node) throws IOException {
   Entity parent = node.getParent();
   if (parent != null) {
     State s = parent.getChildState(node.getName());
     int state = s.intValue();
     if (state > 0) {
       serializer.attribute(null, STATE_ATTRIBUTE, Integer.toString(state));
     }
   }
 }
Example #3
0
 /**
  * Writes empty nodes child of an entity if there is a node state specified.
  *
  * @param serializer
  * @param entity
  * @throws IOException
  */
 private void writeEmptyNodes(XmlSerializer serializer, Entity entity) throws IOException {
   EntityDefinition defn = entity.getDefinition();
   List<NodeDefinition> childDefns = defn.getChildDefinitions();
   for (NodeDefinition childDefn : childDefns) {
     String childName = childDefn.getName();
     if (entity.getCount(childName) == 0) {
       State childState = entity.getChildState(childName);
       int childStateInt = childState.intValue();
       if (childStateInt > 0) {
         serializer.startTag(null, childName);
         serializer.attribute(null, STATE_ATTRIBUTE, Integer.toString(childStateInt));
         serializer.endTag(null, childName);
       }
     }
   }
 }