use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class EntityBuilder method createNode.
private static <T extends Node<D>, D extends NodeDefinition> T createNode(Entity entity, String name, Class<T> type, Class<D> definitionType) {
try {
EntityDefinition entityDefn = entity.getDefinition();
NodeDefinition definition = entityDefn.getChildDefinition(name, definitionType);
Constructor<T> constructor = type.getConstructor(definitionType);
return constructor.newInstance(definition);
} catch (SecurityException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
} else {
throw new RuntimeException(e);
}
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class EntityBuilder method createEntity.
public static Entity createEntity(Entity parentEntity, String name) {
EntityDefinition parentDefn = parentEntity.getDefinition();
EntityDefinition defn = parentDefn.getChildDefinition(name, EntityDefinition.class);
Entity entity = (Entity) defn.createNode();
return entity;
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class EntityDefinitionPR method onStartDefinition.
@Override
protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
super.onStartDefinition();
EntityDefinition def = (EntityDefinition) getDefinition();
boolean virtual = getBooleanAttributeWithDefault(VIRTUAL, false);
def.setVirtual(virtual);
if (virtual) {
String generatorExpression = getAttribute(GENERATOR_EXPRESSION, true);
def.setGeneratorExpression(generatorExpression);
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class NodePointerDependencyGraph method toItems.
@Override
protected Collection<NodePointer> toItems(Node<?> node) {
if (node instanceof Entity) {
EntityDefinition def = (EntityDefinition) node.getDefinition();
List<NodeDefinition> defs = def.getChildDefinitionsInVersion(node.getModelVersion());
List<NodePointer> result = new ArrayList<NodePointer>(defs.size());
for (NodeDefinition childDef : defs) {
result.add(new NodePointer((Entity) node, childDef));
}
return result;
} else if (node.getParent() != null) {
return Collections.singleton(new NodePointer(node));
} else {
return Collections.emptySet();
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class EntitySchema method writeTo.
@Override
public void writeTo(Output out, Entity entity) throws IOException {
List<Node<? extends NodeDefinition>> children = entity.getChildren();
for (Node<?> node : children) {
if (isNodeToBeSaved(node)) {
out.writeUInt32(DEFINITION_ID_FIELD_NUMBER, node.getDefinition().getId(), false);
out.writeObject(NODE_FIELD_NUMBER, node, getSchema(node.getClass()), false);
}
}
EntityDefinition definition = entity.getDefinition();
List<NodeDefinition> childDefinitions = definition.getChildDefinitions();
for (NodeDefinition childDefinition : childDefinitions) {
State childState = entity.getChildState(childDefinition);
out.writeInt32(CHILD_NODE_STATE_FIELD_NUMBER, childState.intValue(), false);
out.writeInt32(CHILD_DEFINITION_ID_FIELD_NUMBER, childDefinition.getId(), false);
}
}
Aggregations