1 17 18 package org.apache.tools.ant.taskdefs.optional.sitraka; 19 20 import java.util.Hashtable ; 21 import java.util.Vector ; 22 import org.apache.tools.ant.BuildException; 23 24 29 public class Triggers { 30 31 protected Vector triggers = new Vector (); 32 33 public Triggers() { 34 } 35 36 37 40 public void addMethod(Method method) { 41 triggers.addElement(method); 42 } 43 44 public String toString() { 46 StringBuffer buf = new StringBuffer (); 47 final int size = triggers.size(); 48 for (int i = 0; i < size; i++) { 49 buf.append(triggers.elementAt(i).toString()); 50 if (i < size - 1) { 51 buf.append(','); 52 } 53 } 54 return buf.toString(); 55 } 56 57 58 61 public static class Method { 62 protected String name; 63 protected String event; 64 protected String action; 65 protected String param; 66 67 72 public void setName(String value) { 73 name = value; 74 } 75 76 81 public void setEvent(String value) { 82 if (eventMap.get(value) == null) { 83 throw new BuildException("Invalid event, must be one of " + eventMap); 84 } 85 event = value; 86 } 87 88 94 public void setAction(String value) throws BuildException { 95 if (actionMap.get(value) == null) { 96 throw new BuildException("Invalid action, must be one of " + actionMap); 97 } 98 action = value; 99 } 100 101 104 public void setParam(String value) { 105 param = value; 106 } 107 108 public String toString() { 110 StringBuffer buf = new StringBuffer (); 111 buf.append(name).append(":"); buf.append(eventMap.get(event)).append(":"); 113 buf.append(actionMap.get(action)); 114 if (param != null) { 115 buf.append(":").append(param); 116 } 117 return buf.toString(); 118 } 119 } 120 121 122 private static final Hashtable actionMap = new Hashtable (3); 123 124 125 private static final Hashtable eventMap = new Hashtable (3); 126 127 static { 128 actionMap.put("enter", "E"); 129 actionMap.put("exit", "X"); 130 eventMap.put("clear", "C"); 132 eventMap.put("pause", "P"); 133 eventMap.put("resume", "R"); 134 eventMap.put("snapshot", "S"); 135 eventMap.put("suspend", "A"); 136 eventMap.put("exit", "X"); 137 } 138 139 } 140 | Popular Tags |