Search in sources :

Example 1 with DataHolder

use of org.osate.ba.aadlba.DataHolder in project osate2 by osate.

the class AadlBaUtils method isSameTarget.

/**
 * Compare the given Target objects.<BR><BR>
 *
 * This comparator is base on name and not on object's hash number, meaning
 * that two different Target instances with the same name are
 * considered as equals.
 *
 * This comparator doesn't support array indexes comparison, meaning that two
 * target instances with the same name and different array indexes
 * are considered as equals.
 * <BR><BR>
 *
 * @param tar0 the first name
 * @param tar1 the second name
 * @return {@code true} if the given Target objects are the same.
 * Otherwise returns {@code false}
 */
public static boolean isSameTarget(Target tar0, Target tar1) {
    if (tar0 instanceof ElementHolder && tar1 instanceof DataComponentReference || tar1 instanceof ElementHolder && tar0 instanceof DataComponentReference) {
        return false;
    } else {
        if (tar0 instanceof ElementHolder && tar1 instanceof ElementHolder) {
            return isSameElementHolder((ElementHolder) tar0, (ElementHolder) tar1);
        } else {
            EList<DataHolder> dhl0 = ((DataComponentReference) tar0).getData();
            EList<DataHolder> dhl1 = ((DataComponentReference) tar1).getData();
            if (dhl0.size() == dhl1.size()) {
                ListIterator<DataHolder> it1 = dhl1.listIterator();
                DataHolder dh1 = null;
                boolean result = true;
                for (DataHolder dh0 : dhl0) {
                    dh1 = it1.next();
                    result &= isSameElementHolder(dh0, dh1);
                }
                return result;
            } else {
                return false;
            }
        }
    }
}
Also used : DataHolder(org.osate.ba.aadlba.DataHolder) ElementHolder(org.osate.ba.aadlba.ElementHolder) PropertyElementHolder(org.osate.ba.aadlba.PropertyElementHolder) DataComponentReference(org.osate.ba.aadlba.DataComponentReference)

Example 2 with DataHolder

use of org.osate.ba.aadlba.DataHolder in project osate2 by osate.

the class AadlBaUtils method getAccessRight.

/**
 * If the given Target object is a DataAccessHolder object or a
 * DataComponentReference object which the last element is a DataAccessHolder
 * object, it returns the data access right or "unknown" if the default
 * data access right is not set.
 *
 * @see org.osate.utils.internal.Aadl2Utils#getAccessRight
 * @param tar the given Target object
 * @return the data access right or "unknown"
 */
public static String getAccessRight(Target tar) {
    ElementHolder el = null;
    if (// The other ElementHolders.
    tar instanceof ElementHolder) {
        el = (ElementHolder) tar;
    } else // Data component reference.
    {
        EList<DataHolder> dhl = ((DataComponentReference) tar).getData();
        el = dhl.get(dhl.size() - 1);
    }
    if (el instanceof DataAccessHolder || el instanceof DataAccessPrototypeHolder || el instanceof FeaturePrototypeHolder) {
        return Aadl2Utils.getAccessRight(el.getElement());
    } else {
        return "unknown";
    }
}
Also used : DataAccessHolder(org.osate.ba.aadlba.DataAccessHolder) DataHolder(org.osate.ba.aadlba.DataHolder) DataAccessPrototypeHolder(org.osate.ba.aadlba.DataAccessPrototypeHolder) FeaturePrototypeHolder(org.osate.ba.aadlba.FeaturePrototypeHolder) ElementHolder(org.osate.ba.aadlba.ElementHolder) PropertyElementHolder(org.osate.ba.aadlba.PropertyElementHolder) DataComponentReference(org.osate.ba.aadlba.DataComponentReference)

Example 3 with DataHolder

use of org.osate.ba.aadlba.DataHolder in project osate2 by osate.

the class AadlBaUtils method prototypeBindingResolverForDataComponentReference.

/**
 * Returns the DataClassifier object associated to prototype binding in a DataComponentReference
 *
 * @param r the DataComponentRefenrence object from which the binding will be resolved
 * @param dp the DataPrototpye object that enables to identify the targeted prototype binding
 * @param parentContainer the object that contains the element binded to the
 * given DataComponentRefenrence
 * @return the DataClassifier object
 */
private static DataClassifier prototypeBindingResolverForDataComponentReference(DataComponentReference r, DataPrototype dp, NamedElement parentContainer) {
    if (r.getData().size() > 1) {
        DataHolder h = r.getData().get(r.getData().size() - 2);
        NamedElement parent = h.getElement();
        if (parent instanceof Classifier) {
            Classifier c = (Classifier) parent;
            return getDataClassifier(c.getOwnedPrototypeBindings(), dp);
        }
        if (parent instanceof Subcomponent) {
            Subcomponent s = (Subcomponent) parent;
            return getDataClassifier(s.getOwnedPrototypeBindings(), dp);
        } else if (parent instanceof DataAccess) {
            DataAccess da = (DataAccess) parent;
            DataSubcomponentType parentDst = da.getDataFeatureClassifier();
            Classifier c = (Classifier) parentDst;
            DataClassifier matchedPrototype = getDataClassifier(c.getOwnedPrototypeBindings(), dp);
            if (matchedPrototype == null) {
                if (parentContainer instanceof ComponentType) {
                    ComponentType ct = (ComponentType) parentContainer;
                    for (Feature f : ct.getOwnedFeatures()) {
                        if (f instanceof DataAccess && f.getName().equals(parent.getName())) {
                            DataAccess containerDa = (DataAccess) f;
                            DataSubcomponentType containerDst = containerDa.getDataFeatureClassifier();
                            Classifier c2 = (Classifier) containerDst;
                            return getDataClassifier(c2.getOwnedPrototypeBindings(), dp);
                        }
                    }
                }
            }
        } else if (parent instanceof DataPort) {
            DataPort dataport = (DataPort) parent;
            DataSubcomponentType parentDst = dataport.getDataFeatureClassifier();
            Classifier c = (Classifier) parentDst;
            DataClassifier matchedPrototype = getDataClassifier(c.getOwnedPrototypeBindings(), dp);
            if (matchedPrototype == null) {
                if (parentContainer instanceof ComponentType) {
                    ComponentType ct = (ComponentType) parentContainer;
                    for (Feature f : ct.getOwnedFeatures()) {
                        if (f instanceof DataPort && f.getName().equals(parent.getName())) {
                            DataPort containerDp = (DataPort) f;
                            DataSubcomponentType containerDst = containerDp.getDataFeatureClassifier();
                            Classifier c2 = (Classifier) containerDst;
                            return getDataClassifier(c2.getOwnedPrototypeBindings(), dp);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ComponentType(org.osate.aadl2.ComponentType) DataHolder(org.osate.ba.aadlba.DataHolder) Subcomponent(org.osate.aadl2.Subcomponent) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ProcessClassifier(org.osate.aadl2.ProcessClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) DataClassifier(org.osate.aadl2.DataClassifier) BehaviorNamedElement(org.osate.ba.aadlba.BehaviorNamedElement) NamedElement(org.osate.aadl2.NamedElement) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) DataAccess(org.osate.aadl2.DataAccess)

Example 4 with DataHolder

use of org.osate.ba.aadlba.DataHolder in project osate2 by osate.

the class AadlBaUtils method getDataClassifier.

/**
 * Returns the DataClassifier of the element binded to the given
 * Value object. A target instance can be given to this method as
 * Target instance can be cast into ValueVariable reference.
 * <BR><BR>
 *  Notes: <BR><BR>
 *  <BR>_ ValueVariable : {@link #getClassifier(Element, Classifier)}
 *                                 to see the restrictions.
 *  <BR>_ ValueConstant : Property constant and property reference are not supported:
 *  returns {@code null}.
 *  <BR><BR>
 *
 * @param v the given Value object
 * @param parentContainer only for AADLBA declarative objects which have no
 * parent set, yet
 * @return the binded component's DataClassifier object or {@code null} for
 * the ValueConstant objects and for the Abstract components objects.
 * @exception UnsupportedOperationException for unsupported binded
 * object types.
 */
public static DataClassifier getDataClassifier(Value v, ComponentClassifier parentContainer) {
    Classifier result = null;
    if (v instanceof ValueVariable) {
        // Either ElementHolder or DataComponentReference object.
        Element el = null;
        if (v instanceof ElementHolder) {
            el = ((ElementHolder) v).getElement();
        } else // DataComponentReference case.
        {
            DataComponentReference dcr = (DataComponentReference) v;
            DataHolder lastElement = dcr.getData().get(dcr.getData().size() - 1);
            el = lastElement.getElement();
        }
        if (parentContainer == null) {
            parentContainer = (ComponentClassifier) v.getContainingClassifier();
        }
        result = getClassifier(el, parentContainer);
    } else // Property constant and property reference are not supported.
    {
        result = null;
    }
    if (result instanceof DataClassifier) {
        return (DataClassifier) result;
    } else // Abstract components case.
    {
        return null;
    }
}
Also used : ValueVariable(org.osate.ba.aadlba.ValueVariable) DataHolder(org.osate.ba.aadlba.DataHolder) StructUnionElement(org.osate.ba.aadlba.StructUnionElement) BehaviorNamedElement(org.osate.ba.aadlba.BehaviorNamedElement) NamedElement(org.osate.aadl2.NamedElement) ArrayableElement(org.osate.aadl2.ArrayableElement) Element(org.osate.aadl2.Element) BehaviorElement(org.osate.ba.aadlba.BehaviorElement) IndexableElement(org.osate.ba.aadlba.IndexableElement) ElementHolder(org.osate.ba.aadlba.ElementHolder) PropertyElementHolder(org.osate.ba.aadlba.PropertyElementHolder) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ProcessClassifier(org.osate.aadl2.ProcessClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) DataClassifier(org.osate.aadl2.DataClassifier) DataComponentReference(org.osate.ba.aadlba.DataComponentReference)

Example 5 with DataHolder

use of org.osate.ba.aadlba.DataHolder in project osate2 by osate.

the class AadlBaUtils method getDataRepresentation.

/**
 * Returns the data representation of the given ValueVariable object
 * or DataRepresentation.UNKNOWN if Data_Model::Data_Representation
 * property is not set or if the ValueVariable object represents a data
 * structure.
 *
 * @param v the given ValueVariable object
 * @return the data representation or DataRepresentation.UNKNOWN
 */
public static DataRepresentation getDataRepresentation(ValueVariable v) {
    if (v instanceof PortCountValue) {
        return DataRepresentation.INTEGER;
    } else if (v instanceof PortFreshValue) {
        return DataRepresentation.BOOLEAN;
    } else {
        // Either ElementHolder or DataComponentReference object.
        Element el = null;
        if (v instanceof ElementHolder) {
            if (v instanceof PrototypeHolder) {
                PrototypeHolder ph = (PrototypeHolder) v;
                if (ph.getPrototypeBinding() != null) {
                    el = ph.getPrototypeBinding();
                } else {
                    el = ph.getPrototype();
                }
            } else {
                el = ((ElementHolder) v).getElement();
            }
        } else // DataComponentReference case.
        {
            DataComponentReference dcr = (DataComponentReference) v;
            DataHolder lastElement = dcr.getData().get(dcr.getData().size() - 1);
            el = lastElement.getElement();
        }
        if (el instanceof Abstract) {
            return DataRepresentation.UNKNOWN;
        } else if (el instanceof Feature) {
            Classifier c = ((Feature) el).getClassifier();
            if (c instanceof DataClassifier) {
                return getDataRepresentation((DataClassifier) c);
            } else {
                return DataRepresentation.UNKNOWN;
            }
        } else if (el instanceof DataSubcomponent) {
            final DataSubcomponent subcompo = (DataSubcomponent) el;
            final Classifier classifier = subcompo.getClassifier();
            // fixes 2401: Avoid crashing the editor when subcomponent is not resolved
            if (classifier == null || classifier.eIsProxy()) {
                return DataRepresentation.UNKNOWN;
            }
            return getDataRepresentation((DataClassifier) ((DataSubcomponent) el).getClassifier());
        } else if (el instanceof BehaviorVariable) {
            // Behavior case.
            return getDataRepresentation((BehaviorVariable) el);
        } else {
            // Prototype cases.
            Classifier klass;
            ComponentClassifier baParentComponent = (ComponentClassifier) v.getContainingClassifier();
            klass = AadlBaUtils.getClassifier(el, baParentComponent);
            return getDataRepresentation((DataClassifier) klass);
        }
    }
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) Abstract(org.osate.aadl2.Abstract) StructUnionElement(org.osate.ba.aadlba.StructUnionElement) BehaviorNamedElement(org.osate.ba.aadlba.BehaviorNamedElement) NamedElement(org.osate.aadl2.NamedElement) ArrayableElement(org.osate.aadl2.ArrayableElement) Element(org.osate.aadl2.Element) BehaviorElement(org.osate.ba.aadlba.BehaviorElement) IndexableElement(org.osate.ba.aadlba.IndexableElement) ElementHolder(org.osate.ba.aadlba.ElementHolder) PropertyElementHolder(org.osate.ba.aadlba.PropertyElementHolder) PortFreshValue(org.osate.ba.aadlba.PortFreshValue) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ProcessClassifier(org.osate.aadl2.ProcessClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) DataClassifier(org.osate.aadl2.DataClassifier) DataComponentReference(org.osate.ba.aadlba.DataComponentReference) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) PortCountValue(org.osate.ba.aadlba.PortCountValue) DataHolder(org.osate.ba.aadlba.DataHolder) DataSubcomponent(org.osate.aadl2.DataSubcomponent) PrototypeHolder(org.osate.ba.aadlba.PrototypeHolder) DataAccessPrototypeHolder(org.osate.ba.aadlba.DataAccessPrototypeHolder) FeaturePrototypeHolder(org.osate.ba.aadlba.FeaturePrototypeHolder)

Aggregations

DataHolder (org.osate.ba.aadlba.DataHolder)5 DataComponentReference (org.osate.ba.aadlba.DataComponentReference)4 ElementHolder (org.osate.ba.aadlba.ElementHolder)4 PropertyElementHolder (org.osate.ba.aadlba.PropertyElementHolder)4 Classifier (org.osate.aadl2.Classifier)3 ComponentClassifier (org.osate.aadl2.ComponentClassifier)3 DataClassifier (org.osate.aadl2.DataClassifier)3 NamedElement (org.osate.aadl2.NamedElement)3 ProcessClassifier (org.osate.aadl2.ProcessClassifier)3 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)3 SubprogramClassifier (org.osate.aadl2.SubprogramClassifier)3 BehaviorNamedElement (org.osate.ba.aadlba.BehaviorNamedElement)3 AbstractFeature (org.osate.aadl2.AbstractFeature)2 ArrayableElement (org.osate.aadl2.ArrayableElement)2 DataSubcomponent (org.osate.aadl2.DataSubcomponent)2 DirectedFeature (org.osate.aadl2.DirectedFeature)2 Element (org.osate.aadl2.Element)2 Feature (org.osate.aadl2.Feature)2 BehaviorElement (org.osate.ba.aadlba.BehaviorElement)2 DataAccessPrototypeHolder (org.osate.ba.aadlba.DataAccessPrototypeHolder)2