Skip to content

Method: KommandoMitExceptionOhneResultat()

1: package schnittstelle.kommandoArchitektur;
2:
3: /**
4: * Kommando Klasse ohne Resultat aber mit möglicher Exception.
5: *
6: * @param <E>
7: * Typ der möglichen exceptions welche ausgelöst werden können.
8: */
9: public abstract class KommandoMitExceptionOhneResultat<E extends Exception> extends Kommando {
10:         
11:         private E exception;
12:         
13:         @SuppressWarnings("unchecked")
14:         // TODO Art: unidentified; es kann nichts anderes fliegen, als ein E, das versteht der Java-Compiler aber scheinbar nicht so gut...
15:         @Override
16:         protected void executeCommand() {
17:                 try {
18:                         this.doIt();
19:                 } catch (final Exception e) {
20:                         this.exception = (E) e;
21:                 }
22:         }
23:         
24:         /**
25:          * Löst eine Exception aus, wenn diese beim Ausführen des Kommandos entstanden ist.
26:          *
27:          * @throws E
28:          * Exception welche ausgelöst werden kann.
29:          */
30:         public void getResultat() throws E {
31:                 // TODO Art: Feature request; um Nebenläufigkeit zu ermöglichen, muss hier das "executed" geprüft werden.
32:                 if (this.exception != null) {
33:                         throw this.exception;
34:                 }
35:         }
36:         
37:         /**
38:          *
39:          * Diese Operation definiert was genau passieren soll, wenn das Kommando ausgeführt wird. Zusätzlich auch wann eine
40:          * Ausnahme ausgelöst werden soll.
41:          *
42:          * @throws E
43:          * Exception welche auftreten kann.
44:          */
45:         protected abstract void doIt() throws E;
46: }