Search in sources :

Example 11 with EReference

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

the class ReferenceCounter method removeInternal.

@SuppressWarnings("rawtypes")
public int removeInternal(IdEObject idEObject) {
    int totalRemoved = 1;
    for (EReference eReference : idEObject.eClass().getEAllReferences()) {
        if (eReference.isMany()) {
            List list = (List) idEObject.eGet(eReference);
            for (Object o : list) {
                IdEObject refObject = (IdEObject) o;
                references.get(refObject).remove(idEObject);
                if (references.get(refObject).size() == 0) {
                    totalRemoved += removeInternal(refObject);
                }
            }
        } else {
            IdEObject refObject = (IdEObject) idEObject.eGet(eReference);
            if (references.containsKey(refObject)) {
                references.get(refObject).remove(idEObject);
                if (references.get(refObject).size() == 0) {
                    totalRemoved += removeInternal(refObject);
                }
            }
        }
    }
    return totalRemoved;
}
Also used : IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) AbstractEList(org.eclipse.emf.common.util.AbstractEList) IdEObject(org.bimserver.emf.IdEObject) EReference(org.eclipse.emf.ecore.EReference)

Example 12 with EReference

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

the class IfcPrinter method printMap.

@SuppressWarnings("unchecked")
public void printMap(Map<Long, EObject> map) {
    for (Long key : map.keySet()) {
        EObject object = map.get(key);
        System.out.println("#" + key + " " + object.eClass().getName());
        for (EAttribute attribute : object.eClass().getEAllAttributes()) {
            System.out.println("\t" + attribute.getName() + "(" + attribute.getEType().getName() + "): " + object.eGet(attribute));
        }
        for (EReference reference : object.eClass().getEAllReferences()) {
            System.out.println("\t" + reference.getName() + "(" + reference.getEReferenceType().getName() + "): ");
            if (object.eGet(reference) instanceof EObjectResolvingEList) {
                EObjectResolvingEList<EObject> referencedObjectList = (EObjectResolvingEList<EObject>) object.eGet(reference);
                if (referencedObjectList != null && referencedObjectList.size() > 0) {
                    if (reference.getEReferenceType().getEStructuralFeature("wrappedValue") != null) {
                        for (Object obj : referencedObjectList) {
                            Object wrappedValue = ((EObject) obj).eGet(reference.getEReferenceType().getEStructuralFeature("wrappedValue"));
                            System.out.println(wrappedValue.toString());
                            if (referencedObjectList.get(referencedObjectList.size() - 1) != obj) {
                                System.out.println();
                                System.out.println("\t" + reference.getName() + "(" + reference.getEReferenceType().getName() + "): ");
                            }
                        }
                    } else {
                        for (Object obj : referencedObjectList) {
                            if (obj != null) {
                                System.out.println("=> ");
                            }
                        }
                    }
                }
            } else if (reference.getEReferenceType().getEStructuralFeature("wrappedValue") != null) {
            // EObject object2 = (EObject)object.eGet(reference);
            // if (object2 != null) {
            // Object wrappedValue = object2.eGet(reference.getEReferenceType().getEStructuralFeature("wrappedValue"));
            // Logger.log(wrappedValue);
            // }
            } else {
                if (object.eGet(reference) != null) {
                    System.out.println("=>");
                } else {
                    System.out.println("null");
                }
            }
            System.out.println();
        }
    }
}
Also used : EAttribute(org.eclipse.emf.ecore.EAttribute) EObjectResolvingEList(org.eclipse.emf.ecore.util.EObjectResolvingEList) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference)

Example 13 with EReference

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

the class HashMapVirtualObject method getExactSize.

private int getExactSize(VirtualObject virtualObject) {
    int size = 0;
    int lastSize = 0;
    for (EStructuralFeature eStructuralFeature : eClass().getEAllStructuralFeatures()) {
        if (getPackageMetaData().useForDatabaseStorage(eClass, eStructuralFeature)) {
            if (!useUnsetBit(eStructuralFeature)) {
                Object val = eGet(eStructuralFeature);
                if (eStructuralFeature instanceof EAttribute) {
                    EAttribute eAttribute = (EAttribute) eStructuralFeature;
                    if (eAttribute.isMany()) {
                        size += 4;
                        for (Object v : ((List<?>) val)) {
                            size += getPrimitiveSize(eAttribute.getEAttributeType(), v);
                        }
                    } else {
                        size += getPrimitiveSize(eAttribute.getEAttributeType(), val);
                    }
                } else if (eStructuralFeature instanceof EReference) {
                    EReference eReference = (EReference) eStructuralFeature;
                    if (eReference.isMany()) {
                        size += 4;
                        for (Object v : ((List<?>) val)) {
                            size += getWrappedValueSize(v, eReference);
                        }
                    } else {
                        size += getWrappedValueSize(val, eReference);
                    }
                }
                lastSize = size;
            }
        }
    }
    size += getPackageMetaData().getUnsettedLength(eClass);
    return size;
}
Also used : EAttribute(org.eclipse.emf.ecore.EAttribute) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ArrayList(java.util.ArrayList) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 14 with EReference

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

the class StructureAnalyzer method printClassifier.

@SuppressWarnings("unchecked")
private int printClassifier(String name, EClassifier classifier, ArrayList<EClassifier> referrers, int indention) {
    out2.println(StringUtils.fill("", indention, "\t") + name + ": " + classifier.getName());
    if (count > limit) {
        return -1;
    }
    count++;
    if (classifier instanceof EClass) {
        EClass eClass = (EClass) classifier;
        int references = 0;
        for (EReference reference : eClass.getEAllReferences()) {
            String name2 = reference.getName();
            if (name2.equals("ProvidesBoundaries") || name2.equals("ContainedInStructure") || name2.equals("FillsVoids") || name2.equals("IsDecomposedBy") || name2.equals("Decomposes") || name2.equals("RelatedObjects") || name2.equals("IsDefinedBy") || name2.equals("ReferencedBy") || name2.equals("HasAssociations") || name2.equals("HasAssignments") || name2.equals("ReferencedByPlacements") || name2.equals("ConnectedTo") || name2.equals("HasCoverings") || name2.equals("HasProjections") || name2.equals("HasStructuralMember") || name2.equals("ReferencedInStructures") || name2.equals("VoidsElements") || name2.equals("ConnectedFrom")) {
            } else {
                boolean go = true;
                for (EClassifier referrer : referrers) {
                    if (referrer == reference.getEType()) {
                        go = false;
                    }
                }
                if (go) {
                    if (((EClass) reference.getEType()).getEStructuralFeature("wrappedValue") == null) {
                        references++;
                        ArrayList<EClassifier> newList = (ArrayList<EClassifier>) referrers.clone();
                        newList.add(classifier);
                        int newReferences = printClassifier(name2, reference.getEType(), newList, indention + 1);
                        if (newReferences != -1) {
                            references += newReferences;
                        } else {
                            return -1;
                        }
                    }
                }
            }
        }
        return references;
    }
    return 0;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ArrayList(java.util.ArrayList) EClassifier(org.eclipse.emf.ecore.EClassifier) EReference(org.eclipse.emf.ecore.EReference)

Example 15 with EReference

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

the class Express2EMF method addInverseAttribute.

private void addInverseAttribute(Attribute attrib, EClass cls) {
    InverseAttribute inverseAttribute = (InverseAttribute) attrib;
    EReference eRef = eFactory.createEReference();
    // Inverses are always optional?
    eRef.setUnsettable(true);
    eRef.getEAnnotations().add(createInverseAnnotation());
    eRef.setName(attrib.getName());
    if (inverseAttribute.getMax_cardinality() != null) {
        IntegerBound max_cardinality = (IntegerBound) inverseAttribute.getMax_cardinality();
        if (max_cardinality.getBound_value() == -1) {
            eRef.setUpperBound(max_cardinality.getBound_value());
        } else {
            eRef.setUpperBound(max_cardinality.getBound_value() + 1);
        }
    }
    String type = (inverseAttribute).getDomain().getName();
    EClass classifier = (EClass) schemaPack.getEClassifier(type);
    eRef.setEType(classifier);
    String reverseName = inverseAttribute.getInverted_attr().getName();
    EReference reference = (EReference) classifier.getEStructuralFeature(reverseName);
    reference.getEAnnotations().add(createInverseAnnotation());
    if (eRef.getEType() == classifier && reference.getEType() == cls) {
        if (eRef.isMany()) {
            eRef.setUnique(true);
        }
        if (reference.isMany()) {
            reference.setUnique(true);
        }
        reference.setEOpposite(eRef);
        eRef.setEOpposite(reference);
    } else {
        System.out.println("Inverse mismatch");
        System.out.println(classifier.getName() + "." + reference.getName() + " => " + cls.getName() + "." + eRef.getName());
    }
    cls.getEStructuralFeatures().add(eRef);
}
Also used : IntegerBound(nl.tue.buildingsmart.schema.IntegerBound) EClass(org.eclipse.emf.ecore.EClass) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute) 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