use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class ReferenceImpl method basicSetPath.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetPath(ContainmentPathElement newPath, NotificationChain msgs) {
ContainmentPathElement oldPath = path;
path = newPath;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, DeclarativePackage.REFERENCE__PATH, oldPath, newPath);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class PropertyUtils method isInAppliesTo.
private static PropertyAssociation isInAppliesTo(NamedElement owner, String propertyName) {
EObject parent = owner.eContainer();
String ownerName = owner.getName();
while (parent != null) {
if (parent instanceof NamedElement) {
EList<PropertyAssociation> pas = ((NamedElement) parent).getOwnedPropertyAssociations();
for (PropertyAssociation pa : pas) {
String propName = pa.getProperty().getName();
if (propName != null && propName.equalsIgnoreCase(propertyName)) {
for (ContainedNamedElement cne : pa.getAppliesTos()) {
EList<ContainmentPathElement> paths = cne.getContainmentPathElements();
ContainmentPathElement lastEl = paths.get(paths.size() - 1);
String lastElName = lastEl.getNamedElement().getName();
if (lastElName.equalsIgnoreCase(ownerName)) {
return pa;
}
}
}
}
}
parent = parent.eContainer();
}
return null;
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class PropertyUtils method getSubcomponentList.
/**
* May return an empty list.
*
* @param object
* @param propertyName
* @return
*/
public static List<Subcomponent> getSubcomponentList(NamedElement object, String propertyName) {
List<Subcomponent> res = new ArrayList<Subcomponent>();
PropertyAssociation pa = findPropertyAssociation(propertyName, object);
if (pa == null) {
return null;
} else {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof ListValue) {
ListValue lv = (ListValue) expr;
for (PropertyExpression pe : lv.getOwnedListElements()) {
if (pe instanceof ReferenceValue) {
ReferenceValue c = ((ReferenceValue) pe);
for (ContainmentPathElement cpe : c.getContainmentPathElements()) {
res.add((Subcomponent) cpe.getNamedElement());
}
}
}
}
}
}
return res;
}
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class CacheContainedPropertyAssociationsSwitch method processContainedPropertyAssociations.
/**
* Copy contained property associations to the instance model.
* Don't fully evaluate the property expression. Just replace reference values with
* a reference to the referenced instance object.
*
* @param modeContext
* @param ci
* @param propertyAssociations
*/
protected void processContainedPropertyAssociations(final ComponentInstance modeContext, final ComponentInstance ci, final EList<PropertyAssociation> propertyAssociations) {
for (PropertyAssociation pa : propertyAssociations) {
// OsateDebug.osateDebug ("[CacheContainedProperty] Process contained property association: " + pa.getProperty().getName());
Property prop = pa.getProperty();
if (Aadl2Util.isNull(prop) || Aadl2Util.isNull(prop.getType())) {
continue;
}
for (ContainedNamedElement cne : pa.getAppliesTos()) {
final EList<ContainmentPathElement> cpes = cne.getContainmentPathElements();
if (cpes != null && !cpes.isEmpty()) {
final NamedElement last = cpes.get(cpes.size() - 1).getNamedElement();
final List<InstanceObject> ios = ci.findInstanceObjects(cpes);
for (InstanceObject io : ios) {
// OsateDebug.osateDebug (" io=" + io);
PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
newPA.setProperty(prop);
newPA.setPropertyAssociation(pa);
newPA.getOwnedValues().addAll(EcoreUtil.copyAll(pa.getOwnedValues()));
// replace reference values in the context of the contained PA's owner
for (Iterator<Element> content = EcoreUtil.getAllProperContents(newPA, false); content.hasNext(); ) {
Element elem = content.next();
if (elem instanceof ReferenceValue) {
// TODO: LW what if ref to connection?
try {
PropertyExpression irv = ((ReferenceValue) elem).instantiate(ci);
if (irv != null) {
EcoreUtil.replace(elem, irv);
}
} catch (InvalidModelException e) {
error(io, e.getMessage());
}
}
}
if (last instanceof Connection) {
final PropertyAssociation existingPA = scProps.retrieveSCProperty((ConnectionInstance) io, prop, (Connection) last);
if (existingPA != null && isConstant(existingPA)) {
/*
* Cannot put the error on the property association that is affected because it might
* be a declarative model element at this point. Need to report the error on the
* instance object itself.
*/
getErrorManager().error(io, "Property association for \"" + prop.getQualifiedName() + "\" is constant. A contained property association in classifier \"" + pa.getContainingClassifier().getQualifiedName() + "\" tries to replace it.");
} else {
scProps.recordSCProperty((ConnectionInstance) io, prop, (Connection) last, newPA);
}
} else {
final PropertyAssociation existingPA = io.getPropertyValue(prop, false).first();
if (existingPA != null && isConstant(existingPA)) {
/*
* Cannot put the error on the property association that is affected because it might
* be a declarative model element at this point. Need to report the error on the
* instance object itself.
*/
getErrorManager().error(io, "Property association for \"" + prop.getQualifiedName() + "\" is constant. A contained property association in classifier \"" + pa.getContainingClassifier().getQualifiedName() + "\" tries to replace it.");
} else {
io.removePropertyAssociations(prop);
io.getOwnedPropertyAssociations().add(newPA);
}
}
}
}
}
checkIfCancelled();
if (cancelled()) {
break;
}
}
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class CacheContainedPropertyAssociationsSwitch method processContainedPropertyAssociations.
protected void processContainedPropertyAssociations(final FeatureInstance fi, final EList<PropertyAssociation> propertyAssociations) {
for (PropertyAssociation pa : propertyAssociations) {
Property prop = pa.getProperty();
if (Aadl2Util.isNull(prop) || Aadl2Util.isNull(prop.getType())) {
// PA is missing the prop def, skip to the next one
continue;
}
for (ContainedNamedElement cne : pa.getAppliesTos()) {
final EList<ContainmentPathElement> cpes = cne.getContainmentPathElements();
if (cpes != null && !cpes.isEmpty()) {
final Collection<FeatureInstance> ios = fi.findFeatureInstances(cpes);
if (!ios.isEmpty()) {
for (InstanceObject io : ios) {
PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
newPA.setProperty(prop);
newPA.setPropertyAssociation(pa);
newPA.getOwnedValues().addAll(EcoreUtil.copyAll(pa.getOwnedValues()));
// replace reference values in the context of the contained PA's owner
for (Iterator<Element> content = EcoreUtil.getAllProperContents(newPA, false); content.hasNext(); ) {
Element elem = content.next();
if (elem instanceof ReferenceValue) {
PropertyExpression irv = ((ReferenceValue) elem).instantiate(fi);
if (irv != null) {
EcoreUtil.replace(elem, irv);
}
}
}
final PropertyAssociation existingPA = io.getPropertyValue(prop, false).first();
if (existingPA != null && isConstant(existingPA)) {
/*
* Cannot put the error on the property association that is affected because it might
* be a declarative model element at this point. Need to report the error on the
* instance object itself.
*/
final String classifierName = pa.getContainingClassifier().getQualifiedName();
final Element owner = pa.getOwner();
final String featureName = (owner instanceof Feature) ? ("." + ((Feature) owner).getName()) : "";
getErrorManager().error(io, "Property association for \"" + prop.getQualifiedName() + "\" is constant. A contained property association in classifier \"" + classifierName + featureName + "\" tries to replace it.");
} else {
io.removePropertyAssociations(prop);
io.getOwnedPropertyAssociations().add(newPA);
}
}
}
}
}
checkIfCancelled();
if (cancelled()) {
break;
}
}
}
Aggregations