Search in sources :

Example 56 with SystemInstance

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

the class InstantiateModel method rebuildAllInstanceModelFiles.

/*
	 * This method will regenerate all instance models in the workspace
	 */
public static void rebuildAllInstanceModelFiles(final IProgressMonitor monitor) throws Exception {
    HashSet<IFile> files = TraverseWorkspace.getInstanceModelFilesInWorkspace();
    List<URI> instanceRoots = new ArrayList<URI>();
    List<IResource> instanceIResources = new ArrayList<IResource>();
    ResourceSet rset = new ResourceSetImpl();
    for (IFile iFile : files) {
        IResource ires = iFile;
        ires.deleteMarkers(null, true, IResource.DEPTH_INFINITE);
        Resource res = rset.getResource(OsateResourceUtil.toResourceURI(ires), true);
        SystemInstance target = (SystemInstance) res.getContents().get(0);
        ComponentImplementation ci = target.getComponentImplementation();
        URI uri = EcoreUtil.getURI(ci);
        instanceRoots.add(uri);
        instanceIResources.add(ires);
        res.getContents().clear();
        res.save(null);
        res.unload();
    }
    for (int i = 0; i < instanceRoots.size(); i++) {
        ComponentImplementation ci = (ComponentImplementation) rset.getEObject(instanceRoots.get(i), true);
        monitor.subTask("Reinstantiating " + ci.getName());
        final InstantiateModel instantiateModel = new InstantiateModel(new NullProgressMonitor(), new AnalysisErrorReporterManager(new MarkerAnalysisErrorReporter.Factory(AadlConstants.INSTANTIATION_OBJECT_MARKER)));
        Resource res = rset.getResource(OsateResourceUtil.toResourceURI(instanceIResources.get(i)), true);
        instantiateModel.createSystemInstance(ci, res);
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) InstanceFactory(org.osate.aadl2.instance.InstanceFactory) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) SystemInstance(org.osate.aadl2.instance.SystemInstance) IResource(org.eclipse.core.resources.IResource)

Example 57 with SystemInstance

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

the class InstantiateModel method fillModes.

private void fillModes(ComponentInstance ci, List<Mode> modes) throws InterruptedException {
    for (Mode m : modes) {
        if (monitor.isCanceled()) {
            throw new InterruptedException();
        }
        ModeInstance mi = InstanceFactory.eINSTANCE.createModeInstance();
        /*
			 * Used to add the mode instance to the component instance at the end of the loop,
			 * but moved it here so that we can report errors on it.
			 */
        ci.getModeInstances().add(mi);
        mi.setMode(m);
        mi.setName(m.getName());
        mi.setInitial(m.isInitial());
        /*
			 * If ci is the root object, ignore derived. This means that we are instantiating an implementation that
			 * contains derived modes. In this case, treat the derived modes as normal modes since there is no
			 * containing component to provide a parent mode.
			 */
        if (m.isDerived() && !(ci instanceof SystemInstance)) {
            mi.setDerived(true);
            Subcomponent sub = ci.getSubcomponent();
            ComponentInstance parentci = ci.getContainingComponentInstance();
            final EList<ModeBinding> ownedModeBindings = sub.getOwnedModeBindings();
            if (ownedModeBindings == null || ownedModeBindings.isEmpty()) {
                // Implicit mode map, must find modes of the same name in the containing component
                ModeInstance foundParentMode = null;
                for (ModeInstance pmi : parentci.getModeInstances()) {
                    if (pmi.getName().equalsIgnoreCase(m.getName())) {
                        foundParentMode = pmi;
                        break;
                    }
                }
                if (foundParentMode == null) {
                    errManager.error(mi, "Required mode '" + m.getName() + "' not found in containing component");
                } else {
                    mi.getParents().add(foundParentMode);
                }
            } else {
                for (ModeBinding mb : ownedModeBindings) {
                    if (monitor.isCanceled()) {
                        throw new InterruptedException();
                    }
                    if (mb.getDerivedMode() == m || mb.getDerivedMode() == null && mb.getParentMode().getName().equalsIgnoreCase(m.getName())) {
                        mi.getParents().add(parentci.findModeInstance(mb.getParentMode()));
                    }
                }
            }
        }
    }
}
Also used : ModeInstance(org.osate.aadl2.instance.ModeInstance) SystemInstance(org.osate.aadl2.instance.SystemInstance) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ModeBinding(org.osate.aadl2.ModeBinding)

Example 58 with SystemInstance

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

the class InstantiateModel method processConnections.

// --------------------------------------------------------------------------------------------
// Methods for connection sets and connection patterns
// --------------------------------------------------------------------------------------------
private void processConnections(SystemInstance root) throws InterruptedException {
    if (monitor.isCanceled()) {
        throw new InterruptedException();
    }
    EList<ComponentInstance> replicateConns = new UniqueEList<ComponentInstance>();
    List<ConnectionInstance> toRemove = new ArrayList<ConnectionInstance>();
    EList<ConnectionInstance> connilist = root.getAllConnectionInstances();
    for (ConnectionInstance conni : connilist) {
        // track all component instances that contain connection instances
        replicateConns.add(conni.getComponentInstance());
        PropertyAssociation setPA = getPA(conni, "Connection_Set");
        PropertyAssociation patternPA = getPA(conni, "Connection_Pattern");
        if (setPA == null && patternPA == null) {
            // OsateDebug.osateDebug("[InstantiateModel] processConnections");
            LinkedList<Integer> srcDims = new LinkedList<Integer>();
            LinkedList<Integer> dstDims = new LinkedList<Integer>();
            LinkedList<Integer> srcSizes = new LinkedList<Integer>();
            LinkedList<Integer> dstSizes = new LinkedList<Integer>();
            boolean done = false;
            analyzePath(conni.getContainingComponentInstance(), conni.getSource(), null, srcDims, srcSizes);
            analyzePath(conni.getContainingComponentInstance(), conni.getDestination(), null, dstDims, dstSizes);
            for (int d : srcDims) {
                if (d != 0) {
                    done = true;
                    if (interpretConnectionPatterns(conni, false, null, 0, srcSizes, 0, dstSizes, 0, new ArrayList<Long>(), new ArrayList<Long>())) {
                        toRemove.add(conni);
                    }
                    break;
                }
            }
            if (!done) {
                for (int d : dstDims) {
                    if (d != 0) {
                        done = true;
                        if (interpretConnectionPatterns(conni, false, null, 0, srcSizes, 0, dstSizes, 0, new ArrayList<Long>(), new ArrayList<Long>())) {
                            toRemove.add(conni);
                        }
                        break;
                    }
                }
            }
        } else if (patternPA != null) {
            boolean isOpposite = Aadl2InstanceUtil.isOpposite(conni);
            EcoreUtil.remove(patternPA);
            List<PropertyExpression> patterns = ((ListValue) patternPA.getOwnedValues().get(0).getOwnedValue()).getOwnedListElements();
            for (PropertyExpression pe : patterns) {
                List<PropertyExpression> pattern = ((ListValue) pe).getOwnedListElements();
                LinkedList<Integer> srcSizes = new LinkedList<Integer>();
                LinkedList<Integer> dstSizes = new LinkedList<Integer>();
                analyzePath(conni.getContainingComponentInstance(), conni.getSource(), null, null, srcSizes);
                analyzePath(conni.getContainingComponentInstance(), conni.getDestination(), null, null, dstSizes);
                if (srcSizes.size() == 0 && dstSizes.size() == 0) {
                    errManager.warning(conni, "Connection pattern specified for connection that does not connect array elements.");
                } else {
                    if (interpretConnectionPatterns(conni, isOpposite, pattern, 0, srcSizes, 0, dstSizes, 0, new ArrayList<Long>(), new ArrayList<Long>())) {
                        toRemove.add(conni);
                    }
                }
            }
        }
        // no else as we want both the pattern and the connection set evaluated
        if (setPA != null) {
            EcoreUtil.remove(setPA);
            // TODO-LW: modal conn set allowed?
            List<Long> srcIndices;
            List<Long> dstIndices;
            for (PropertyExpression pe : ((ListValue) setPA.getOwnedValues().get(0).getOwnedValue()).getOwnedListElements()) {
                RecordValue rv = (RecordValue) pe;
                srcIndices = getIndices(rv, "src");
                dstIndices = getIndices(rv, "dst");
                if (Aadl2InstanceUtil.isOpposite(conni)) {
                    // flip indices since we are going in the opposite direction
                    createNewConnection(conni, dstIndices, srcIndices);
                } else {
                    createNewConnection(conni, srcIndices, dstIndices);
                }
            }
            toRemove.add(conni);
        }
    }
    for (ConnectionInstance conni : toRemove) {
        EcoreUtil.delete(conni);
    }
    replicateConnections(replicateConns);
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) UniqueEList(org.eclipse.emf.common.util.UniqueEList) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ListValue(org.osate.aadl2.ListValue) ArrayList(java.util.ArrayList) RecordValue(org.osate.aadl2.RecordValue) LinkedList(java.util.LinkedList) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ArrayList(java.util.ArrayList) UniqueEList(org.eclipse.emf.common.util.UniqueEList) List(java.util.List) LinkedList(java.util.LinkedList) EList(org.eclipse.emf.common.util.EList) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 59 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance 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 60 with SystemInstance

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

SystemInstance (org.osate.aadl2.instance.SystemInstance)100 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)52 InstanceObject (org.osate.aadl2.instance.InstanceObject)26 ComponentImplementation (org.osate.aadl2.ComponentImplementation)25 Element (org.osate.aadl2.Element)25 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)22 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)21 Classifier (org.osate.aadl2.Classifier)18 ForAllElement (org.osate.aadl2.modelsupport.modeltraversal.ForAllElement)18 ComponentCategory (org.osate.aadl2.ComponentCategory)17 NamedElement (org.osate.aadl2.NamedElement)16 List (java.util.List)14 Resource (org.eclipse.emf.ecore.resource.Resource)14 AadlPackage (org.osate.aadl2.AadlPackage)14 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)14 ArrayList (java.util.ArrayList)13 EList (org.eclipse.emf.common.util.EList)13 IOException (java.io.IOException)12 IStatus (org.eclipse.core.runtime.IStatus)12 Optional (java.util.Optional)10