Search in sources :

Example 1 with EEnumLiteral

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

the class PackageMetaData method getEEnumLiteral.

public EEnumLiteral getEEnumLiteral(String enumName, String literalName) {
    EClassifier eClassifier = ePackage.getEClassifier(enumName);
    if (eClassifier == null) {
        throw new RuntimeException("Classifier " + enumName + " not found in package " + ePackage.getName());
    }
    if (eClassifier instanceof EEnum) {
        EEnum eEnum = (EEnum) eClassifier;
        EEnumLiteral literal = eEnum.getEEnumLiteral(literalName);
        if (literal == null) {
            throw new RuntimeException("No enum literal " + literalName + " found on " + ePackage.getName() + "." + enumName);
        }
        return literal;
    } else {
        throw new RuntimeException("Classifier " + enumName + " is not of type enum");
    }
}
Also used : EClassifier(org.eclipse.emf.ecore.EClassifier) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) EEnum(org.eclipse.emf.ecore.EEnum)

Example 2 with EEnumLiteral

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

the class Express2EMF method addEnumerations.

private void addEnumerations() {
    Iterator<DefinedType> typeIter = schema.getTypes().iterator();
    while (typeIter.hasNext()) {
        DefinedType type = typeIter.next();
        if (type instanceof EnumerationType) {
            EEnum enumeration = eFactory.createEEnum();
            enumeration.setName(type.getName());
            EEnumLiteral nullValue = eFactory.createEEnumLiteral();
            nullValue.setName("NULL");
            nullValue.setLiteral("NULL");
            nullValue.setValue(0);
            enumeration.getELiterals().add(nullValue);
            int counter = 1;
            Iterator<String> values = ((EnumerationType) type).getElements().iterator();
            while (values.hasNext()) {
                String stringVal = values.next();
                if (!stringVal.equals("NULL")) {
                    EEnumLiteral value = eFactory.createEEnumLiteral();
                    value.setName(stringVal);
                    value.setLiteral(stringVal);
                    value.setValue(counter);
                    counter++;
                    enumeration.getELiterals().add(value);
                }
            }
            schemaPack.getEClassifiers().add(enumeration);
        }
    }
}
Also used : EnumerationType(nl.tue.buildingsmart.schema.EnumerationType) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) DefinedType(nl.tue.buildingsmart.schema.DefinedType) EEnum(org.eclipse.emf.ecore.EEnum)

Example 3 with EEnumLiteral

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

the class Express2EMF method createTristate.

private void createTristate() {
    tristate = eFactory.createEEnum();
    tristate.setName("Tristate");
    EEnumLiteral trueLiteral = eFactory.createEEnumLiteral();
    trueLiteral.setName("TRUE");
    trueLiteral.setValue(0);
    EEnumLiteral falseLiteral = eFactory.createEEnumLiteral();
    falseLiteral.setName("FALSE");
    falseLiteral.setValue(1);
    EEnumLiteral undefinedLiteral = eFactory.createEEnumLiteral();
    undefinedLiteral.setName("UNDEFINED");
    undefinedLiteral.setValue(2);
    tristate.getELiterals().add(trueLiteral);
    tristate.getELiterals().add(falseLiteral);
    tristate.getELiterals().add(undefinedLiteral);
    schemaPack.getEClassifiers().add(tristate);
}
Also used : EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral)

Example 4 with EEnumLiteral

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

the class AbstractSchemaConverter method copy.

@SuppressWarnings("unchecked")
protected IdEObject copy(IdEObject original) throws IfcModelInterfaceException, ObjectAlreadyExistsException {
    if (!((IdEObjectImpl) original).isLoadedOrLoading()) {
        return null;
    }
    if (converted.containsKey(original)) {
        return converted.get(original);
    }
    if (original.eClass().getName().equals("GeometryInfo") || original.eClass().getName().equals("GeometryData") || original.eClass().getName().equals("Vector3f")) {
        return null;
    }
    EClass eClass = (EClass) target.getPackageMetaData().getEPackage().getEClassifier(original.eClass().getName());
    if (eClass == null) {
        LOGGER.info("No class " + original.eClass().getName() + " in " + target.getPackageMetaData().getEPackage().getName());
        return null;
    }
    IdEObject newObject = (IdEObject) eClass.getEPackage().getEFactoryInstance().create(eClass);
    ((IdEObjectImpl) newObject).setOid(original.getOid());
    converted.put(original, newObject);
    if (newObject.eClass().getEAnnotation("wrapped") == null) {
        target.add(newObject.getOid(), newObject);
    }
    for (EStructuralFeature eStructuralFeature : original.eClass().getEAllStructuralFeatures()) {
        EStructuralFeature targetFeature = newObject.eClass().getEStructuralFeature(eStructuralFeature.getName());
        if (targetFeature == null) {
            continue;
        }
        Object get = original.eGet(eStructuralFeature);
        if (eStructuralFeature instanceof EAttribute) {
            if (get instanceof Double) {
                EStructuralFeature doubleStringFeature = original.eClass().getEStructuralFeature("wrappedValueAsString");
                EStructuralFeature targetDoubleStringFeature = newObject.eClass().getEStructuralFeature("wrappedValueAsString");
                if (doubleStringFeature != null && targetDoubleStringFeature != null) {
                    Object doubleString = original.eGet(doubleStringFeature);
                    newObject.eSet(targetDoubleStringFeature, doubleString);
                } else {
                    newObject.eSet(targetFeature, get);
                }
            } else {
                if (eStructuralFeature.getEType() instanceof EEnum) {
                    EEnum targetEnum = (EEnum) targetFeature.getEType();
                    EEnumLiteral newLiteral = targetEnum.getEEnumLiteral(get.toString());
                    if (newLiteral != null) {
                        newObject.eSet(targetFeature, newLiteral.getInstance());
                    }
                } else {
                    if (targetFeature instanceof EAttribute) {
                        newObject.eSet(targetFeature, get);
                    }
                }
            }
        } else if (eStructuralFeature instanceof EReference) {
            if (get == null) {
            } else {
                if (eStructuralFeature.isMany()) {
                    EList<EObject> list = (EList<EObject>) get;
                    AbstractEList<EObject> toList = (AbstractEList<EObject>) newObject.eGet(targetFeature);
                    if (toList != null) {
                        for (Object o : list) {
                            IdEObject ref = (IdEObject) o;
                            if (targetFeature.getEType().isInstance(ref)) {
                                if (converted.containsKey(o)) {
                                    toList.addUnique(converted.get(o));
                                } else {
                                    IdEObject result = copy((IdEObject) o);
                                    if (result != null) {
                                        toList.addUnique(result);
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if (targetFeature.isMany()) {
                        LOGGER.info("Different multiplicity");
                    } else {
                        if (converted.containsKey(get)) {
                            newObject.eSet(targetFeature, converted.get(get));
                        } else {
                            newObject.eSet(targetFeature, copy((IdEObject) get));
                        }
                    }
                }
            }
        }
    }
    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) EEnum(org.eclipse.emf.ecore.EEnum) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) EList(org.eclipse.emf.common.util.EList) AbstractEList(org.eclipse.emf.common.util.AbstractEList) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) EReference(org.eclipse.emf.ecore.EReference)

Example 5 with EEnumLiteral

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

the class Schema method createEEnumLiteral.

public EEnumLiteral createEEnumLiteral(EEnum eEnum, String name, int value) {
    EEnumLiteral eEnumLiteral = EcoreFactory.eINSTANCE.createEEnumLiteral();
    eEnumLiteral.setValue(value);
    eEnum.getELiterals().add(eEnumLiteral);
    eEnumLiteral.setName(name);
    return eEnumLiteral;
}
Also used : EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral)

Aggregations

EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)35 EEnum (org.eclipse.emf.ecore.EEnum)22 EPackage (org.eclipse.emf.ecore.EPackage)10 Grammar (org.eclipse.xtext.Grammar)10 Test (org.junit.Test)9 EClass (org.eclipse.emf.ecore.EClass)8 EDataType (org.eclipse.emf.ecore.EDataType)6 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)6 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 EClassifier (org.eclipse.emf.ecore.EClassifier)4 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)4 IdEObject (org.bimserver.emf.IdEObject)3 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)3 EObject (org.eclipse.emf.ecore.EObject)3 DTDEnumGroupKind (org.eclipse.wst.dtd.core.internal.emf.DTDEnumGroupKind)3 DTDEnumerationType (org.eclipse.wst.dtd.core.internal.emf.DTDEnumerationType)3 EnumRule (org.eclipse.xtext.EnumRule)3 BufferOverflowException (java.nio.BufferOverflowException)2 BufferUnderflowException (java.nio.BufferUnderflowException)2