use of org.eclipse.emf.ecore.EClassifier in project BIMserver by opensourceBIM.
the class Express2EMF method addDerivedTypes.
/**
* constructs the EXPRESS TYPEs like IfcPositiveLength measure that are not
* simple types but derived types: <code>
* TYPE IfcPositiveLengthMeasure = IfcLengthMeasure;
* WHERE
* WR1 : SELF > 0.;
* END_TYPE;
* </code>
*/
private void addDerivedTypes() {
Iterator<DefinedType> typeIter = schema.getTypes().iterator();
while (typeIter.hasNext()) {
DefinedType type = typeIter.next();
/*
* one of the hard things TODO : TYPE IfcCompoundPlaneAngleMeasure =
* LIST [3:3] OF INTEGER; WHERE WR1 : { -360 <= SELF[1] < 360 }; WR2
* : { -60 <= SELF[2] < 60 }; WR3 : { -60 <= SELF[3] < 60 }; WR4 :
* ((SELF[1] >= 0) AND (SELF[2] >= 0) AND (SELF[3] >= 0)) OR
* ((SELF[1] <= 0) AND (SELF[2] <= 0) AND (SELF[3] <= 0)); END_TYPE;
*
* I am skipping this for now, it only occurs once in the model
* future versions should definitely find an answer to this
*
* A fix for this has been implemented in addHackedTypes
*/
if (type.getName().equalsIgnoreCase("IfcCompoundPlaneAngleMeasure")) {
EClass testType = getOrCreateEClass(type.getName());
DefinedType type2 = new DefinedType("Integer");
type2.setDomain(new IntegerType());
modifySimpleType(type2, testType);
testType.getEAnnotations().add(createWrappedAnnotation());
} else if (type.getDomain() instanceof DefinedType) {
if (schemaPack.getEClassifier(type.getName()) != null) {
EClass testType = (EClass) schemaPack.getEClassifier(type.getName());
DefinedType domain = (DefinedType) type.getDomain();
EClassifier classifier = schemaPack.getEClassifier(domain.getName());
testType.getESuperTypes().add((EClass) classifier);
testType.setInstanceClass(classifier.getInstanceClass());
} else {
EClass testType = getOrCreateEClass(type.getName());
DefinedType domain = (DefinedType) type.getDomain();
if (simpleTypeReplacementMap.containsKey(domain.getName())) {
// We can't subclass because it's a 'primitive' type
simpleTypeReplacementMap.put(type.getName(), simpleTypeReplacementMap.get(domain.getName()));
} else {
EClass classifier = getOrCreateEClass(domain.getName());
testType.getESuperTypes().add((EClass) classifier);
if (classifier.getEAnnotation("wrapped") != null) {
testType.getEAnnotations().add(createWrappedAnnotation());
}
testType.setInstanceClass(classifier.getInstanceClass());
}
}
}
}
}
use of org.eclipse.emf.ecore.EClassifier in project BIMserver by opensourceBIM.
the class Express2EMF method doRealDerivedAttributes.
private void doRealDerivedAttributes() {
for (EntityDefinition entityDefinition : schema.getEntities()) {
for (DerivedAttribute2 attributeName : entityDefinition.getDerivedAttributes().values()) {
EClass eClass = (EClass) schemaPack.getEClassifier(entityDefinition.getName());
// eFactory.createEReference();
if (attributeName.getType() != null && !attributeName.hasSuper()) {
// derivedAttribute.setEType(schemaPack.getEClassifier("IfcLogical"));
if (attributeName.getType() instanceof DefinedType) {
EClassifier eType = schemaPack.getEClassifier(((DefinedType) attributeName.getType()).getName());
boolean found = false;
for (EClass eSuperType : eClass.getEAllSuperTypes()) {
if (eSuperType.getEStructuralFeature(attributeName.getName()) != null) {
found = true;
break;
}
}
if (eType.getEAnnotation("wrapped") != null) {
if (!found) {
EAttribute eAttribute = eFactory.createEAttribute();
eAttribute.setDerived(true);
eAttribute.setName(attributeName.getName());
if (eAttribute.getName().equals("RefLatitude") || eAttribute.getName().equals("RefLongitude")) {
eAttribute.setUpperBound(3);
eAttribute.setUnique(false);
}
EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType();
eAttribute.setEType(type);
// TODO find out
eAttribute.setUnsettable(true);
// if its
// optional
eClass.getEStructuralFeatures().add(eAttribute);
if (type == EcorePackage.eINSTANCE.getEDouble()) {
EAttribute doubleStringAttribute = eFactory.createEAttribute();
doubleStringAttribute.setName(attributeName.getName() + "AsString");
doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
// TODO
doubleStringAttribute.setUnsettable(true);
// find
// out
// if
// its
// optional
doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
eClass.getEStructuralFeatures().add(doubleStringAttribute);
}
}
} else {
if (!found) {
EReference eReference = eFactory.createEReference();
eReference.setName(attributeName.getName());
eReference.setDerived(true);
eReference.setUnsettable(true);
eReference.setEType(eType);
eClass.getEStructuralFeatures().add(eReference);
}
}
// derivedAttribute.setEType(eType);
}
}
// derivedAttribute.setName(attributeName.getName());
// derivedAttribute.setDerived(true);
// derivedAttribute.setTransient(true);
// derivedAttribute.setVolatile(true);
// if (attributeName.isCollection()) {
// derivedAttribute.setUpperBound(-1);
// }
// EAnnotation annotation = eFactory.createEAnnotation();
// annotation.setSource("http://www.iso.org/iso10303-11/EXPRESS");
// annotation.getDetails().put("code",
// attributeName.getExpressCode());
// derivedAttribute.getEAnnotations().add(annotation);
// if (eClass.getEStructuralFeature(derivedAttribute.getName())
// == null) {
// eClass.getEStructuralFeatures().add(derivedAttribute);
// }
}
}
}
use of org.eclipse.emf.ecore.EClassifier in project BIMserver by opensourceBIM.
the class Express2EMF method getOrCreateEClass.
private EClass getOrCreateEClass(String name) {
EClassifier eClassifier = schemaPack.getEClassifier(name);
if (eClassifier == null) {
eClassifier = eFactory.createEClass();
eClassifier.setName(name);
schemaPack.getEClassifiers().add(eClassifier);
}
return (EClass) eClassifier;
}
use of org.eclipse.emf.ecore.EClassifier in project BIMserver by opensourceBIM.
the class Express2EMF method addTwoDimensionalArray.
private void addTwoDimensionalArray(String entityName, String attribName) {
EClassifier finalType = null;
if (entityName.equals("IfcBSplineSurface") && attribName.equals("ControlPointsList")) {
finalType = schemaPack.getEClassifier("IfcCartesianPoint");
} else if (entityName.equals("IfcCartesianPointList3D") && attribName.equals("CoordList")) {
finalType = schemaPack.getEClassifier("IfcLengthMeasure");
} else if (entityName.equals("IfcColourRgbList") && attribName.equals("ColourList")) {
finalType = schemaPack.getEClassifier("IfcNormalisedRatioMeasure");
} else if (entityName.equals("IfcIndexedTriangleTextureMap") && attribName.equals("TexCoordIndex")) {
finalType = EcorePackage.eINSTANCE.getELong();
} else if (entityName.equals("IfcRationalBSplineSurfaceWithKnots") && attribName.equals("WeightsData")) {
finalType = EcorePackage.eINSTANCE.getEDouble();
} else if (entityName.equals("IfcStructuralLoadConfiguration") && attribName.equals("Locations")) {
finalType = schemaPack.getEClassifier("IfcLengthMeasure");
} else if (entityName.equals("IfcTessellatedFaceSet") && attribName.equals("Normals")) {
finalType = schemaPack.getEClassifier("IfcParameterValue");
} else if (entityName.equals("IfcTextureVertexList") && attribName.equals("TexCoordsList")) {
finalType = schemaPack.getEClassifier("IfcParameterValue");
} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("CoordIndex")) {
finalType = EcorePackage.eINSTANCE.getELong();
} else if (entityName.equals("IfcCartesianPointList2D") && attribName.equals("CoordList")) {
finalType = schemaPack.getEClassifier("IfcCartesianPoint");
} else if (entityName.equals("IfcIndexedPolygonalFaceWithVoids") && attribName.equals("InnerCoordIndices")) {
finalType = EcorePackage.eINSTANCE.getELong();
} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("Normals")) {
finalType = schemaPack.getEClassifier("IfcParameterValue");
} else if (entityName.equals("IfcTriangulatedFaceSet") && attribName.equals("NormalIndex")) {
finalType = EcorePackage.eINSTANCE.getELong();
} else {
throw new RuntimeException("Unimplemented " + entityName + "." + attribName);
}
EClass containerClass = (EClass) schemaPack.getEClassifier("ListOf" + finalType.getName());
if (containerClass == null) {
containerClass = EcoreFactory.eINSTANCE.createEClass();
containerClass.setName("ListOf" + finalType.getName());
if (finalType.getEPackage() == EcorePackage.eINSTANCE) {
EAttribute finalAttribute = EcoreFactory.eINSTANCE.createEAttribute();
finalAttribute.setName("List");
finalAttribute.setEType(finalType);
finalAttribute.setUpperBound(-1);
containerClass.getEAttributes().add(finalAttribute);
} else {
EReference finalReference = EcoreFactory.eINSTANCE.createEReference();
finalReference.setName("List");
finalReference.setEType(finalType);
finalReference.setUpperBound(-1);
containerClass.getEReferences().add(finalReference);
}
schemaPack.getEClassifiers().add(containerClass);
}
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.getEAnnotations().add(createTwoDimensionalArrayAnnotation());
eReference.setName(attribName);
eReference.setUpperBound(-1);
eReference.setEType(containerClass);
EClass cls = (EClass) schemaPack.getEClassifier(entityName);
cls.getEStructuralFeatures().add(eReference);
}
use of org.eclipse.emf.ecore.EClassifier in project BIMserver by opensourceBIM.
the class DataObjectGeneratorWrapper method generateDataObjects.
public void generateDataObjects(Set<EPackage> ePackages) {
try {
FileUtils.forceMkdir(packageFolder);
} catch (IOException e) {
LOGGER.error("", e);
}
ServiceInterfaceObjectGenerator dataObjectGenerator = new ServiceInterfaceObjectGenerator();
Set<String> fileNamesCreated = new HashSet<String>();
for (EPackage ePackage : ePackages) {
for (EClassifier eClassifier : ePackage.getEClassifiers()) {
if (eClassifier instanceof EClass || eClassifier instanceof EEnum) {
Object[] arguments = new Object[] { eClassifier, new ImportManager(), metaDataManager };
String generated = dataObjectGenerator.generate(arguments);
String fileName = "S" + eClassifier.getName() + ".java";
fileNamesCreated.add(fileName);
File file = new File(packageFolder, fileName);
try {
OutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(generated.getBytes(Charsets.UTF_8));
fileOutputStream.close();
} catch (FileNotFoundException e) {
LOGGER.error("", e);
} catch (UnsupportedEncodingException e) {
LOGGER.error("", e);
} catch (IOException e) {
LOGGER.error("", e);
}
}
}
}
for (File file : packageFolder.listFiles()) {
if (!fileNamesCreated.contains(file.getName())) {
file.delete();
}
}
}
Aggregations