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);
}
}
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()));
}
}
}
}
}
}
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);
}
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);
}
}
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() + ".");
}
}
}
}
Aggregations