use of org.eclipse.emf.ecore.EClassifier in project BIMserver by opensourceBIM.
the class HashMapVirtualObject method writePrimitiveValue.
private void writePrimitiveValue(EStructuralFeature feature, Object value, ByteBuffer buffer) throws BimserverDatabaseException {
EClassifier type = feature.getEType();
if (type == EcorePackage.eINSTANCE.getEString()) {
if (value == null) {
buffer.putInt(-1);
} else {
String stringValue = (String) value;
byte[] bytes = stringValue.getBytes(Charsets.UTF_8);
if (bytes.length > Integer.MAX_VALUE) {
throw new BimserverDatabaseException("String value too long (max length is " + Integer.MAX_VALUE + ")");
}
buffer.putInt(bytes.length);
buffer.put(bytes);
}
} else if (type == EcorePackage.eINSTANCE.getEInt() || type == EcorePackage.eINSTANCE.getEIntegerObject()) {
if (value == null) {
buffer.putInt(0);
} else {
buffer.putInt((Integer) value);
}
} else if (type == EcorePackage.eINSTANCE.getEDouble() || type == EcorePackage.eINSTANCE.getEDoubleObject()) {
if (value == null) {
buffer.putDouble(0D);
} else {
buffer.putDouble((Double) value);
}
} else if (type == EcorePackage.eINSTANCE.getEFloat() || type == EcorePackage.eINSTANCE.getEFloatObject()) {
if (value == null) {
buffer.putFloat(0F);
} else {
buffer.putFloat((Float) value);
}
} else if (type == EcorePackage.eINSTANCE.getELong() || type == EcorePackage.eINSTANCE.getELongObject()) {
if (value == null) {
buffer.putLong(0L);
} else {
buffer.putLong((Long) value);
}
} else if (type == EcorePackage.eINSTANCE.getEBoolean() || type == EcorePackage.eINSTANCE.getEBooleanObject()) {
if (value == null) {
buffer.put((byte) 0);
} else {
buffer.put(((Boolean) value) ? (byte) 1 : (byte) 0);
}
} else if (type == EcorePackage.eINSTANCE.getEDate()) {
if (value == null) {
buffer.putLong(-1L);
} else {
buffer.putLong(((Date) value).getTime());
}
} else if (type.getName().equals("Tristate")) {
if (value == null) {
buffer.putInt(Tristate.UNDEFINED.getValue());
} else {
Enumerator eEnumLiteral = (Enumerator) value;
buffer.putInt(eEnumLiteral.getValue());
}
} else if (value instanceof Enumerator) {
Enumerator eEnumLiteral = (Enumerator) value;
buffer.putInt(eEnumLiteral.getValue());
} else if (type == EcorePackage.eINSTANCE.getEByteArray()) {
if (value == null) {
buffer.putInt(0);
} else {
byte[] bytes = (byte[]) value;
buffer.putInt(bytes.length);
buffer.put(bytes);
}
} else {
throw new RuntimeException("Unsupported type " + type.getName());
}
}
use of org.eclipse.emf.ecore.EClassifier in project BIMserver by opensourceBIM.
the class XSDSchemaReader method createGroup.
private void createGroup(XSModelGroupDecl modelGroupDecl) {
EClass eClass = ecoreFactory.createEClass();
eClass.setName(modelGroupDecl.getName());
ePackage.getEClassifiers().add(eClass);
for (XSParticle particle : modelGroupDecl.getModelGroup().getChildren()) {
XSTerm term = particle.getTerm();
if (term.isElementDecl()) {
String name = term.asElementDecl().getName();
EClassifier subClass = ePackage.getEClassifier(name);
if (subClass != null && subClass instanceof EClass) {
((EClass) subClass).getESuperTypes().add(eClass);
}
}
}
}
use of org.eclipse.emf.ecore.EClassifier 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.EClassifier in project BIMserver by opensourceBIM.
the class StructureAnalyzer method start.
private void start() {
limit = 1000000;
try {
out = new PrintWriter(Paths.get("structure.txt").toFile());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int i = 0;
// Ifc2x3tc1Package einstance = Ifc2x3tc1Package.eINSTANCE;
// System.out.println(printClassifier("root", Ifc2x3tc1Package.eINSTANCE.getEClassifier("IfcWall"), new ArrayList<EClassifier>(), 0));
// EList<EClassifier> classifiers = Ifc2x3tc1Package.eINSTANCE.getEClassifiers();
EList<EClassifier> classifiers = new BasicEList<EClassifier>();
classifiers.add(Ifc2x3tc1Package.eINSTANCE.getEClassifier("IfcWall"));
for (EClassifier ecl : classifiers) {
try {
out2 = new PrintWriter(Paths.get("structure/" + ecl.getName() + ".txt").toFile());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
count = 0;
int printClassifier = printClassifier("root", ecl, new ArrayList<EClassifier>(), 0);
if (printClassifier == -1) {
out2.println("TERMINATED AFTER " + limit + " REFERENCES");
}
String string = i + "\t" + printClassifier + "\t" + ecl.getName();
System.out.println(string);
out.println(string);
out.flush();
out2.close();
i++;
}
out.close();
}
use of org.eclipse.emf.ecore.EClassifier in project BIMserver by opensourceBIM.
the class Express2EMF method addHackedTypes.
private void addHackedTypes() {
Iterator<DefinedType> typeIter = schema.getTypes().iterator();
while (typeIter.hasNext()) {
DefinedType type = typeIter.next();
if (type.getName().equals("IfcCompoundPlaneAngleMeasure")) {
// IfcCompoundPlaneAngleMeasure is a type of LIST [3..4] OF INTEGER (http://www.steptools.com/support/stdev_docs/express/ifc2x3/html/t_ifcco-03.html)
// We model this by using a wrapper class
// EClass ifcCompoundPlaneAngleMeasure = getOrCreateEClass(type.getName());
// DefinedType integerType = new DefinedType("Integer");
// integerType.setDomain(new IntegerType());
// EAttribute attribute = modifySimpleType(integerType, ifcCompoundPlaneAngleMeasure);
// attribute.setUpperBound(4);
// ifcCompoundPlaneAngleMeasure.getEAnnotations().add(createWrappedAnnotation());
} else if (type.getName().equals("IfcComplexNumber")) {
// IfcComplexNumber is a type of ARRAY [1..2] OF REAL (http://www.steptools.com/support/stdev_docs/express/ifc2x3/html/t_ifcco-07.html)
// We model this by using a wrapper class
EClass ifcComplexNumber = getOrCreateEClass(type.getName());
DefinedType realType = new DefinedType("Real");
realType.setDomain(new RealType());
EAttribute attribute = modifySimpleType(realType, ifcComplexNumber);
ifcComplexNumber.getEStructuralFeature("wrappedValueAsString").setUpperBound(2);
attribute.setUpperBound(2);
ifcComplexNumber.getEAnnotations().add(createWrappedAnnotation());
} else if (type.getName().equals("IfcNullStyle")) {
// IfcNullStyle is a type of ENUMERATION OF NULL (http://www.steptools.com/support/stdev_docs/express/ifc2x3/html/t_ifcnu-02.html)
// We cannot simply make this an enum because it is defined as a subtype(select) of IfcPresentationStyleSelect, so we use a wrapper here, both the wrapper and
EClassifier ifcNullStyleEnum = schemaPack.getEClassifier("IfcNullStyle");
ifcNullStyleEnum.setName("IfcNullStyleEnum");
EClass ifcNullStyleWrapper = getOrCreateEClass(type.getName());
EAttribute wrappedValue = eFactory.createEAttribute();
wrappedValue.setName("wrappedValue");
wrappedValue.setEType(ifcNullStyleEnum);
ifcNullStyleWrapper.getEAnnotations().add(createWrappedAnnotation());
ifcNullStyleWrapper.getEStructuralFeatures().add(wrappedValue);
}
}
}
Aggregations