use of org.osate.aadl2.instance.InstanceObject 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;
}
}
}
use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class CachePropertyAssociationsSwitch method cachePropertyAssociations.
protected void cachePropertyAssociations(InstanceObject io) {
try {
for (Property property : propertyFilter) {
if (io.acceptsProperty(property)) {
/*
* Just look up the property. The property doesn't yet have a
* local association, so lookup will get the value from the
* declarative model. Property lookup process now corrects
* reference values to instance reference values.
*/
PropertyEvaluationResult result = property.evaluate(new EvaluationContext(io, classifierCache), 0);
List<EvaluatedProperty> evaluated = result.getEvaluated();
if (!evaluated.isEmpty()) {
// OsateDebug.osateDebug ("[CachePropertyAssociation] io=" + io + ";property=" + property + ";value=" + value);
PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
io.removePropertyAssociations(property);
newPA.setProperty(property);
newPA.setPropertyAssociation(getDeclarativePA(result.getPa()));
fillPropertyValue(io, newPA, evaluated);
if (!newPA.getOwnedValues().isEmpty()) {
io.getOwnedPropertyAssociations().add(newPA);
}
}
}
checkIfCancelled();
if (cancelled()) {
break;
}
}
} catch (IllegalStateException e) {
// circular dependency
// xxx: this is a misleading place to put the marker
OsateDebug.osateDebug("IllegalStateException raised in cachePropertyAssociations");
error(io, e.getMessage());
return;
} catch (InvalidModelException e) {
OsateDebug.osateDebug("InvalidModelException raised in cachePropertyAssociations");
error(e.getElement(), e.getMessage());
return;
}
}
use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class AadlUtil method getInstanceOrigin.
// /**
// * Find the Element whose location reference is close to the line number.
// *
// * @param modelelement The model element used as root of the search
// * @param location line number
// * @return Element
// */
// public static Element findElement(Element modelelement, int location) {
// return doFindElement(modelelement, location, modelelement);
// }
//
// /**
// * Find an Element whose reference location is the largest less or equal to
// * the location we are looking for. This find method cannot assume that the
// * elements of the object model are visited in unparse order. Therefore we
// * search the whole containment tree for the closest element whose location
// * reference is less or equal to the desired location.
// *
// * @param modelelement The model element and its sub elements to be visited
// * @param location The location as line whose Element equivalent we are
// * trying to find
// * @param closestLocation the last Element whose location reference is less
// * or equal than the location
// * @return Element the last visited Element whose location reference matches
// * the condition
// */
// private static Element doFindElement(Element modelelement, int location, Element closestLocation) {
// LocationReference loc = modelelement.getLocationReference();
// if (loc != null) {
// int thisline = loc.getLine();
// if (thisline > location) {
// return closestLocation;
// } else if (thisline == location) {
// return modelelement;
// } else {
// // out location is less than the desired location. Check if it
// // closer than the previously remembered location
// LocationReference closeloc = closestLocation.getLocationReference();
// if (closeloc == null) {
// closestLocation = modelelement;
// } else if (thisline > closeloc.getLine()) {
// closestLocation = modelelement;
// }
// }
// }
// EList<EObject> list = modelelement.eContents();//getOwnedElements(); for (Iterator<Element> it = list.iterator(); it.hasNext();) {
// for (Iterator<EObject> it = list.iterator(); it.hasNext();) {
// Element child = (Element) it.next();
// Element result = doFindElement(child, location, closestLocation);
// if (result != closestLocation) {
// closestLocation = result;
// }
// }
// return closestLocation;
// }
//
// private static final String PropertySetLabel = "propertySet[@name=";
// private static final String PackageLabel = "aadlPackage[@name=";
public static Element getInstanceOrigin(InstanceObject io) {
List<? extends NamedElement> el = io.getInstantiatedObjects();
Element target = null;
if (el.size() == 0) {
return null;
} else if (el.size() == 1) {
target = el.get(0);
} else if (el.size() > 1) {
for (NamedElement o : el) {
if (o instanceof Connection) {
Connection conn = (Connection) o;
if ((conn.getAllSourceContext() instanceof Subcomponent && conn.getAllDestinationContext() instanceof Subcomponent) || (conn.getAllSourceContext() == null || conn.getAllDestinationContext() == null)) {
target = conn;
break;
}
}
}
if (target instanceof InstanceObject) {
target = el.get(0);
}
}
return target;
}
use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class ForAllElement method processObject.
/**
* Process a single model object. Delegates to {@link #process(Element)}.
* This method exists to satisfy the {@link IProcessingMethod} interface. I
* would have preferred to have a <code>process</code> method in the
* interface, but I cannot because the <code>ForAllElement.process</code>
* method is <code>protected</code>. If I put the method in an interface, I
* would have to make the method <code>public</code>, which could break
* existing code.
*/
@Override
public final void processObject(final Element theElement) {
if (theElement instanceof InstanceObject) {
InstanceObject io = (InstanceObject) theElement;
SystemInstance root = io.getSystemInstance();
SystemOperationMode som = root.getCurrentSystemOperationMode();
if (som == null || io.isActive(som)) {
process(io);
}
} else {
process(theElement);
}
}
use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class NamedElementImpl method getNonModalPropertyValue.
/**
* Retrieves the property value (single or list) of a non-modal property. Throws an exception
* if its a modal value or undefined.
* @param property Property
* @return The property expression or null if the property has no value.
*/
public PropertyExpression getNonModalPropertyValue(final Property property) throws InvalidModelException, PropertyNotPresentException, PropertyIsModalException, IllegalStateException, IllegalArgumentException, PropertyDoesNotApplyToHolderException {
PropertyAssociation pa = getPropertyValue(property, false).first();
if (pa == null) {
if (property.getDefaultValue() == null) {
throw new PropertyNotPresentException(this, property, "No property association was found");
}
return property.getDefaultValue();
} else {
if (!pa.isModal()) {
// should always exist because it's not modal
if (pa.getOwnedValues().isEmpty()) {
throw new PropertyNotPresentException(this, property, "Property association has no value (yet)");
}
return pa.getOwnedValues().get(0).getOwnedValue();
} else {
// If we are an InstanceObject, get the value in the current SOM
if (this instanceof InstanceObject) {
final SystemInstance si = ((InstanceObject) this).getSystemInstance();
final SystemOperationMode som = si.getCurrentSystemOperationMode();
if (som != null) {
PropertyExpression defaultPE = null;
// find value in SOM
for (ModalPropertyValue mpv : pa.getOwnedValues()) {
if (mpv.getInModes() == null || mpv.getInModes().size() == 0) {
defaultPE = mpv.getOwnedValue();
} else if (mpv.getInModes().contains(som)) {
return mpv.getOwnedValue();
}
}
// default
if (defaultPE != null) {
return defaultPE;
}
// use global default
return property.getDefaultValue();
} else {
throw new PropertyIsModalException(this, property, "Cannot use simple property lookup because the instance model has not been projected into a System Operation Mode." + " This occurred when looking up Property " + property.getName() + " on NamedElement " + getName() + ".");
}
} else {
throw new PropertyIsModalException(this, property, "A non-modal property lookup method was called for a modal property." + " This occurred when looking up Property " + property.getName() + " on NamedElement " + getName() + ".");
}
}
}
}
Aggregations