Search in sources :

Example 1 with AggregationType

use of nl.tue.buildingsmart.schema.AggregationType in project BIMserver by opensourceBIM.

the class Express2EMF method processAttribute.

private void processAttribute(EntityDefinition ent, Attribute attrib) {
    if (attrib.getName().equals("RasterCode")) {
        System.out.println();
    }
    ExplicitAttribute expAttrib = (ExplicitAttribute) attrib;
    BaseType domain = expAttrib.getDomain();
    if (ent.getName().equals("IfcRelConnectsPathElements") && (attrib.getName().equals("RelatingPriorities") || attrib.getName().equals("RelatedPriorities"))) {
        // HACK, express parser does not recognize LIST [0:?] OF NUMBER
        EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
        EAttribute eAttribute = eFactory.createEAttribute();
        eAttribute.setName(attrib.getName());
        eAttribute.setUpperBound(-1);
        eAttribute.setUnique(false);
        eAttribute.setEType(EcorePackage.eINSTANCE.getELong());
        eAttribute.setUnsettable(expAttrib.isOptional());
        cls.getEStructuralFeatures().add(eAttribute);
        return;
    }
    if (domain instanceof NamedType) {
        NamedType nt = (NamedType) domain;
        if (nt instanceof EnumerationType) {
            EAttribute enumAttrib = eFactory.createEAttribute();
            enumAttrib.setUnsettable(expAttrib.isOptional());
            enumAttrib.setName(attrib.getName());
            EClassifier eType = schemaPack.getEClassifier(nt.getName());
            enumAttrib.setEType(eType);
            EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
            cls.getEStructuralFeatures().add(enumAttrib);
        } else {
            EClass eType = (EClass) schemaPack.getEClassifier(nt.getName());
            EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
            // If the DEFINED type is already a wrapped value, we prefer not to use wrappedValue indirection
            boolean wrapped = superTypeIsWrapped(eType);
            if (wrapped) {
                EAttribute eAttribute = eFactory.createEAttribute();
                eAttribute.setUnsettable(expAttrib.isOptional());
                eAttribute.setName(attrib.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);
                cls.getEStructuralFeatures().add(eAttribute);
                if (type == EcorePackage.eINSTANCE.getEDouble()) {
                    EAttribute doubleStringAttribute = eFactory.createEAttribute();
                    doubleStringAttribute.setName(attrib.getName() + "AsString");
                    doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
                    doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
                    doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
                    doubleStringAttribute.setUnsettable(expAttrib.isOptional());
                    cls.getEStructuralFeatures().add(doubleStringAttribute);
                }
            } else {
                EReference eRef = eFactory.createEReference();
                eRef.setName(attrib.getName());
                // Hardcoded hack to fix multiplicity for
                // IfcSpatialStructureElement which references
                // RefLatitude and RefLongitude
                eRef.setUnsettable(expAttrib.isOptional());
                eRef.setEType(eType);
                cls.getEStructuralFeatures().add(eRef);
            }
        }
    } else if (domain instanceof AggregationType) {
        BaseType bt = ((AggregationType) domain).getElement_type();
        EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
        if (bt instanceof NamedType) {
            NamedType nt = (NamedType) bt;
            EClassifier eType = schemaPack.getEClassifier(nt.getName());
            if (superTypeIsWrapped((EClass) eType)) {
                EAttribute eAttribute = eFactory.createEAttribute();
                eAttribute.setName(attrib.getName());
                if (eAttribute.getName().equals("RefLatitude") || eAttribute.getName().equals("RefLongitude")) {
                    eAttribute.setUpperBound(3);
                } else {
                    eAttribute.setUpperBound(-1);
                }
                EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType();
                eAttribute.setEType(type);
                eAttribute.setUnsettable(expAttrib.isOptional());
                eAttribute.setUnique(false);
                cls.getEStructuralFeatures().add(eAttribute);
                if (type == EcorePackage.eINSTANCE.getEDouble()) {
                    EAttribute doubleStringAttribute = eFactory.createEAttribute();
                    doubleStringAttribute.setName(attrib.getName() + "AsString");
                    doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
                    doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
                    doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
                    doubleStringAttribute.setUpperBound(-1);
                    doubleStringAttribute.setUnsettable(expAttrib.isOptional());
                    doubleStringAttribute.setUpperBound(eAttribute.getUpperBound());
                    doubleStringAttribute.setUnique(false);
                    cls.getEStructuralFeatures().add(doubleStringAttribute);
                }
            } else if (eType == EcorePackage.eINSTANCE.getEDouble()) {
                EAttribute eAttribute = eFactory.createEAttribute();
                eAttribute.setName(attrib.getName());
                eAttribute.setUnsettable(expAttrib.isOptional());
                eAttribute.setUnique(false);
                eAttribute.setEType(EcorePackage.eINSTANCE.getEAttribute());
                cls.getEStructuralFeatures().add(eAttribute);
                EAttribute doubleStringAttribute = eFactory.createEAttribute();
                doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
                doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
                doubleStringAttribute.setName(attrib.getName() + "AsString");
                doubleStringAttribute.setUpperBound(-1);
                doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
                doubleStringAttribute.setUnsettable(expAttrib.isOptional());
                doubleStringAttribute.setUpperBound(eAttribute.getUpperBound());
                doubleStringAttribute.setUnique(false);
                cls.getEStructuralFeatures().add(doubleStringAttribute);
            } else {
                EReference eRef = eFactory.createEReference();
                eRef.setUpperBound(-1);
                eRef.setName(attrib.getName());
                // Hardcoded hack to fix multiplicity for
                // IfcSpatialStructureElement which references
                // RefLatitude and RefLongitude
                eRef.setUnsettable(expAttrib.isOptional());
                eRef.setEType(eType);
                eRef.setUnique(false);
                // EClass cls = (EClass)
                // schemaPack.getEClassifier(ent.getName());
                cls.getEStructuralFeatures().add(eRef);
            }
        // EClassifier eType = schemaPack.getEClassifier(nt.getName());
        // eRef.setEType(eType);
        // cls.getEStructuralFeatures().add(eRef);
        } else if (bt instanceof RealType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setUpperBound(-1);
            eAttribute.setUnique(false);
            eAttribute.setEType(EcorePackage.eINSTANCE.getEDouble());
            cls.getEStructuralFeatures().add(eAttribute);
            EAttribute doubleStringAttribute = eFactory.createEAttribute();
            doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
            doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
            doubleStringAttribute.setName(attrib.getName() + "AsString");
            doubleStringAttribute.setUpperBound(-1);
            doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
            doubleStringAttribute.setUnsettable(expAttrib.isOptional());
            doubleStringAttribute.setUpperBound(eAttribute.getUpperBound());
            doubleStringAttribute.setUnique(false);
            cls.getEStructuralFeatures().add(doubleStringAttribute);
        } else if (bt instanceof IntegerType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setName(attrib.getName());
            eAttribute.setUpperBound(-1);
            eAttribute.setUnique(false);
            eAttribute.setEType(EcorePackage.eINSTANCE.getELong());
            eAttribute.setUnsettable(expAttrib.isOptional());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (bt instanceof NumberType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setName(attrib.getName());
            eAttribute.setUpperBound(-1);
            eAttribute.setUnique(false);
            eAttribute.setEType(EcorePackage.eINSTANCE.getELong());
            eAttribute.setUnsettable(expAttrib.isOptional());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (bt instanceof LogicalType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setName(attrib.getName());
            eAttribute.setUpperBound(-1);
            eAttribute.setUnique(false);
            eAttribute.setEType(EcorePackage.eINSTANCE.getEBoolean());
            eAttribute.setUnsettable(expAttrib.isOptional());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (bt instanceof BinaryType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setUpperBound(-1);
            eAttribute.setName(attrib.getName());
            eAttribute.setUnique(false);
            eAttribute.setEType(EcorePackage.eINSTANCE.getEByteArray());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (bt == null) {
            // These are the new 2-dimensional arrays in IFC4, there are 10 of them (more in add2)
            addTwoDimensionalArray(ent.getName(), attrib.getName());
        }
        if (domain instanceof ArrayType) {
        // TODO this is not yet implmented in simpelSDAI
        // eAttrib.setLowerBound(((nl.tue.buildingsmart.express.dictionary
        // .ArrayType)domain).getLower_index());
        // One fix for this has been implemented in addHackedTypes
        }
    } else {
        EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
        if (domain == null) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(tristate);
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (domain instanceof IntegerType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(EcorePackage.eINSTANCE.getELong());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (domain instanceof LogicalType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(EcorePackage.eINSTANCE.getEBoolean());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (domain instanceof RealType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(EcorePackage.eINSTANCE.getEDouble());
            cls.getEStructuralFeatures().add(eAttribute);
            EAttribute eAttributeAsString = eFactory.createEAttribute();
            eAttributeAsString.getEAnnotations().add(createAsStringAnnotation());
            eAttributeAsString.getEAnnotations().add(createHiddenAnnotation());
            eAttributeAsString.setUnsettable(expAttrib.isOptional());
            eAttributeAsString.setName(attrib.getName() + "AsString");
            eAttributeAsString.setEType(EcorePackage.eINSTANCE.getEString());
            cls.getEStructuralFeatures().add(eAttributeAsString);
        } else if (domain instanceof StringType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(EcorePackage.eINSTANCE.getEString());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (domain instanceof BinaryType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(EcorePackage.eINSTANCE.getEByteArray());
            cls.getEStructuralFeatures().add(eAttribute);
        } else {
            throw new RuntimeException("Unknown type: " + domain);
        }
    }
}
Also used : BinaryType(nl.tue.buildingsmart.schema.BinaryType) StringType(nl.tue.buildingsmart.schema.StringType) NamedType(nl.tue.buildingsmart.schema.NamedType) EnumerationType(nl.tue.buildingsmart.schema.EnumerationType) EClassifier(org.eclipse.emf.ecore.EClassifier) LogicalType(nl.tue.buildingsmart.schema.LogicalType) AggregationType(nl.tue.buildingsmart.schema.AggregationType) RealType(nl.tue.buildingsmart.schema.RealType) IntegerType(nl.tue.buildingsmart.schema.IntegerType) ArrayType(nl.tue.buildingsmart.schema.ArrayType) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) NumberType(nl.tue.buildingsmart.schema.NumberType) BaseType(nl.tue.buildingsmart.schema.BaseType) EReference(org.eclipse.emf.ecore.EReference) ExplicitAttribute(nl.tue.buildingsmart.schema.ExplicitAttribute)

Aggregations

AggregationType (nl.tue.buildingsmart.schema.AggregationType)1 ArrayType (nl.tue.buildingsmart.schema.ArrayType)1 BaseType (nl.tue.buildingsmart.schema.BaseType)1 BinaryType (nl.tue.buildingsmart.schema.BinaryType)1 EnumerationType (nl.tue.buildingsmart.schema.EnumerationType)1 ExplicitAttribute (nl.tue.buildingsmart.schema.ExplicitAttribute)1 IntegerType (nl.tue.buildingsmart.schema.IntegerType)1 LogicalType (nl.tue.buildingsmart.schema.LogicalType)1 NamedType (nl.tue.buildingsmart.schema.NamedType)1 NumberType (nl.tue.buildingsmart.schema.NumberType)1 RealType (nl.tue.buildingsmart.schema.RealType)1 StringType (nl.tue.buildingsmart.schema.StringType)1 EAttribute (org.eclipse.emf.ecore.EAttribute)1 EClass (org.eclipse.emf.ecore.EClass)1 EClassifier (org.eclipse.emf.ecore.EClassifier)1 EReference (org.eclipse.emf.ecore.EReference)1