use of org.osate.aadl2.instantiation.InstantiateModel in project AGREE by loonwerks.
the class EphemeralImplementationUtil method generateEphemeralCompInstanceFromImplementation.
/**
* Generate an ephemeral {@link SystemInstance} matching the subtype of the given {@link ComponentType}.
* <p>
* Ephemerally generated system instances are placed it in an ephemeral {@link Resource}. The ephemeral
* resources are intended to have short lifecycles and deleted by the {@link cleanup} method.
*
* @param ct The component type for which to create an ephemeral implementation.
* @return A system instance for the given component type.
* @throws Exception
* @since 2.8
*/
@SuppressWarnings("unchecked")
public SystemInstance generateEphemeralCompInstanceFromImplementation(ComponentImplementation ci) throws Exception {
final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
Resource instanceAadlResource = getResource(InstantiateModel.getInstanceModelURI(ci));
ephemeralResources.add(instanceAadlResource);
List<SystemInstance> instanceResultList;
SystemInstance instanceResult;
// We execute this command on the command stack because otherwise, we will not
// have write permissions on the editing domain.
Command instanceCmd = new RecordingCommand(domain) {
public SystemInstance systemInstance;
@Override
protected void doExecute() {
try {
final InstantiateModel instantiateModel = new InstantiateModel(monitor, new AnalysisErrorReporterManager(new MarkerAnalysisErrorReporter.Factory(AadlConstants.INSTANTIATION_OBJECT_MARKER)));
systemInstance = instantiateModel.createSystemInstance(ci, instanceAadlResource);
} catch (InterruptedException e) {
// Do nothing. Will be thrown after execute.
} catch (Exception e) {
e.printStackTrace();
errorMessage = e.getMessage();
e.getMessage();
}
}
@Override
public List<SystemInstance> getResult() {
return Collections.singletonList(systemInstance);
}
};
((TransactionalCommandStack) domain.getCommandStack()).execute(instanceCmd, null);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
try {
// We're done: Save the model.
monitor.subTask("Saving instance model");
instanceAadlResource.save(null);
} catch (IOException e) {
e.printStackTrace();
setErrorMessage(e.getMessage());
return null;
}
instanceResultList = (List<SystemInstance>) instanceCmd.getResult();
instanceResult = instanceResultList.get(0);
return instanceResult;
}
use of org.osate.aadl2.instantiation.InstantiateModel in project AGREE by loonwerks.
the class EphemeralImplementationUtil method generateEphemeralCompInstanceFromType.
/**
* Generate an ephemeral {@link SystemInstance} matching the subtype of the given {@link ComponentType}.
* <p>
* Ephemerally generated system instances are placed it in an ephemeral {@link Resource}. The ephemeral
* resources are intended to have short lifecycles and deleted by the {@link cleanup} method.
*
* @param ct The component type for which to create an ephemeral implementation.
* @return A system instance for the given component type.
* @throws Exception
* @since 2.8
*/
@SuppressWarnings("unchecked")
public SystemInstance generateEphemeralCompInstanceFromType(ComponentType ct) throws Exception {
Resource implementationAadlResource = getResource(getEphemeralImplURI(ct));
ephemeralResources.add(implementationAadlResource);
List<ComponentImplementation> implementationResultList;
ComponentImplementation implementationResult;
final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
Command implementationCmd = new RecordingCommand(domain) {
public ComponentImplementation implementation;
@Override
protected void doExecute() {
try {
implementation = createComponentImplementationInternal(ct, implementationAadlResource);
} catch (InterruptedException e) {
// Do nothing. Will be thrown after execute.
}
}
@Override
public List<ComponentImplementation> getResult() {
return Collections.singletonList(implementation);
}
};
((TransactionalCommandStack) domain.getCommandStack()).execute(implementationCmd, null);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
try {
// We're done: Save the model.
// We don't respond to a cancel at this point
monitor.subTask("Saving implementation model");
implementationAadlResource.save(null);
} catch (IOException e) {
e.printStackTrace();
setErrorMessage(e.getMessage());
return null;
}
implementationResultList = (List<ComponentImplementation>) implementationCmd.getResult();
implementationResult = implementationResultList.get(0);
Resource instanceAadlResource = getResource(InstantiateModel.getInstanceModelURI(implementationResult));
ephemeralResources.add(instanceAadlResource);
List<SystemInstance> instanceResultList;
SystemInstance instanceResult;
// We execute this command on the command stack because otherwise, we will not
// have write permissions on the editing domain.
Command instanceCmd = new RecordingCommand(domain) {
public SystemInstance systemInstance;
@Override
protected void doExecute() {
try {
final InstantiateModel instantiateModel = new InstantiateModel(monitor, new AnalysisErrorReporterManager(new MarkerAnalysisErrorReporter.Factory(AadlConstants.INSTANTIATION_OBJECT_MARKER)));
systemInstance = instantiateModel.createSystemInstance(implementationResult, instanceAadlResource);
} catch (InterruptedException e) {
// Do nothing. Will be thrown after execute.
} catch (Exception e) {
e.printStackTrace();
errorMessage = e.getMessage();
e.getMessage();
}
}
@Override
public List<SystemInstance> getResult() {
return Collections.singletonList(systemInstance);
}
};
((TransactionalCommandStack) domain.getCommandStack()).execute(instanceCmd, null);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
try {
// We're done: Save the model.
monitor.subTask("Saving instance model");
instanceAadlResource.save(null);
} catch (IOException e) {
e.printStackTrace();
setErrorMessage(e.getMessage());
return null;
}
instanceResultList = (List<SystemInstance>) instanceCmd.getResult();
instanceResult = instanceResultList.get(0);
return instanceResult;
}
use of org.osate.aadl2.instantiation.InstantiateModel in project osate2 by osate.
the class InstantiateModel method rebuildInstanceModelFile.
/**
* This method will construct an instance model, save it on disk and return
* its root object The method will make sure the declarative models are up
* to date.
*
* @param si system implementation
*
* @return SystemInstance or <code>null</code> if cancelled.
* @since 1.1
*/
public static SystemInstance rebuildInstanceModelFile(final IResource ires, final IProgressMonitor monitor) throws Exception {
ires.deleteMarkers(null, true, IResource.DEPTH_INFINITE);
ResourceSet rset = new ResourceSetImpl();
Resource res = rset.getResource(OsateResourceUtil.toResourceURI(ires), true);
SystemInstance target = (SystemInstance) res.getContents().get(0);
ComponentImplementation ci = target.getComponentImplementation();
URI uri = EcoreUtil.getURI(ci);
res.getContents().clear();
res.save(null);
res.unload();
ci = (ComponentImplementation) rset.getEObject(uri, true);
if (ci == null) {
// The root component instance doesn't exist anymore
throw new RootMissingException();
}
final InstantiateModel instantiateModel = new InstantiateModel(monitor, new AnalysisErrorReporterManager(new MarkerAnalysisErrorReporter.Factory(AadlConstants.INSTANTIATION_OBJECT_MARKER)));
SystemInstance root = instantiateModel.createSystemInstance(ci, res);
return root;
}
use of org.osate.aadl2.instantiation.InstantiateModel 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.instantiation.InstantiateModel 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);
}
Aggregations