Search in sources :

Example 6 with BasicEObjectImpl

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);
                }
            }
        }
    }
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) URI(org.eclipse.emf.common.util.URI) BasicEObjectImpl(org.eclipse.emf.ecore.impl.BasicEObjectImpl) Entry(java.util.Map.Entry) EAttribute(org.eclipse.emf.ecore.EAttribute) EList(org.eclipse.emf.common.util.EList) Relationship(org.neo4j.graphdb.Relationship) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

BasicEObjectImpl (org.eclipse.emf.ecore.impl.BasicEObjectImpl)6 EObject (org.eclipse.emf.ecore.EObject)5 EList (org.eclipse.emf.common.util.EList)3 URI (org.eclipse.emf.common.util.URI)3 EAttribute (org.eclipse.emf.ecore.EAttribute)3 EReference (org.eclipse.emf.ecore.EReference)3 Label (org.neo4j.graphdb.Label)3 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 Entry (java.util.Map.Entry)2 Other (org.iobserve.model.test.storage.one.Other)2 Link (org.iobserve.model.test.storage.two.Link)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Two (org.iobserve.model.test.storage.two.Two)1 NotFoundException (org.neo4j.graphdb.NotFoundException)1 PrimitiveDataType (org.palladiosimulator.pcm.repository.PrimitiveDataType)1 ResourceEnvironment (org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment)1 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)1