]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/refaktor-after/src/no/uio/ifi/refaktor/change/SingleExecutionExecutorManager.java
Some talks, mostly identical.
[ifi-stolz-refaktor.git] / case-study / refaktor-after / src / no / uio / ifi / refaktor / change / SingleExecutionExecutorManager.java
1 package no.uio.ifi.refaktor.change;
2
3 import no.uio.ifi.refaktor.change.exceptions.ExecutorManagerInitializationException;
4 import no.uio.ifi.refaktor.change.exceptions.SingleExecutionViolationException;
5 import no.uio.ifi.refaktor.change.executors.Executor;
6
7 import org.eclipse.core.runtime.CoreException;
8 import org.eclipse.core.runtime.IProgressMonitor;
9
10 public class SingleExecutionExecutorManager implements ExecutorManager {
11         private Executor executor;
12         private boolean isExecuted;
13
14         public SingleExecutionExecutorManager() {
15                 this(null);
16         }
17         
18         public SingleExecutionExecutorManager(Executor executor) {
19                 setExecutor(executor);
20         }
21
22         @Override
23         public void setExecutor(Executor executor) {
24                 this.executor = executor;
25                 isExecuted = false;
26         }
27
28         @Override
29         public void executeChange(IProgressMonitor monitor) throws CoreException {
30                 if (executor == null)
31                         throw new ExecutorManagerInitializationException(this.getClass().getSimpleName() + ": No executor set!");
32
33                 if (isExecuted)
34                         throw new SingleExecutionViolationException("The change can only be executed once!");
35
36                 executor.execute(monitor);
37                 markAsExecuted();
38         }
39
40         private void markAsExecuted() {
41                 isExecuted = true;
42         }
43 }