Search in sources :

Example 1 with ProtostuffException

use of com.dyuproject.protostuff.ProtostuffException in project collect by openforis.

the class AttributeSchema method mergeFrom.

@Override
public void mergeFrom(Input input, T attr) throws IOException {
    int cnt = attr.getFieldCount();
    for (int number = input.readFieldNumber(this), fieldIndex = 0; number > 0; number = input.readFieldNumber(this), fieldIndex++) {
        if (fieldIndex >= cnt) {
            throw new ProtostuffException("Too many attribute fields");
        } else if (number != 1) {
            throw new ProtostuffException("Unexpected field number");
        } else {
            Field<?> fld = attr.getField(fieldIndex);
            input.mergeObject(fld, ATTRIBUTE_FIELD_SCHEMA);
        }
    }
    attr.updateSummaryInfo();
}
Also used : ProtostuffException(com.dyuproject.protostuff.ProtostuffException)

Example 2 with ProtostuffException

use of com.dyuproject.protostuff.ProtostuffException in project collect by openforis.

the class EntitySchema method mergeFrom.

@Override
public void mergeFrom(Input input, Entity entity) throws IOException {
    EntityDefinition entityDef = entity.getDefinition();
    for (int number = input.readFieldNumber(this); number > 0; number = input.readFieldNumber(this)) {
        switch(number) {
            case DEFINITION_ID_FIELD_NUMBER:
                // Definition id
                int definitionId = input.readUInt32();
                NodeDefinition defn = null;
                try {
                    defn = entityDef.getChildDefinition(definitionId);
                } catch (IllegalArgumentException e) {
                // not existing child definition
                }
                if (defn == null || (defn instanceof AttributeDefinition && ((AttributeDefinition) defn).isCalculated())) {
                    skipNode(input);
                } else {
                    Node<?> node = defn.createNode();
                    entity.add(node);
                    // Node
                    readAndCheckFieldNumber(input, NODE_FIELD_NUMBER);
                    input.mergeObject(node, getSchema(node.getClass()));
                }
                break;
            case CHILD_NODE_STATE_FIELD_NUMBER:
                // Node state
                int intState = input.readInt32();
                State state = State.parseState(intState);
                readAndCheckFieldNumber(input, CHILD_DEFINITION_ID_FIELD_NUMBER);
                int childDefnId = input.readInt32();
                NodeDefinition childDefn = null;
                try {
                    childDefn = entityDef.getChildDefinition(childDefnId);
                    entity.setChildState(childDefn, state);
                } catch (IllegalArgumentException e) {
                // not existing child definition
                }
                break;
            default:
                throw new ProtostuffException("Unexpected field number");
        }
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) ProtostuffException(com.dyuproject.protostuff.ProtostuffException)

Aggregations

ProtostuffException (com.dyuproject.protostuff.ProtostuffException)2 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1