use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class AadlPropertyResolver method processedPropertyAssociationsForInstanceObjectNotInTree.
private void processedPropertyAssociationsForInstanceObjectNotInTree(final BusinessObjectContext q, final InstanceObject ioNotInTree, final Iterable<InstanceObject> parentPath) {
final Iterable<InstanceObject> newPath = Iterables.concat(parentPath, Collections.singletonList(ioNotInTree));
// Process relevant properties
for (final PropertyAssociation pa : ioNotInTree.getOwnedPropertyAssociations()) {
final Property property = pa.getProperty();
// Only process reference of list reference properties
if (AadlPropertyUtil.isReferenceOrListReferenceType(property.getType())) {
final PropertyNode pn = getOrCreatePropertyNode(q);
final ProcessedPropertyAssociationCollection ppas = pn.getCreateProcessedPropertyAssociations(property);
ppas.processedPropertyAssociations.add(new InstanceProcessedPropertyAssociation(pa, newPath));
}
}
// Process children
for (final Element child : ioNotInTree.getChildren()) {
if (isSupportedInstanceObject(child)) {
processedPropertyAssociationsForInstanceObjectNotInTree(q, (InstanceObject) child, newPath);
}
}
}
use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class AadlFlowSpecificationUtil method createFlowSegmentReference.
public static FlowSegmentReference createFlowSegmentReference(final Object bo, final BusinessObjectContext container) {
if (bo instanceof FlowSegment) {
final FlowSegment flowSegment = (FlowSegment) bo;
final FlowElement flowElement = flowSegment.getFlowElement();
if (flowSegment.getContext() == null) {
return createFlowSegmentReference(flowElement, container);
} else {
return container.getChildren().stream().filter(child -> {
if (child.getBusinessObject() instanceof NamedElement) {
final NamedElement ne = (NamedElement) child.getBusinessObject();
return AgeAadlUtil.getRootRefinedElement(ne) == AgeAadlUtil.getRootRefinedElement(flowSegment.getContext());
}
return false;
}).findAny().map(contextQueryable -> createFlowSegmentReference(flowElement, contextQueryable)).orElse(null);
}
} else if (bo instanceof EndToEndFlowSegment) {
final EndToEndFlowSegment flowSegment = (EndToEndFlowSegment) bo;
final FlowElement flowElement = (FlowElement) flowSegment.getFlowElement();
if (flowSegment.getContext() == null) {
return createFlowSegmentReference(flowElement, container);
} else {
return container.getChildren().stream().filter(child -> {
if (child.getBusinessObject() instanceof NamedElement) {
final NamedElement ne = (NamedElement) child.getBusinessObject();
return AgeAadlUtil.getRootRefinedElement(ne) == AgeAadlUtil.getRootRefinedElement(flowSegment.getContext());
}
return false;
}).findAny().map(contextQueryable -> createFlowSegmentReference(flowElement, contextQueryable)).orElse(null);
}
} else if (bo instanceof InstanceObject) {
final InstanceObject io = (InstanceObject) bo;
if (bo instanceof EndToEndFlowInstance) {
return new FlowSegmentReference(io, container);
} else {
return container.getAllDescendants().filter(q -> q.getBusinessObject() == io).findAny().map(q -> new FlowSegmentReference(io, q.getParent())).orElse(null);
}
} else if (bo instanceof FlowImplementation) {
final FlowImplementation fi = (FlowImplementation) bo;
return new FlowSegmentReference(fi, container);
} else if (bo instanceof NamedElement) {
return new FlowSegmentReference((NamedElement) bo, container);
} else {
throw new RuntimeException("Unexpected business object: " + bo);
}
}
use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class CachePropertyAssociationsSwitch method fillPropertyValue.
private void fillPropertyValue(InstanceObject io, PropertyAssociation pa, List<EvaluatedProperty> values) {
PropertyExpression lexp;
List<PropertyExpression> elems;
final Iterator<EvaluatedProperty> valueIter = values.iterator();
final EvaluatedProperty value = valueIter.next();
final List<MpvProxy> proxies = value.getProxies();
for (MpvProxy proxy : proxies) {
ModalPropertyValue newVal = Aadl2Factory.eINSTANCE.createModalPropertyValue();
List<SystemOperationMode> inSOMs = new ArrayList<SystemOperationMode>();
newVal.setOwnedValue(EcoreUtil.copy(proxy.getValue()));
// process list appends
while (valueIter.hasNext()) {
MpvProxy prx = valueIter.next().getProxies().get(0);
if (prx.isModal()) {
throw new InvalidModelException(pa, "Trying to append to a modal list value");
}
lexp = EcoreUtil.copy(prx.getValue());
elems = ((ListValue) lexp).getOwnedListElements();
((ListValue) newVal.getOwnedValue()).getOwnedListElements().addAll(0, elems);
}
boolean valueIsUsed = false;
if (!proxy.isModal()) {
valueIsUsed = true;
pa.getOwnedValues().add(newVal);
} else {
List<Mode> modes = proxy.getModes();
for (Mode mode : modes) {
if (mode instanceof SystemOperationMode) {
inSOMs.add((SystemOperationMode) mode);
} else {
if (io instanceof ConnectionReference) {
List<SystemOperationMode> conniModes = ((ConnectionInstance) io.eContainer()).getInSystemOperationModes();
if (conniModes.isEmpty()) {
conniModes = io.getSystemInstance().getSystemOperationModes();
}
List<ModeInstance> holderModes = ((ConnectionReference) io).getContext().getModeInstances();
for (ModeInstance mi : holderModes) {
if (mi.getMode() == mode) {
for (SystemOperationMode som : conniModes) {
if (som.getCurrentModes().contains(mi)) {
inSOMs.add(som);
}
}
break;
}
}
} else {
List<ModeInstance> holderModes = (io instanceof ComponentInstance) ? ((ComponentInstance) io).getModeInstances() : io.getContainingComponentInstance().getModeInstances();
for (ModeInstance mi : holderModes) {
if (mi.getMode() == mode) {
if (mode2som.containsKey(mi)) {
inSOMs.addAll(mode2som.get(mi));
break;
}
}
}
}
}
}
for (SystemOperationMode som : inSOMs) {
if (io.isActive(som)) {
newVal.getInModes().add(som);
}
}
if (!newVal.getInModes().isEmpty()) {
valueIsUsed = true;
pa.getOwnedValues().add(newVal);
}
}
if (valueIsUsed) {
// replace reference values in the context of the contained PA's owner
for (Iterator<Element> content = EcoreUtil.getAllProperContents(newVal, false); content.hasNext(); ) {
Element elem = content.next();
if (elem instanceof ReferenceValue) {
try {
PropertyExpression irv = ((ReferenceValue) elem).instantiate(io);
if (irv != null) {
EcoreUtil.replace(elem, irv);
}
} catch (InvalidModelException e) {
error(io, e.getMessage());
}
}
}
}
}
}
use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class InstantiateModel method createNewConnection.
/**
* create a copy of the connection instance with the specified indices for the source and the destination
* @param conni
* @param srcIndices
* @param dstIndices
*/
private void createNewConnection(ConnectionInstance conni, List<Long> srcIndices, List<Long> dstIndices) {
LinkedList<String> names = new LinkedList<String>();
LinkedList<Integer> dims = new LinkedList<Integer>();
LinkedList<Integer> sizes = new LinkedList<Integer>();
ConnectionInstance newConn = EcoreUtil.copy(conni);
conni.getContainingComponentInstance().getConnectionInstances().add(newConn);
ConnectionReference topConnRef = Aadl2InstanceUtil.getTopConnectionReference(newConn);
analyzePath(conni.getContainingComponentInstance(), conni.getSource(), names, dims, sizes);
if (srcIndices.size() != sizes.size() && // filter out one side being an element without index (array of 1) (many to one mapping)
!(sizes.size() == 0 && dstIndices.size() == 1)) {
errManager.error(newConn, "Source indices " + srcIndices + " do not match source dimension " + sizes.size());
}
InstanceObject src = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, srcIndices, true);
names.clear();
dims.clear();
sizes.clear();
analyzePath(conni.getContainingComponentInstance(), conni.getDestination(), names, dims, sizes);
if (dstIndices.size() != sizes.size() && // filter out one side being an element without index (array of 1) (many to one mapping)
!(sizes.size() == 0 && dstIndices.size() == 1)) {
errManager.error(newConn, "For " + newConn.getConnectionReferences().get(0).getFullName() + " : " + newConn.getFullName() + ", destination indices " + dstIndices + " do not match destination dimension " + sizes.size());
}
InstanceObject dst = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, dstIndices, false);
if (src == null) {
errManager.error(newConn, "Connection source not found");
}
if (dst == null) {
errManager.error(newConn, "Connection destination not found");
}
String containerPath = conni.getContainingComponentInstance().getInstanceObjectPath();
int len = containerPath.length() + 1;
String srcPath = (src != null) ? src.getInstanceObjectPath() : "Source end not found";
StringBuffer sb = new StringBuffer();
int i = (srcPath.startsWith(containerPath)) ? len : 0;
sb.append(srcPath.substring(i));
sb.append(" --> ");
String dstPath = (dst != null) ? dst.getInstanceObjectPath() : "Destination end not found";
i = (dstPath.startsWith(containerPath)) ? len : 0;
sb.append(dstPath.substring(i));
ConnectionInstance duplicate = (ConnectionInstance) AadlUtil.findNamedElementInList(conni.getContainingComponentInstance().getConnectionInstances(), sb.toString());
if (duplicate != null && duplicate != conni) {
// conni will be removed later
errManager.warning(newConn, "There is already another connection between the same endpoints");
}
newConn.setSource((ConnectionInstanceEnd) src);
newConn.setDestination((ConnectionInstanceEnd) dst);
newConn.setName(sb.toString());
}
use of org.osate.aadl2.instance.InstanceObject in project osate2 by osate.
the class InstantiateModel method createNewConnection.
/**
* create a copy of the connection instance with the specified indices for the source and the destination
* @param conni
* @param srcIndices
* @param dstIndices
* @return
*/
private void createNewConnection(ConnectionInstance conni, ComponentInstance targetComponent) {
LinkedList<Long> indices = new LinkedList<Long>();
LinkedList<String> names = new LinkedList<String>();
LinkedList<Integer> dims = new LinkedList<Integer>();
LinkedList<Integer> sizes = new LinkedList<Integer>();
ConnectionInstance newConn = EcoreUtil.copy(conni);
targetComponent.getConnectionInstances().add(newConn);
ConnectionReference topConnRef = Aadl2InstanceUtil.getTopConnectionReference(newConn);
analyzePath(conni.getContainingComponentInstance(), conni.getSource(), names, dims, sizes, indices);
InstanceObject src = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, indices, true);
names.clear();
dims.clear();
sizes.clear();
indices.clear();
analyzePath(conni.getContainingComponentInstance(), conni.getDestination(), names, dims, sizes, indices);
InstanceObject dst = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, indices, false);
if (src == null) {
errManager.error(newConn, "Connection source not found");
}
if (dst == null) {
errManager.error(newConn, "Connection destination not found");
}
String containerPath = targetComponent.getInstanceObjectPath();
int len = containerPath.length() + 1;
String srcPath = (src != null) ? src.getInstanceObjectPath() : "Source end not found";
StringBuffer sb = new StringBuffer();
int i = (srcPath.startsWith(containerPath)) ? len : 0;
sb.append(srcPath.substring(i));
sb.append(" --> ");
String dstPath = (dst != null) ? dst.getInstanceObjectPath() : "Destination end not found";
i = (dstPath.startsWith(containerPath)) ? len : 0;
sb.append(dstPath.substring(i));
newConn.setSource((ConnectionInstanceEnd) src);
newConn.setDestination((ConnectionInstanceEnd) dst);
newConn.setName(sb.toString());
}
Aggregations