Search in sources :

Example 51 with InstanceObject

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

Example 52 with InstanceObject

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;
    }
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyEvaluationResult(org.osate.aadl2.properties.PropertyEvaluationResult) PropertyAssociationInstance(org.osate.aadl2.instance.PropertyAssociationInstance) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) EvaluationContext(org.osate.aadl2.properties.EvaluationContext) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) Property(org.osate.aadl2.Property)

Example 53 with InstanceObject

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;
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) NamedElement(org.osate.aadl2.NamedElement) ArrayableElement(org.osate.aadl2.ArrayableElement) ModalElement(org.osate.aadl2.ModalElement) Element(org.osate.aadl2.Element) RefinableElement(org.osate.aadl2.RefinableElement) FlowElement(org.osate.aadl2.FlowElement) ConnectedElement(org.osate.aadl2.ConnectedElement) ThreadSubcomponent(org.osate.aadl2.ThreadSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ThreadGroupSubcomponent(org.osate.aadl2.ThreadGroupSubcomponent) DeviceSubcomponent(org.osate.aadl2.DeviceSubcomponent) ProcessSubcomponent(org.osate.aadl2.ProcessSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) AbstractSubcomponent(org.osate.aadl2.AbstractSubcomponent) ProcessorSubcomponent(org.osate.aadl2.ProcessorSubcomponent) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) Connection(org.osate.aadl2.Connection) NamedElement(org.osate.aadl2.NamedElement)

Example 54 with InstanceObject

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);
    }
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) SystemInstance(org.osate.aadl2.instance.SystemInstance) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode)

Example 55 with InstanceObject

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() + ".");
            }
        }
    }
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) PropertyIsModalException(org.osate.aadl2.properties.PropertyIsModalException) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyAssociation(org.osate.aadl2.PropertyAssociation) SystemInstance(org.osate.aadl2.instance.SystemInstance) PropertyExpression(org.osate.aadl2.PropertyExpression) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode)

Aggregations

InstanceObject (org.osate.aadl2.instance.InstanceObject)77 PropertyExpression (org.osate.aadl2.PropertyExpression)38 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)36 Property (org.osate.aadl2.Property)35 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)31 SystemInstance (org.osate.aadl2.instance.SystemInstance)27 InstanceReferenceValue (org.osate.aadl2.instance.InstanceReferenceValue)24 ArrayList (java.util.ArrayList)19 ListValue (org.osate.aadl2.ListValue)17 NamedElement (org.osate.aadl2.NamedElement)17 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)15 Element (org.osate.aadl2.Element)14 Classifier (org.osate.aadl2.Classifier)13 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)12 List (java.util.List)11 EObject (org.eclipse.emf.ecore.EObject)11 Resource (org.eclipse.emf.ecore.resource.Resource)10 ComponentClassifier (org.osate.aadl2.ComponentClassifier)10 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)10 URI (org.eclipse.emf.common.util.URI)9