Search in sources :

Example 86 with InstanceObject

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);
        }
    }
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) RefinableElement(org.osate.aadl2.RefinableElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) Property(org.osate.aadl2.Property)

Example 87 with InstanceObject

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);
    }
}
Also used : FlowSegment(org.osate.aadl2.FlowSegment) FlowSpecification(org.osate.aadl2.FlowSpecification) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) EndToEndFlowInstance(org.osate.aadl2.instance.EndToEndFlowInstance) Objects(java.util.Objects) Stream(java.util.stream.Stream) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext) FlowImplementation(org.osate.aadl2.FlowImplementation) FlowElement(org.osate.aadl2.FlowElement) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) NamedElement(org.osate.aadl2.NamedElement) EndToEndFlow(org.osate.aadl2.EndToEndFlow) InstanceObject(org.osate.aadl2.instance.InstanceObject) InstanceObject(org.osate.aadl2.instance.InstanceObject) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) FlowElement(org.osate.aadl2.FlowElement) FlowImplementation(org.osate.aadl2.FlowImplementation) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) EndToEndFlowInstance(org.osate.aadl2.instance.EndToEndFlowInstance) FlowSegment(org.osate.aadl2.FlowSegment) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) NamedElement(org.osate.aadl2.NamedElement)

Example 88 with InstanceObject

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());
                    }
                }
            }
        }
    }
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ModeInstance(org.osate.aadl2.instance.ModeInstance) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) ReferenceValue(org.osate.aadl2.ReferenceValue) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Element(org.osate.aadl2.Element) ArrayList(java.util.ArrayList) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) InvalidModelException(org.osate.aadl2.properties.InvalidModelException) MpvProxy(org.osate.aadl2.properties.EvaluatedProperty.MpvProxy) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 89 with InstanceObject

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());
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) LinkedList(java.util.LinkedList)

Example 90 with InstanceObject

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());
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) LinkedList(java.util.LinkedList)

Aggregations

InstanceObject (org.osate.aadl2.instance.InstanceObject)71 PropertyExpression (org.osate.aadl2.PropertyExpression)38 Property (org.osate.aadl2.Property)35 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)35 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)31 InstanceReferenceValue (org.osate.aadl2.instance.InstanceReferenceValue)24 SystemInstance (org.osate.aadl2.instance.SystemInstance)22 ListValue (org.osate.aadl2.ListValue)17 NamedElement (org.osate.aadl2.NamedElement)17 ArrayList (java.util.ArrayList)16 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)15 Classifier (org.osate.aadl2.Classifier)13 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)12 Element (org.osate.aadl2.Element)11 ComponentClassifier (org.osate.aadl2.ComponentClassifier)10 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)10 BasicProperty (org.osate.aadl2.BasicProperty)9 PropertyLookupException (org.osate.aadl2.properties.PropertyLookupException)9 List (java.util.List)8 Subcomponent (org.osate.aadl2.Subcomponent)8