Search in sources :

Example 1 with DerivedAttribute2

use of nl.tue.buildingsmart.schema.DerivedAttribute2 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);
        // }
        }
    }
}
Also used : EntityDefinition(nl.tue.buildingsmart.schema.EntityDefinition) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) EClassifier(org.eclipse.emf.ecore.EClassifier) DerivedAttribute2(nl.tue.buildingsmart.schema.DerivedAttribute2) DefinedType(nl.tue.buildingsmart.schema.DefinedType) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

DefinedType (nl.tue.buildingsmart.schema.DefinedType)1 DerivedAttribute2 (nl.tue.buildingsmart.schema.DerivedAttribute2)1 EntityDefinition (nl.tue.buildingsmart.schema.EntityDefinition)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