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