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;
}
}
}
}
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";
}
}
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;
}
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;
}
}
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);
}
}
}
Aggregations