Search in sources :

Example 21 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.

the class TimingPropertyValueHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    final PropertyValueGroup pvg = boc.getBusinessObject(PropertyValueGroup.class).orElseThrow();
    final Object parentBo = boc.getParent() == null ? null : boc.getParent().getBusinessObject();
    // Use default property handler if the BO isn't a connection or connection reference.
    if (!(parentBo instanceof Connection || parentBo instanceof ConnectionReference)) {
        return pvgBoh.getGraphicalConfiguration(ctx);
    }
    final NamedValue namedValue = (NamedValue) pvg.getFirstValueBasedOnCompletelyProcessedAssociation().getValue();
    Graphic graphic = null;
    if (namedValue.getNamedValue() instanceof NamedElement) {
        final NamedElement ne = (NamedElement) namedValue.getNamedValue();
        if (CommunicationProperties.IMMEDIATE.equalsIgnoreCase(ne.getName())) {
            graphic = IMMEDIATE_GRAPHIC;
        } else if (CommunicationProperties.DELAYED.equalsIgnoreCase(ne.getName())) {
            graphic = DELAYED_GRAPHIC;
        }
    }
    if (graphic == null) {
        return Optional.empty();
    }
    return Optional.of(GraphicalConfigurationBuilder.create().graphic(graphic).build());
}
Also used : PropertyValueGroup(org.osate.ge.aadl2.internal.model.PropertyValueGroup) Graphic(org.osate.ge.graphics.Graphic) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) Connection(org.osate.aadl2.Connection) NamedValue(org.osate.aadl2.NamedValue) BusinessObjectContext(org.osate.ge.BusinessObjectContext) NamedElement(org.osate.aadl2.NamedElement)

Example 22 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.

the class AadlPropertyResolver method getProcessedPropertyAssociations.

/**
 * Returns a list of processed property associations for a specific Queryable and property. The property associations order in the list
 * will be such that elements earlier in the list should override elements later in the list.
 * @param q
 * @param property
 * @return
 */
public final List<ProcessedPropertyAssociation> getProcessedPropertyAssociations(final BusinessObjectContext q, final Property property) {
    final PropertyNode pn = getOrCreatePropertyNode(q);
    final ProcessedPropertyAssociationCollection ppas = pn.getCreateProcessedPropertyAssociations(property);
    // Add local property associations to the collection if it does not include them already.
    if (!ppas.includesLocalProperties) {
        Object bo = q.getBusinessObject();
        // Use the connection instance instead of the connection reference.
        bo = bo instanceof ConnectionReference ? ((ConnectionReference) bo).eContainer() : bo;
        if (bo instanceof NamedElement) {
            final NamedElement ne = (NamedElement) bo;
            final PropertyAcc pas = new PropertyAcc(property);
            ne.getPropertyValueInternal(property, pas, true);
            if (pas.getAssociations().size() > 0) {
                for (final PropertyAssociation localPa : pas.getAssociations()) {
                    // processed
                    if (localPa.getAppliesTos().size() == 0) {
                        ppas.processedPropertyAssociations.add(new LocalProcessedPropertyAssociation(localPa));
                    }
                }
            }
        }
        ppas.includesLocalProperties = true;
    }
    return ppas == null || ppas.processedPropertyAssociations == null ? Collections.emptyList() : Collections.unmodifiableList(ppas.processedPropertyAssociations);
}
Also used : PropertyAssociation(org.osate.aadl2.PropertyAssociation) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) PropertyAcc(org.osate.aadl2.properties.PropertyAcc) InstanceObject(org.osate.aadl2.instance.InstanceObject) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 23 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.

the class CreateConnectionsSwitch method fillInModes.

/**
 * For the given connection instance, identify all connection declarations
 * with "in modes." For all possible mode combinations of those "in modes,"
 * add those SOMs that contain the mode instance combinations.
 *
 * @param conni
 *            the connection instance
 */
private void fillInModes(ConnectionInstance conni) {
    ListIterator<ConnectionReference> refIter = conni.getConnectionReferences().listIterator();
    while (refIter.hasNext()) {
        ConnectionReference connRef = refIter.next();
        Connection conn = connRef.getConnection();
        ComponentInstance ci = connRef.getContext();
        List<ModeInstance> mis = null;
        // source modal
        mis = getComponentModes(conni.getSource().getComponentInstance());
        // conns modal
        if (mis == null) {
            var connModes = conn.getAllInModes();
            if (connModes.isEmpty()) {
                mis = getComponentModes(ci);
            } else {
                mis = connModes.stream().map(ci::findModeInstance).collect(Collectors.toList());
            }
        }
        // destination modal
        if (mis == null) {
            mis = getComponentModes(conni.getDestination().getComponentInstance());
        }
        if (mis != null) {
            for (ModeInstance mi : mis) {
                generateModeCombinations(conni, refIter, new ArrayList<>(Collections.singletonList(mi)));
            }
            if (conni.getInSystemOperationModes().isEmpty()) {
                warning(conni.getContainingComponentInstance(), "Connection " + conni.getName() + " was removed because it is not active in any system operation mode");
                EcoreUtil.delete(conni);
            }
            break;
        }
    }
}
Also used : ModeInstance(org.osate.aadl2.instance.ModeInstance) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ParameterConnection(org.osate.aadl2.ParameterConnection) AccessConnection(org.osate.aadl2.AccessConnection) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) Connection(org.osate.aadl2.Connection) PortConnection(org.osate.aadl2.PortConnection) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Example 24 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.

the class CachePropertyAssociationsSwitch method cacheConnectionPropertyAssociations.

protected void cacheConnectionPropertyAssociations(final ConnectionInstance conni) {
    PropertyAssociation setPA;
    PropertyExpression defaultvalue;
    try {
        /*
			 * propertyFilter contains all properties used by the system, so, we try to
			 * use the one associated to the connection instance and their reference and
			 * see if the user declares a specific value.
			 */
        for (Property prop : propertyFilter) {
            setPA = null;
            defaultvalue = prop.getDefaultValue();
            for (final ConnectionReference connRef : conni.getConnectionReferences()) {
                /*
					 * In the following piece of code, we check that a property
					 * is consistent all along the connection reference.
					 * For example, we check that the timing property (immediate, delayed)
					 * is consistent for each connection.
					 */
                if (connRef.acceptsProperty(prop)) {
                    /*
						 * 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.
						 */
                    final PropertyAssociation propAssociation = scProps.retrieveSCProperty(conni, prop, connRef.getConnection());
                    final EvaluationContext ctx = new EvaluationContext(connRef, classifierCache, propAssociation);
                    PropertyEvaluationResult result = prop.evaluate(ctx, 0);
                    List<EvaluatedProperty> evaluated = result.getEvaluated();
                    if (!evaluated.isEmpty()) {
                        PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
                        newPA.setProperty(prop);
                        newPA.setPropertyAssociation(getDeclarativePA(result.getPa()));
                        fillPropertyValue(connRef, newPA, evaluated);
                        if (!newPA.getOwnedValues().isEmpty()) {
                            /*
								 * FIXME JD
								 *
								 * Try to look if the property references a component or not.
								 * This was done to fix the issue related to the Bound Bus analysis plugin
								 */
                            for (Iterator<Element> content = EcoreUtil.getAllProperContents(newPA, false); content.hasNext(); ) {
                                Element elem = content.next();
                                if (elem instanceof ModalPropertyValue) {
                                    ModalPropertyValue mpv = (ModalPropertyValue) elem;
                                    if (mpv.getOwnedValue() instanceof ListValue) {
                                        ListValue lv = (ListValue) mpv.getOwnedValue();
                                        for (Element e : lv.getOwnedListElements()) {
                                            if (e instanceof ReferenceValue) {
                                                PropertyExpression irv = ((ReferenceValue) e).instantiate(conni.getContainingComponentInstance());
                                                if (irv != null) {
                                                    EcoreUtil.replace(e, irv);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (elem instanceof ReferenceValue) {
                                    PropertyExpression irv = ((ReferenceValue) elem).instantiate(conni.getContainingComponentInstance());
                                    if (irv != null) {
                                        EcoreUtil.replace(elem, irv);
                                    }
                                }
                            }
                            scProps.recordSCProperty(conni, prop, connRef.getConnection(), newPA);
                            if (setPA == null) {
                                setPA = newPA;
                                conni.getOwnedPropertyAssociations().add(newPA);
                            } else {
                                // check consistency
                                for (Mode m : conni.getSystemInstance().getSystemOperationModes()) {
                                    PropertyExpression newVal = newPA.valueInMode(m);
                                    PropertyExpression setVal = setPA.valueInMode(m);
                                    if (!newVal.sameAs(setVal)) {
                                        error(conni, "Value for property " + setPA.getProperty().getQualifiedName() + " not consistent along connection");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            checkIfCancelled();
            if (cancelled()) {
                break;
            }
        }
    } catch (IllegalStateException e) {
        // circular dependency
        // xxx: this is a misleading place to put the marker
        error(conni, e.getMessage());
        System.out.println("IllegalStateException raised in cacheConnectionPropertyAssociations");
    } catch (InvalidModelException e) {
        error(conni, e.getMessage());
        System.out.println("InvalidModelException raised in cacheConnectionPropertyAssociations");
    }
}
Also used : PropertyEvaluationResult(org.osate.aadl2.properties.PropertyEvaluationResult) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ReferenceValue(org.osate.aadl2.ReferenceValue) Element(org.osate.aadl2.Element) ListValue(org.osate.aadl2.ListValue) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyAssociationInstance(org.osate.aadl2.instance.PropertyAssociationInstance) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) PropertyExpression(org.osate.aadl2.PropertyExpression) EvaluationContext(org.osate.aadl2.properties.EvaluationContext) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) Property(org.osate.aadl2.Property)

Example 25 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference 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)

Aggregations

ConnectionReference (org.osate.aadl2.instance.ConnectionReference)35 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)20 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)14 Connection (org.osate.aadl2.Connection)12 ConnectionInstanceEnd (org.osate.aadl2.instance.ConnectionInstanceEnd)11 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)7 InstanceObject (org.osate.aadl2.instance.InstanceObject)7 Element (org.osate.aadl2.Element)6 ArrayList (java.util.ArrayList)5 ConnectionEnd (org.osate.aadl2.ConnectionEnd)5 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)5 BasicEList (org.eclipse.emf.common.util.BasicEList)4 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)4 LinkedList (java.util.LinkedList)3 AccessConnection (org.osate.aadl2.AccessConnection)3 Context (org.osate.aadl2.Context)3 Feature (org.osate.aadl2.Feature)3 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)3 Mode (org.osate.aadl2.Mode)3 NamedElement (org.osate.aadl2.NamedElement)3