use of org.eclipse.emf.ecore.impl.BasicEObjectImpl in project iobserve-analysis by research-iobserve.
the class ModelProvider method loadRelatedNodes.
/**
* Load related nodes representing referenced components.
*
* @param component
* component the other components are related to
* @param node
* the corresponding node to the component
* @param containmentsAndDatatypes
* datatypes
* @param nodesToCreatedObjects
* additional nodes
*/
@SuppressWarnings("unchecked")
private void loadRelatedNodes(final EObject component, final Node node, final Set<Node> containmentsAndDatatypes, final Map<Node, EObject> nodesToCreatedObjects) {
for (final Relationship rel : ModelProviderUtil.sortRelsByPosition(node.getRelationships(Direction.OUTGOING))) {
final Node endNode = rel.getEndNode();
final String relName = (String) rel.getProperty(ModelProvider.REF_NAME);
final EReference ref = (EReference) component.eClass().getEStructuralFeature(relName);
Object refReprensation = component.eGet(ref);
// For partial reading: Only load containments and data types of the root
if (containmentsAndDatatypes.contains(endNode)) {
if (refReprensation instanceof EList<?>) {
final EObject endComponent = this.readNodes(endNode, containmentsAndDatatypes, nodesToCreatedObjects);
((EList<EObject>) refReprensation).add(endComponent);
} else {
refReprensation = this.readNodes(endNode, containmentsAndDatatypes, nodesToCreatedObjects);
component.eSet(ref, refReprensation);
}
} else {
// Create proxy EObject here...
final Label endLabel = ModelProviderUtil.getFirstLabel(endNode.getLabels());
final EObject endComponent = ModelProviderUtil.instantiateEObject(endLabel.name());
if (endComponent != null) {
final URI endUri = URI.createURI(endNode.getProperty(ModelProvider.EMF_URI).toString());
((BasicEObjectImpl) endComponent).eSetProxyURI(endUri);
// Load attribute values from the node
final Iterator<Map.Entry<String, Object>> i2 = endNode.getAllProperties().entrySet().iterator();
while (i2.hasNext()) {
final Entry<String, Object> property = i2.next();
final EAttribute attr = (EAttribute) endComponent.eClass().getEStructuralFeature(property.getKey());
// attr == null for the emfUri property stored in the graph
if (attr != null) {
final Object value = ModelProviderUtil.instantiateAttribute(attr.getEAttributeType().getInstanceClass(), property.getValue().toString());
if (value != null) {
endComponent.eSet(attr, value);
}
}
}
if (refReprensation instanceof EList<?>) {
((EList<EObject>) refReprensation).add(endComponent);
} else {
component.eSet(ref, endComponent);
}
}
}
}
}
Aggregations