Search in sources :

Example 6 with EReference

use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.

the class ModelHelper method copy.

@SuppressWarnings({ "unchecked", "rawtypes" })
private IdEObject copy(EClass originalEClass, IdEObject original, boolean setOid, ObjectIDM objectIDM) throws IfcModelInterfaceException {
    if (!((IdEObjectImpl) original).isLoadedOrLoading()) {
        return null;
    }
    if (converted.containsKey(original)) {
        return converted.get(original);
    }
    IdEObject newObject = (IdEObject) objectFactory.create(original.eClass());
    ((IdEObjectImpl) newObject).setPid(original.getPid());
    ((IdEObjectImpl) newObject).setLoadingState(State.LOADED);
    long oid = -1;
    if (keepOriginalOids) {
        oid = original.getOid();
        ((IdEObjectImpl) newObject).setOid(oid);
    } else {
        if (newObject.getOid() == -1) {
            if (oidProvider != null) {
                oid = oidProvider.newOid(newObject.eClass());
            } else {
                oid = original.getOid();
            }
        }
    }
    if (setOid && newObject.getOid() == -1) {
        ((IdEObjectImpl) newObject).setOid(oid);
    }
    converted.put(original, newObject);
    if (newObject.eClass().getEAnnotation("wrapped") == null) {
        targetModel.add(newObject.getOid(), newObject);
    }
    if (inverseFixes.containsKey(original.getOid())) {
        InverseFix inverseFix = inverseFixes.get(original.getOid());
        inverseFix.apply(newObject);
    }
    for (EStructuralFeature eStructuralFeature : original.eClass().getEAllStructuralFeatures()) {
        boolean canFollow = objectIDM == null || objectIDM.shouldFollowReference(originalEClass, original.eClass(), eStructuralFeature);
        Object get = original.eGet(eStructuralFeature);
        if (eStructuralFeature instanceof EAttribute) {
            if (get instanceof List) {
                List list = (List) get;
                List targetList = (List) newObject.eGet(eStructuralFeature);
                for (Object o : list) {
                    targetList.add(o);
                }
            } else {
                newObject.eSet(eStructuralFeature, get);
            }
        } else if (eStructuralFeature instanceof EReference) {
            if (!canFollow) {
                continue;
            }
            if (get == null) {
            } else {
                if (eStructuralFeature.isMany()) {
                    EList<EObject> list = (EList<EObject>) get;
                    AbstractEList<EObject> toList = (AbstractEList<EObject>) newObject.eGet(eStructuralFeature);
                    for (Object o : list) {
                        if (converted.containsKey(o)) {
                            toList.addUnique(converted.get(o));
                        } else {
                            if (canFollow) {
                                IdEObject result = copy(originalEClass, (IdEObject) o, setOid, objectIDM);
                                if (result != null) {
                                    toList.addUnique(result);
                                }
                            } else {
                                // Findbugs says canFollow is always true at this point and it's right, TODO
                                if (eStructuralFeature.getName().equals("RelatedElements")) {
                                    inverseFixes.put(((IdEObject) o).getOid(), new InverseFix(Ifc2x3tc1Package.eINSTANCE.getIfcRelContainedInSpatialStructure_RelatedElements(), newObject));
                                }
                            }
                        }
                    }
                } else {
                    if (converted.containsKey(get)) {
                        newObject.eSet(eStructuralFeature, converted.get(get));
                    } else {
                        if (canFollow) {
                            newObject.eSet(eStructuralFeature, copy(originalEClass, (IdEObject) get, setOid, objectIDM));
                        }
                    }
                }
            }
        }
    }
    return newObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) AbstractEList(org.eclipse.emf.common.util.AbstractEList) IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EAttribute(org.eclipse.emf.ecore.EAttribute) EList(org.eclipse.emf.common.util.EList) AbstractEList(org.eclipse.emf.common.util.AbstractEList) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) AbstractEList(org.eclipse.emf.common.util.AbstractEList) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 7 with EReference

use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.

the class SharedJsonDeserializer method processRef.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void processRef(IfcModelInterface model, WaitingList<Long> waitingList, IdEObjectImpl object, EStructuralFeature eStructuralFeature, int index, AbstractEList list, long refOid) throws DeserializeException {
    EntityDefinition entityBN = model.getPackageMetaData().getSchemaDefinition().getEntityBN(object.eClass().getName());
    Attribute attributeBN = entityBN.getAttributeBNWithSuper(eStructuralFeature.getName());
    if (skipInverses && attributeBN instanceof InverseAttribute && ((EReference) eStructuralFeature).getEOpposite() != null) {
    // skip
    } else {
        if (model.contains(refOid)) {
            EObject referencedObject = model.get(refOid);
            if (referencedObject != null) {
                addToList(eStructuralFeature, index, list, referencedObject);
            }
        } else {
            waitingList.add(refOid, new ListWaitingObject(-1, object, (EReference) eStructuralFeature, index));
        }
    }
}
Also used : EntityDefinition(nl.tue.buildingsmart.schema.EntityDefinition) EAttribute(org.eclipse.emf.ecore.EAttribute) Attribute(nl.tue.buildingsmart.schema.Attribute) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute) EObject(org.eclipse.emf.ecore.EObject) ListWaitingObject(org.bimserver.shared.ListWaitingObject) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute) EReference(org.eclipse.emf.ecore.EReference)

Example 8 with EReference

use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.

the class SharedJsonSerializer method writeObject.

private void writeObject(IdEObject object) throws IOException {
    if (((IdEObjectImpl) object).getLoadingState() != State.LOADED) {
        print("{");
        print("\"_i\":" + object.getOid() + ",");
        print("\"_t\":\"" + object.eClass().getName() + "\",");
        print("\"_s\":0");
        print("}\n");
    } else {
        print("{");
        print("\"_i\":" + object.getOid() + ",");
        print("\"_t\":\"" + object.eClass().getName() + "\",");
        print("\"_s\":1");
        for (EStructuralFeature eStructuralFeature : object.eClass().getEAllStructuralFeatures()) {
            if (eStructuralFeature.getEAnnotation("nolazyload") == null && (eStructuralFeature.getEAnnotation("hidden") == null || includeHidden)) {
                if (eStructuralFeature instanceof EReference) {
                    Object value = object.eGet(eStructuralFeature);
                    if (value != null) {
                        if (eStructuralFeature.isMany()) {
                            List<?> list = (List<?>) value;
                            if (SERIALIZE_EMPTY_LISTS || !list.isEmpty()) {
                                print(",");
                                int wrapped = 0;
                                int referred = 0;
                                for (Object o : list) {
                                    if (((IdEObject) o).eClass().getEAnnotation("wrapped") != null) {
                                        // A little tricky,
                                        // can we assume if
                                        // one object in
                                        // this list is
                                        // embedded, they
                                        // all are?
                                        wrapped++;
                                    } else {
                                        referred++;
                                    }
                                }
                                if (wrapped == 0 && referred != 0) {
                                    print("\"_r" + eStructuralFeature.getName() + "\":[");
                                } else if (wrapped != 0 && referred == 0) {
                                    print("\"_e" + eStructuralFeature.getName() + "\":[");
                                } else if (wrapped == 0 && referred == 0) {
                                // should not happen
                                } else {
                                    // both, this can occur,
                                    // for example
                                    // IfcTrimmedCurve.Trim1
                                    print("\"_e" + eStructuralFeature.getName() + "\":[");
                                }
                                boolean f = true;
                                for (Object o : list) {
                                    if (!f) {
                                        print(",");
                                    } else {
                                        f = false;
                                    }
                                    IdEObject ref = (IdEObject) o;
                                    EClass eClass = ((IdEObject) o).eClass();
                                    if (ref.getOid() < 0 || eClass.getEAnnotation("wrapped") != null || eStructuralFeature.getEAnnotation("dbembed") != null) {
                                        write(ref);
                                    } else {
                                        if (wrapped != 0 && referred != 0) {
                                            // Special
                                            // situation,
                                            // where we have
                                            // to construct
                                            // an object
                                            // around the
                                            // OID to make
                                            // it
                                            // distinguishable
                                            // from embedded
                                            // objects
                                            print("{");
                                            print("\"_i\":");
                                            print("" + ref.getOid());
                                            print(",\"_t\":");
                                            print("\"" + ref.eClass().getName() + "\"");
                                            print("}");
                                        } else {
                                            print("" + ref.getOid());
                                        }
                                    }
                                }
                                print("]");
                            }
                        } else {
                            print(",");
                            IdEObject ref = (IdEObject) value;
                            if (ref instanceof IfcGloballyUniqueId) {
                                print("\"" + eStructuralFeature.getName() + "\":");
                                writePrimitive(eStructuralFeature, ((IfcGloballyUniqueId) ref).getWrappedValue());
                            } else if (((IdEObject) ref).eClass().getEAnnotation("wrapped") != null) {
                                print("\"_e" + eStructuralFeature.getName() + "\":");
                                write(ref);
                            } else if (eStructuralFeature.getEAnnotation("dbembed") != null) {
                                print("\"_e" + eStructuralFeature.getName() + "\":");
                                writeEmbedded(ref);
                            } else {
                                print("\"_r" + eStructuralFeature.getName() + "\":{\"_i\":" + ref.getOid() + ",\"_t\":\"" + ref.eClass().getName() + "\"}");
                            }
                        }
                    }
                } else {
                    Object value = object.eGet(eStructuralFeature);
                    if (value != null) {
                        if (eStructuralFeature.isMany()) {
                            List<?> list = (List<?>) value;
                            if (SERIALIZE_EMPTY_LISTS || !list.isEmpty()) {
                                print(",");
                                print("\"" + eStructuralFeature.getName() + "\":[");
                                boolean f = true;
                                for (Object o : list) {
                                    if (!f) {
                                        print(",");
                                    } else {
                                        f = false;
                                    }
                                    writePrimitive(eStructuralFeature, o);
                                }
                                print("]");
                            }
                        } else {
                            print(",");
                            print("\"" + eStructuralFeature.getName() + "\":");
                            writePrimitive(eStructuralFeature, value);
                        }
                    }
                }
            }
        }
        print("}\n");
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IfcGloballyUniqueId(org.bimserver.models.ifc2x3tc1.IfcGloballyUniqueId) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 9 with EReference

use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.

the class SharedJsonStreamingSerializer method writeObject.

private void writeObject(HashMapVirtualObject object) throws IOException, BimserverDatabaseException {
    // if (((IdEObjectImpl) object).getLoadingState() != State.LOADED) {
    // print("{");
    // print("\"_i\":" + object.getOid() + ",");
    // print("\"_t\":\"" + object.eClass().getName() + "\",");
    // print("\"_s\":0");
    // print("}\n");
    // } else {
    print("{");
    print("\"_i\":" + object.getOid() + ",");
    print("\"_t\":\"" + object.eClass().getName() + "\",");
    print("\"_s\":1");
    for (EStructuralFeature eStructuralFeature : object.eClass().getEAllStructuralFeatures()) {
        if (eStructuralFeature.getEAnnotation("nolazyload") == null && (eStructuralFeature.getEAnnotation("hidden") == null || includeHidden)) {
            if (eStructuralFeature instanceof EReference) {
                Object value = object.eGet(eStructuralFeature);
                if (value != null) {
                    if (eStructuralFeature.isMany()) {
                        List<?> list = (List<?>) value;
                        if (SERIALIZE_EMPTY_LISTS || !list.isEmpty()) {
                            print(",");
                            int wrapped = 0;
                            int referred = 0;
                            for (Object o : list) {
                                if (o instanceof Long) {
                                    referred++;
                                } else if (o instanceof HashMapWrappedVirtualObject) {
                                    wrapped++;
                                }
                            }
                            if (wrapped == 0 && referred != 0) {
                                print("\"_r" + eStructuralFeature.getName() + "\":[");
                            } else if (wrapped != 0 && referred == 0) {
                                print("\"_e" + eStructuralFeature.getName() + "\":[");
                            } else if (wrapped == 0 && referred == 0) {
                                print("\"_e" + eStructuralFeature.getName() + "\":[");
                            // should not happen
                            } else {
                                // both, this can occur,
                                // for example
                                // IfcTrimmedCurve.Trim1
                                print("\"_e" + eStructuralFeature.getName() + "\":[");
                            }
                            boolean f = true;
                            for (Object o : list) {
                                if (o == null) {
                                    LOGGER.info("Unexpeced null in list " + object.eClass().getName() + ":" + object.getOid() + "." + eStructuralFeature.getName());
                                } else {
                                    if (!f) {
                                        print(",");
                                    } else {
                                        f = false;
                                    }
                                    if (o instanceof Long) {
                                        long ref = (Long) o;
                                        if (wrapped != 0 && referred != 0) {
                                            // Special
                                            // situation,
                                            // where we have
                                            // to construct
                                            // an object
                                            // around the
                                            // OID to make
                                            // it
                                            // distinguishable
                                            // from embedded
                                            // objects
                                            print("{");
                                            print("\"_i\":");
                                            print("" + ref + ",");
                                            print("\"_t\":");
                                            print("\"" + object.getReusable().getDatabaseInterface().getEClassForOid(ref).getName() + "\"");
                                            print("}");
                                        } else {
                                            print("{");
                                            print("\"_i\":");
                                            print("" + ref + ",");
                                            print("\"_t\":");
                                            print("\"" + object.getReusable().getDatabaseInterface().getEClassForOid(ref).getName() + "\"");
                                            print("}");
                                        }
                                    } else if (o instanceof HashMapWrappedVirtualObject) {
                                        write((HashMapWrappedVirtualObject) o);
                                    } else if (eStructuralFeature.getEAnnotation("twodimensionalarray") != null) {
                                        EClass type = (EClass) eStructuralFeature.getEType();
                                        EStructuralFeature listFeature = type.getEStructuralFeature("List");
                                        List<?> listX = (List<?>) (((HashMapVirtualObject) o).eGet(listFeature));
                                        print("[");
                                        boolean fq = true;
                                        for (Object k : listX) {
                                            if (!fq) {
                                                print(",");
                                            }
                                            fq = false;
                                            if (k instanceof HashMapWrappedVirtualObject) {
                                                write((HashMapWrappedVirtualObject) k);
                                            } else {
                                                print("\"" + k + "\"");
                                            }
                                        }
                                        print("]");
                                    } else {
                                        LOGGER.info("Unimplemented " + o);
                                    }
                                }
                            }
                            print("]");
                        }
                    } else {
                        print(",");
                        if (value instanceof Long) {
                            long ref = (Long) value;
                            print("\"_r" + eStructuralFeature.getName() + "\":{\"_i\":" + ref + ",\"_t\":\"" + object.getReusable().getDatabaseInterface().getEClassForOid(ref).getName() + "\"}");
                        } else if (value instanceof HashMapWrappedVirtualObject) {
                            print("\"_e" + eStructuralFeature.getName() + "\":");
                            HashMapWrappedVirtualObject hashMapWrappedVirtualObject = (HashMapWrappedVirtualObject) value;
                            write(hashMapWrappedVirtualObject);
                        } else {
                        // print("\"" + eStructuralFeature.getName() + "\":");
                        // writePrimitive(eStructuralFeature, ((IfcGloballyUniqueId) ref).getWrappedValue());
                        }
                    }
                }
            } else {
                Object value = object.eGet(eStructuralFeature);
                if (value != null) {
                    if (eStructuralFeature.isMany()) {
                        List<?> list = (List<?>) value;
                        if (SERIALIZE_EMPTY_LISTS || !list.isEmpty()) {
                            print(",");
                            print("\"" + eStructuralFeature.getName() + "\":[");
                            boolean f = true;
                            for (Object o : list) {
                                if (!f) {
                                    print(",");
                                } else {
                                    f = false;
                                }
                                writePrimitive(eStructuralFeature, o);
                            }
                            print("]");
                        }
                    } else {
                        print(",");
                        print("\"" + eStructuralFeature.getName() + "\":");
                        writePrimitive(eStructuralFeature, value);
                    }
                }
            }
        }
    }
    print("}\n");
// }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) MinimalVirtualObject(org.bimserver.shared.MinimalVirtualObject) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 10 with EReference

use of org.eclipse.emf.ecore.EReference in project BIMserver by opensourceBIM.

the class Include method addFieldDirect.

public void addFieldDirect(String fieldName) throws QueryException {
    EReference feature = null;
    for (TypeDef typeDef : types) {
        if (typeDef.geteClass().getEStructuralFeature(fieldName) == null) {
            throw new QueryException("Class \"" + typeDef.geteClass().getName() + "\" does not have the field \"" + fieldName + "\"");
        }
        if (feature == null) {
            if (!(typeDef.geteClass().getEStructuralFeature(fieldName) instanceof EReference)) {
                throw new QueryException(fieldName + " is not a reference");
            }
            feature = (EReference) typeDef.geteClass().getEStructuralFeature(fieldName);
        } else {
            if (feature != typeDef.geteClass().getEStructuralFeature(fieldName)) {
                throw new QueryException("Classes \"" + typeDef.geteClass().getName() + "\" and \"" + feature.getEContainingClass().getName() + "\" have fields with the same name, but they are not logically the same");
            }
        }
    }
    if (fieldsDirect == null) {
        fieldsDirect = new ArrayList<>();
    }
    fieldsDirect.add(feature);
}
Also used : EReference(org.eclipse.emf.ecore.EReference)

Aggregations

EReference (org.eclipse.emf.ecore.EReference)229 EObject (org.eclipse.emf.ecore.EObject)118 EClass (org.eclipse.emf.ecore.EClass)58 List (java.util.List)52 ArrayList (java.util.ArrayList)48 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)37 Test (org.junit.Test)31 EAttribute (org.eclipse.emf.ecore.EAttribute)29 PalladioSelectEObjectDialog (org.palladiosimulator.editors.commons.dialogs.selection.PalladioSelectEObjectDialog)28 EClassifier (org.eclipse.emf.ecore.EClassifier)21 Resource (org.eclipse.emf.ecore.resource.Resource)21 IdEObject (org.bimserver.emf.IdEObject)18 EList (org.eclipse.emf.common.util.EList)17 IScope (org.eclipse.xtext.scoping.IScope)15 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)14 InternalEObject (org.eclipse.emf.ecore.InternalEObject)14 URI (org.eclipse.emf.common.util.URI)13 EPackage (org.eclipse.emf.ecore.EPackage)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)10 CrossReference (org.eclipse.xtext.CrossReference)10