Search in sources :

Example 1 with State

use of org.openforis.idm.model.State in project collect by openforis.

the class DataMarshaller method writeField.

private void writeField(XmlSerializer serializer, Attribute<?, ?> attr, int fieldIdx) throws IOException {
    Field<?> fld = attr.getField(fieldIdx);
    if (fld.hasData()) {
        FieldDefinition<?> fldDefn = fld.getDefinition();
        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);
    }
}
Also used : State(org.openforis.idm.model.State)

Example 2 with State

use of org.openforis.idm.model.State in project collect by openforis.

the class DataMarshaller method writeEmptyNodes.

/**
 * 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) {
        if (entity.getCount(childDefn) == 0) {
            State childState = entity.getChildState(childDefn);
            int childStateInt = childState.intValue();
            if (childStateInt > 0) {
                String childName = childDefn.getName();
                serializer.startTag(null, childName);
                serializer.attribute(null, STATE_ATTRIBUTE, Integer.toString(childStateInt));
                serializer.endTag(null, childName);
            }
        }
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) State(org.openforis.idm.model.State) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 3 with State

use of org.openforis.idm.model.State in project collect by openforis.

the class DataMarshaller method writeState.

private void writeState(XmlSerializer serializer, Node<?> node) throws IOException {
    Entity parent = node.getParent();
    if (parent != null) {
        State s = parent.getChildState(node.getDefinition());
        int state = s.intValue();
        if (state > 0) {
            serializer.attribute(null, STATE_ATTRIBUTE, Integer.toString(state));
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) State(org.openforis.idm.model.State)

Aggregations

State (org.openforis.idm.model.State)3 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 Entity (org.openforis.idm.model.Entity)1