Search in sources :

Example 1 with XMIHelperImpl

use of org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl in project statecharts by Yakindu.

the class ShadowModelValidationJob method cloneResource.

protected void cloneResource(final IProgressMonitor monitor, final Resource shadowResource) throws ExecutionException {
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(TransactionUtil.getEditingDomain(resource), "", null) {

        @Override
        protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            try {
                XMISaveImpl saver = new XMISaveImpl(new XMIHelperImpl((XMLResource) resource));
                saver.save((XMLResource) resource, bout, Collections.emptyMap());
                bout.flush();
            } catch (Throwable t) {
                return CommandResult.newErrorCommandResult(t.getMessage());
            }
            return CommandResult.newOKCommandResult();
        }
    };
    cmd.execute(monitor, null);
    try {
        shadowResource.load(new ByteArrayInputStream(bout.toByteArray()), Collections.emptyMap());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) XMIHelperImpl(org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) XMISaveImpl(org.eclipse.emf.ecore.xmi.impl.XMISaveImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) AbstractTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)1 XMIHelperImpl (org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl)1 XMISaveImpl (org.eclipse.emf.ecore.xmi.impl.XMISaveImpl)1 AbstractTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand)1