use of org.osate.aadl2.ComponentType 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.ComponentType 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.ComponentType in project AGREE by loonwerks.
the class VerifyHandler method getComponentImplementation.
protected ComponentImplementation getComponentImplementation(Element root, EphemeralImplementationUtil implUtil) {
Classifier classifier = getOutermostClassifier(root);
if (isRealizability()) {
if (!(classifier instanceof ComponentType)) {
throw new AgreeException("Must select an AADL Component Type");
}
ComponentImplementation result;
try {
result = implUtil.generateEphemeralCompImplFromType((ComponentType) classifier);
} catch (Exception e) {
e.printStackTrace();
throw new AgreeException("Error creating component implementation.");
}
return result;
} else {
if (classifier instanceof ComponentImplementation) {
return (ComponentImplementation) classifier;
}
if (!(classifier instanceof ComponentType)) {
throw new AgreeException("Must select an AADL Component Type or Implementation");
}
ComponentType ct = (ComponentType) classifier;
List<ComponentImplementation> cis = getComponentImplementations(ct);
if (cis.size() == 0) {
throw new AgreeException("AADL Component Type has no implementation to verify");
} else if (cis.size() == 1) {
ComponentImplementation ci = cis.get(0);
Shell shell = getWindow().getShell();
String message = "User selected " + ct.getFullName() + ".\nRunning analysis on " + ci.getFullName() + " instead.";
shell.getDisplay().asyncExec(() -> MessageDialog.openInformation(shell, "Analysis information", message));
return ci;
} else {
throw new AgreeException("AADL Component Type has multiple implementations to verify: please select just one");
}
}
}
use of org.osate.aadl2.ComponentType in project AGREE by loonwerks.
the class VerifyHandler method getComponentImplementations.
private List<ComponentImplementation> getComponentImplementations(ComponentType ct) {
List<ComponentImplementation> result = new ArrayList<>();
AadlPackage pkg = AadlUtil.getContainingPackage(ct);
for (ComponentImplementation ci : EcoreUtil2.getAllContentsOfType(pkg, ComponentImplementation.class)) {
if (ci.getType().equals(ct)) {
result.add(ci);
}
}
return result;
}
use of org.osate.aadl2.ComponentType in project AGREE by loonwerks.
the class MATLABFunctionHandler method setMatlabExportInfo.
private void setMatlabExportInfo(ComponentType ct, ModelInfo info) {
ListValue lv = getOrCreateSourceText(ct);
StringLiteral sl1 = (StringLiteral) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getStringLiteral());
sl1.setValue(savePathToAADLProperty(info.outputDirPath));
StringLiteral sl2 = (StringLiteral) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getStringLiteral());
sl2.setValue(savePathToAADLProperty(info.implMdlPath));
StringLiteral sl3 = (StringLiteral) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getStringLiteral());
sl3.setValue(savePathToAADLProperty(info.verifyMdlName));
StringLiteral sl4 = (StringLiteral) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getStringLiteral());
sl4.setValue(savePathToAADLProperty(info.subsystemName));
}
Aggregations