package no.uio.ifi.refaktor.change; import no.uio.ifi.refaktor.change.exceptions.ExecutorManagerInitializationException; import no.uio.ifi.refaktor.change.exceptions.SingleExecutionViolationException; import no.uio.ifi.refaktor.change.executors.Executor; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; public class SingleExecutionExecutorManager implements ExecutorManager { private Executor executor; private boolean isExecuted; public SingleExecutionExecutorManager() { this(null); } public SingleExecutionExecutorManager(Executor executor) { setExecutor(executor); } @Override public void setExecutor(Executor executor) { this.executor = executor; isExecuted = false; } @Override public void executeChange(IProgressMonitor monitor) throws CoreException { if (executor == null) throw new ExecutorManagerInitializationException(this.getClass().getSimpleName() + ": No executor set!"); if (isExecuted) throw new SingleExecutionViolationException("The change can only be executed once!"); executor.execute(monitor); markAsExecuted(); } private void markAsExecuted() { isExecuted = true; } }