use of org.eclipse.emf.transaction.TransactionalCommandStack in project AGREE by loonwerks.
the class EphemeralImplementationUtil method cleanup.
/**
* Delete the accumulated ephemeral component implementations by deleting their containing {@link Resource}.
* <p>
* This method is intended to be called immediately prior to the instance of this utility going out of scope.
* However, it may be called multiple times, deleting the ephemeral implementations and resource accumulated to
* that point.
*/
public void cleanup() {
final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
// We execute this command on the command stack because otherwise, we will not
// have write permissions on the editing domain.
Command cmd = new RecordingCommand(domain) {
@Override
protected void doExecute() {
try {
Iterator<Resource> iter = ephemeralResources.iterator();
while (iter.hasNext()) {
Resource res = iter.next();
res.delete(Collections.EMPTY_MAP);
iter.remove();
}
} catch (IOException e) {
setErrorMessage(e.getMessage());
e.printStackTrace();
}
}
};
try {
((TransactionalCommandStack) domain.getCommandStack()).execute(cmd, null);
} catch (InterruptedException | RollbackException e) {
setErrorMessage(e.getMessage());
e.printStackTrace();
}
}
use of org.eclipse.emf.transaction.TransactionalCommandStack in project AGREE by loonwerks.
the class EphemeralImplementationUtil method generateEphemeralCompImplFromType.
/**
* Generate an ephemeral {@link ComponentImplementation} matching the subtype of the given {@link ComponentType}.
* <p>
* Ephemerally generated component implementations 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 component implementation for the given component type.
* @throws Exception
*/
@SuppressWarnings("unchecked")
public ComponentImplementation generateEphemeralCompImplFromType(ComponentType ct) throws Exception {
// Resource aadlResource = OsateResourceUtil.getResource(getEphemeralImplURI(ct));
Resource aadlResource = getResource(getEphemeralImplURI(ct));
ephemeralResources.add(aadlResource);
List<ComponentImplementation> resultList;
ComponentImplementation result;
final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
// We execute this command on the command stack because otherwise, we will not
// have write permissions on the editing domain.
Command cmd = new RecordingCommand(domain) {
public ComponentImplementation implementation;
@Override
protected void doExecute() {
try {
implementation = createComponentImplementationInternal(ct, aadlResource);
} catch (InterruptedException e) {
// Do nothing. Will be thrown after execute.
}
}
@Override
public List<ComponentImplementation> getResult() {
return Collections.singletonList(implementation);
}
};
((TransactionalCommandStack) domain.getCommandStack()).execute(cmd, 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");
aadlResource.save(null);
} catch (IOException e) {
e.printStackTrace();
setErrorMessage(e.getMessage());
return null;
}
resultList = (List<ComponentImplementation>) cmd.getResult();
result = resultList.get(0);
return result;
}
use of org.eclipse.emf.transaction.TransactionalCommandStack 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.eclipse.emf.transaction.TransactionalCommandStack 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;
}
Aggregations