1 package cz.cuni.amis.pogamut.sposh.engine; 2 3 /** 4 * Result of ElementExecutors, it specified how should be drive stack modified. 5 * Only FOLLOW requires specification of nextElement. 6 * 7 * @author Honza 8 */ 9 public final class FireResult { 10 11 /** 12 * Value returned by the executor of an element on the stack, it determines 13 * how should drive stack be modified. 14 */ 15 public enum Type { 16 17 /** 18 * The element is finished and result is success. 19 */ 20 FULFILLED, 21 /** 22 * The element is finished and it failed. 23 */ 24 FAILED, 25 /** 26 * Element wasn't yet finished. 27 */ 28 CONTINUE, 29 /** 30 * Some child element is supposed to be evaluated. 31 */ 32 FOLLOW, 33 /** 34 * Well, not many will use this I suppose, but move up in the stack, 35 * something like return from function. This is the only type that 36 * causes the sposh logic controller to stop iterating. If {@link PoshEngine#evaluatePlan(cz.cuni.amis.pogamut.sposh.executor.IWorkExecutor) 37 * } returns any other value, the sposh logic controller will call 38 * another round of {@link PoshEngine#evaluatePlan(cz.cuni.amis.pogamut.sposh.executor.IWorkExecutor)} 39 */ 40 SURFACE, 41 /** 42 * E.g. surface (pop element on the stack), but also indicates that 43 * execution should continue. 44 */ 45 SURFACE_CONTINUE, 46 } 47 private Type type; 48 private StackElement nextElement; 49 50 /** 51 * Create result for modification of stack, the {@link #getNextElement() } 52 * is null. 53 * 54 * @param type How should be stack modified, not {@link Type#FOLLOW}. 55 */ 56 protected FireResult(Type type) { 57 this(type, null); 58 } 59 60 /** 61 * Create structure saying how the should be the drive stack modified. 62 * 63 * Example: Follow + some element of stack will result in stack of drive 64 * adding the elemnet of stack on the top of the stack. 65 * 66 * @param type How should be stack of drive modified. 67 * @param nextElement What should {@link #getNextElement() } be. 68 */ 69 protected FireResult(Type type, StackElement nextElement) { 70 this.type = type; 71 this.nextElement = nextElement; 72 } 73 74 /** 75 * @return How should stack be modified? 76 */ 77 public Type getType() { 78 return type; 79 } 80 81 /** 82 * Get element that should be put at the top of the stack. This method can 83 * be called only if {@link #getType() } is {@link Type#FOLLOW}. 84 * 85 * @return the nextElement that be added to the top of the stack 86 */ 87 public StackElement getNextElement() { 88 assert (nextElement != null) : "NextElement is null, type of FireResult should be such, that we never ask for it (is " + getType() + ")"; 89 return nextElement; 90 } 91 }