KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > sitraka > Triggers


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
18 package org.apache.tools.ant.taskdefs.optional.sitraka;
19
20 import java.util.Hashtable JavaDoc;
21 import java.util.Vector JavaDoc;
22 import org.apache.tools.ant.BuildException;
23
24 /**
25  * Trigger information. It will return as a command line argument by calling
26  * the <tt>toString()</tt> method.
27  *
28  */

29 public class Triggers {
30
31     protected Vector JavaDoc triggers = new Vector JavaDoc();
32
33     public Triggers() {
34     }
35
36
37     /**
38      * add a method trigger
39      */

40     public void addMethod(Method method) {
41         triggers.addElement(method);
42     }
43
44     // -jp_trigger=ClassName.*():E:S,ClassName.MethodName():X:X
45
public String JavaDoc toString() {
46         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
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     /**
59      * A trigger for the coverage report
60      */

61     public static class Method {
62         protected String JavaDoc name;
63         protected String JavaDoc event;
64         protected String JavaDoc action;
65         protected String JavaDoc param;
66
67         /**
68          * The name of the method(s) as a regular expression. The name
69          * is the fully qualified name on the form <tt>package.classname.method</tt>
70          * required.
71          */

72         public void setName(String JavaDoc value) {
73             name = value;
74         }
75
76         /**
77          * the event on the method that will trigger the action. Must be
78          * &quot;enter&quot; or &quot;exit&quot;
79          * required.
80          */

81         public void setEvent(String JavaDoc 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         /**
89          * The action to execute; required. Must be one of &quot;clear&quot;,
90          * &quot;pause&quot;, &quot;resume&quot;, &quot;snapshot&quot;, &quot;suspend&quot;,
91          * or &quot;exit&quot;. They respectively clear recording, pause recording,
92          * resume recording, take a snapshot, suspend the recording and exit the program.
93          */

94         public void setAction(String JavaDoc 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         /**
102          * A alphanumeric custom name for the snapshot; optional.
103          */

104         public void setParam(String JavaDoc value) {
105             param = value;
106         }
107
108         // return <name>:<event>:<action>[:param]
109
public String JavaDoc toString() {
110             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
111             buf.append(name).append(":"); //@todo name must not be null, check for it
112
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     /** mapping of actions to cryptic command line mnemonics */
122     private static final Hashtable JavaDoc actionMap = new Hashtable JavaDoc(3);
123
124     /** mapping of events to cryptic command line mnemonics */
125     private static final Hashtable JavaDoc eventMap = new Hashtable JavaDoc(3);
126
127     static {
128         actionMap.put("enter", "E");
129         actionMap.put("exit", "X");
130         // clear|pause|resume|snapshot|suspend|exit
131
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