Exemple #1
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));
     }
   }
 }
Exemple #2
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);
       }
     }
   }
 }
Exemple #3
0
 private void writeChildren(XmlSerializer serializer, Entity rootEntity) throws IOException {
   List<Node<?>> children = rootEntity.getChildren();
   for (Node<?> node : children) {
     write(serializer, node);
   }
   writeEmptyNodes(serializer, rootEntity);
 }
Exemple #4
0
  private void write(XmlSerializer serializer, Entity entity) throws IOException {
    String name = entity.getName();

    serializer.startTag(null, name);

    writeState(serializer, entity);

    writeChildren(serializer, entity);

    serializer.endTag(null, name);
  }
Exemple #5
0
  private Object extractNonEmptyChildren(String propertyName, Entity entity) {
    List<Node<?>> list = new ArrayList<Node<?>>();

    for (Node<?> childNode : entity.getAll(propertyName)) {
      if (childNode instanceof Entity || (!childNode.isEmpty())) {
        list.add(childNode);
      }
    }
    if (list.isEmpty()) {
      return null;
    }
    return Collections.unmodifiableList(list);
  }
Exemple #6
0
  public void write(CollectRecord record, Writer out) throws IOException, XmlPullParserException {
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    XmlSerializer serializer = factory.newSerializer();
    serializer.setFeature(INDENT_FEATURE, true);
    serializer.setOutput(out);
    // do not use UTF-8 encoding: unicode text will be escaped by the serializer instead
    // serializer.startDocument("UTF-8", true);
    serializer.startDocument(null, true);

    Entity rootEntity = record.getRootEntity();
    String rootEntityName = rootEntity.getName();
    serializer.startTag(null, rootEntityName);

    ModelVersion version = record.getVersion();
    if (version != null) {
      serializer.attribute(null, RECORD_VERSION_ATTRIBUTE, version.getName());
    }
    serializer.attribute(
        null, RECORD_STEP_ATTRIBUTE, Integer.toString(record.getStep().getStepNumber()));
    if (record.getState() != null) {
      serializer.attribute(null, STATE_ATTRIBUTE, record.getState().getCode());
    }
    User createdBy = record.getCreatedBy();
    if (createdBy != null) {
      serializer.attribute(null, RECORD_CREATED_BY_ATTRIBUTE, createdBy.getName());
    }
    User modifiedBy = record.getModifiedBy();
    if (modifiedBy != null) {
      serializer.attribute(null, RECORD_MODIFIED_BY_ATTRIBUTE, modifiedBy.getName());
    }
    addDateAttribute(serializer, RECORD_CREATED_ATTRIBUTE, record.getCreationDate());
    addDateAttribute(serializer, RECORD_MODIFIED_ATTRIBUTE, record.getModifiedDate());

    writeChildren(serializer, rootEntity);
    serializer.endTag(null, rootEntityName);
    serializer.endDocument();
    serializer.flush();
  }
Exemple #7
0
 private NodeDefinition getChildDefinition(Entity entity, String childName) {
   EntityDefinition entityDefn = entity.getDefinition();
   NodeDefinition childDefn = entityDefn.getChildDefinition(childName);
   return childDefn;
 }