use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class ProgrammingProperties method getRecoverEntrypointCallSequence.
public static Optional<InstanceObject> getRecoverEntrypointCallSequence(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getRecoverEntrypointCallSequence_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((InstanceReferenceValue) resolved).getReferencedInstanceObject());
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class ProgrammingProperties method getDeactivateEntrypointCallSequence.
public static Optional<InstanceObject> getDeactivateEntrypointCallSequence(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getDeactivateEntrypointCallSequence_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((InstanceReferenceValue) resolved).getReferencedInstanceObject());
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class ProgrammingProperties method getInitializeEntrypointCallSequence.
public static Optional<InstanceObject> getInitializeEntrypointCallSequence(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getInitializeEntrypointCallSequence_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((InstanceReferenceValue) resolved).getReferencedInstanceObject());
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
use of org.osate.aadl2.instance.InstanceObject 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.instance.InstanceObject in project osate2 by osate.
the class InstantiateModel method interpretConnectionPatterns.
private boolean interpretConnectionPatterns(ConnectionInstance conni, boolean isOpposite, List<PropertyExpression> patterns, int offset, List<Integer> srcSizes, int srcOffset, List<Integer> dstSizes, int dstOffset, List<Long> srcIndices, List<Long> dstIndices) {
boolean result = true;
if (patterns != null ? offset >= patterns.size() : srcOffset == srcSizes.size() && dstOffset == dstSizes.size()) {
createNewConnection(conni, srcIndices, dstIndices);
return result;
}
String patternName = "One_to_One";
if (patterns == null) {
// default one-to-one pattern
if (!conni.isComplete()) {
// outgoing or incoming only
InstanceObject io = conni.getSource();
if (io instanceof FeatureInstance && io.getContainingComponentInstance() instanceof SystemInstance) {
if (srcSizes.isEmpty()) {
patternName = isOpposite ? "All_to_One" : "One_To_All";
}
} else {
if (dstSizes.isEmpty()) {
patternName = isOpposite ? "One_To_All" : "All_to_One";
}
}
}
} else {
NamedValue nv = (NamedValue) patterns.get(offset);
EnumerationLiteral pattern = (EnumerationLiteral) nv.getNamedValue();
patternName = pattern.getName();
}
if (!isOpposite && !patternName.equalsIgnoreCase("One_To_All") && (srcOffset >= srcSizes.size())) {
errManager.error(conni, "Too few indices for connection source for " + conni.getFullName());
return false;
}
if (!isOpposite && !patternName.equalsIgnoreCase("All_To_One") && (dstOffset >= dstSizes.size())) {
errManager.error(conni, "Too few indices for connection destination for " + conni.getFullName());
return false;
}
if (isOpposite && !patternName.equalsIgnoreCase("One_To_All") && (dstOffset >= dstSizes.size())) {
// verbose exception message
errManager.error(conni, "Too few indices for connection source for " + conni.getFullName());
return false;
}
if (isOpposite && !patternName.equalsIgnoreCase("All_To_One") && (srcOffset >= srcSizes.size())) {
errManager.error(conni, "Too few indices for connection destination for " + conni.getFullName());
return false;
}
if (patternName.equalsIgnoreCase("All_To_All")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
for (long j = 1; j <= dstSizes.get(dstOffset); j++) {
dstIndices.add(j);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
}
srcIndices.remove(srcOffset);
}
} else if ((!isOpposite && patternName.equalsIgnoreCase("One_To_All")) || (isOpposite && patternName.equalsIgnoreCase("All_To_One"))) {
for (long j = 1; j <= dstSizes.get(dstOffset); j++) {
dstIndices.add(j);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
}
} else if ((!isOpposite && patternName.equalsIgnoreCase("All_To_One")) || (isOpposite && patternName.equalsIgnoreCase("One_To_All"))) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset, srcIndices, dstIndices);
srcIndices.remove(srcOffset);
}
} else {
if (!srcSizes.get(srcOffset).equals(dstSizes.get(dstOffset))) {
// verbose exception message
errManager.error(conni, "Array size mismatch (" + patternName + ") on connection " + conni.getFullName() + " in " + conni.getContainingComponentInstance().getFullName() + ": " + srcSizes.get(srcOffset) + // ("+conni.getSource().getFullName()+")
" at source " + "and " + dstSizes.get(dstOffset) + // ("+conni.getSource().getFullName()+")."
" at destination.");
return false;
} else {
if (patternName.equalsIgnoreCase("One_To_One")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
srcIndices.remove(srcOffset);
dstIndices.remove(dstOffset);
}
} else if (patternName.equalsIgnoreCase("Next")) {
for (long i = 1; i <= srcSizes.get(srcOffset) - 1; i++) {
srcIndices.add(i);
dstIndices.add(i + 1);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Previous")) {
for (long i = 2; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i - 1);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Cyclic_Next")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i == srcSizes.get(srcOffset) ? 1 : i + 1);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Cyclic_Previous")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i == 1 ? srcSizes.get(srcOffset) : i - 1);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Next_Next")) {
for (long i = 1; i <= srcSizes.get(srcOffset) - 2; i++) {
srcIndices.add(i);
dstIndices.add(i + 2);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Previous_Previous")) {
for (long i = 3; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i - 2);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Cyclic_Next_Next")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i == srcSizes.get(srcOffset) ? 2 : (i == srcSizes.get(srcOffset) - 1 ? 1 : i + 1));
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Cyclic_Previous_Previous")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i == 2 ? srcSizes.get(srcOffset) : (i == 1 ? srcSizes.get(srcOffset) - 1 : i - 1));
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Even_To_Even")) {
for (long i = 2; i <= srcSizes.get(srcOffset); i = i + 2) {
srcIndices.add(i);
dstIndices.add(i);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Odd_To_Odd")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i = i + 2) {
srcIndices.add(i);
dstIndices.add(i);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
}
}
}
return result;
}
Aggregations