Search in sources :

Example 1 with IntegerBound

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

the class Express2EMF method addInverseAttribute.

private void addInverseAttribute(Attribute attrib, EClass cls) {
    InverseAttribute inverseAttribute = (InverseAttribute) attrib;
    EReference eRef = eFactory.createEReference();
    // Inverses are always optional?
    eRef.setUnsettable(true);
    eRef.getEAnnotations().add(createInverseAnnotation());
    eRef.setName(attrib.getName());
    if (inverseAttribute.getMax_cardinality() != null) {
        IntegerBound max_cardinality = (IntegerBound) inverseAttribute.getMax_cardinality();
        if (max_cardinality.getBound_value() == -1) {
            eRef.setUpperBound(max_cardinality.getBound_value());
        } else {
            eRef.setUpperBound(max_cardinality.getBound_value() + 1);
        }
    }
    String type = (inverseAttribute).getDomain().getName();
    EClass classifier = (EClass) schemaPack.getEClassifier(type);
    eRef.setEType(classifier);
    String reverseName = inverseAttribute.getInverted_attr().getName();
    EReference reference = (EReference) classifier.getEStructuralFeature(reverseName);
    reference.getEAnnotations().add(createInverseAnnotation());
    if (eRef.getEType() == classifier && reference.getEType() == cls) {
        if (eRef.isMany()) {
            eRef.setUnique(true);
        }
        if (reference.isMany()) {
            reference.setUnique(true);
        }
        reference.setEOpposite(eRef);
        eRef.setEOpposite(reference);
    } else {
        System.out.println("Inverse mismatch");
        System.out.println(classifier.getName() + "." + reference.getName() + " => " + cls.getName() + "." + eRef.getName());
    }
    cls.getEStructuralFeatures().add(eRef);
}
Also used : IntegerBound(nl.tue.buildingsmart.schema.IntegerBound) EClass(org.eclipse.emf.ecore.EClass) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

IntegerBound (nl.tue.buildingsmart.schema.IntegerBound)1 InverseAttribute (nl.tue.buildingsmart.schema.InverseAttribute)1 EClass (org.eclipse.emf.ecore.EClass)1 EReference (org.eclipse.emf.ecore.EReference)1