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;
}
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();
}
}
}
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;
}
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;
}
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);
}
Aggregations