1. /*
  2. * Copyright 2001-2002,2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs.optional.sitraka;
  18. import java.util.Hashtable;
  19. import java.util.Vector;
  20. import org.apache.tools.ant.BuildException;
  21. /**
  22. * Trigger information. It will return as a command line argument by calling
  23. * the <tt>toString()</tt> method.
  24. *
  25. */
  26. public class Triggers {
  27. protected Vector triggers = new Vector();
  28. public Triggers() {
  29. }
  30. /**
  31. * add a method trigger
  32. */
  33. public void addMethod(Method method) {
  34. triggers.addElement(method);
  35. }
  36. // -jp_trigger=ClassName.*():E:S,ClassName.MethodName():X:X
  37. public String toString() {
  38. StringBuffer buf = new StringBuffer();
  39. final int size = triggers.size();
  40. for (int i = 0; i < size; i++) {
  41. buf.append(triggers.elementAt(i).toString());
  42. if (i < size - 1) {
  43. buf.append(',');
  44. }
  45. }
  46. return buf.toString();
  47. }
  48. /**
  49. * A trigger for the coverage report
  50. */
  51. public static class Method {
  52. protected String name;
  53. protected String event;
  54. protected String action;
  55. protected String param;
  56. /**
  57. * The name of the method(s) as a regular expression. The name
  58. * is the fully qualified name on the form <tt>package.classname.method</tt>
  59. * required.
  60. */
  61. public void setName(String value) {
  62. name = value;
  63. }
  64. /**
  65. * the event on the method that will trigger the action. Must be
  66. * "enter" or "exit"
  67. * required.
  68. */
  69. public void setEvent(String value) {
  70. if (eventMap.get(value) == null) {
  71. throw new BuildException("Invalid event, must be one of " + eventMap);
  72. }
  73. event = value;
  74. }
  75. /**
  76. * The action to execute; required. Must be one of "clear",
  77. * "pause", "resume", "snapshot", "suspend",
  78. * or "exit". They respectively clear recording, pause recording,
  79. * resume recording, take a snapshot, suspend the recording and exit the program.
  80. */
  81. public void setAction(String value) throws BuildException {
  82. if (actionMap.get(value) == null) {
  83. throw new BuildException("Invalid action, must be one of " + actionMap);
  84. }
  85. action = value;
  86. }
  87. /**
  88. * A alphanumeric custom name for the snapshot; optional.
  89. */
  90. public void setParam(String value) {
  91. param = value;
  92. }
  93. // return <name>:<event>:<action>[:param]
  94. public String toString() {
  95. StringBuffer buf = new StringBuffer();
  96. buf.append(name).append(":"); //@todo name must not be null, check for it
  97. buf.append(eventMap.get(event)).append(":");
  98. buf.append(actionMap.get(action));
  99. if (param != null) {
  100. buf.append(":").append(param);
  101. }
  102. return buf.toString();
  103. }
  104. }
  105. /** mapping of actions to cryptic command line mnemonics */
  106. private static final Hashtable actionMap = new Hashtable(3);
  107. /** mapping of events to cryptic command line mnemonics */
  108. private static final Hashtable eventMap = new Hashtable(3);
  109. static {
  110. actionMap.put("enter", "E");
  111. actionMap.put("exit", "X");
  112. // clear|pause|resume|snapshot|suspend|exit
  113. eventMap.put("clear", "C");
  114. eventMap.put("pause", "P");
  115. eventMap.put("resume", "R");
  116. eventMap.put("snapshot", "S");
  117. eventMap.put("suspend", "A");
  118. eventMap.put("exit", "X");
  119. }
  120. }