KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > transitions > Transition


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2003 France Telecom R&D
4 * Copyright (C) 2003 INRIA
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * CLIF $Name: $
21 *
22 * Contact: clif@objectweb.org
23 *
24 * @authors: Julien Buret
25 * @authors: Nicolas Droze
26 */

27
28 package org.objectweb.clif.scenario.util.transitions;
29
30 import java.util.Properties JavaDoc;
31 import java.util.StringTokenizer JavaDoc;
32
33 public class Transition {
34
35     private String JavaDoc id;
36     //private String action;
37
private String JavaDoc[] args;
38     private boolean isEndSession = false;
39     private Properties JavaDoc prop;
40
41     private StringTokenizer JavaDoc st;
42     private int nbTokens;
43     private String JavaDoc parsedId;
44
45     
46     public Transition() {
47     }
48
49     /**
50      * Set the transition and parse the parameters: id, action, and optional arguments.
51      * @param transition The complete String from the matrix.
52      */

53     public void setTransition(String JavaDoc transition) {
54         if (transition == null)
55             isEndSession = true;
56         else {
57             isEndSession = false;
58             st = new StringTokenizer JavaDoc(transition, ";");
59             nbTokens = st.countTokens();
60
61             id = st.nextToken();
62             //action = st.nextToken();
63

64             args = new String JavaDoc[nbTokens - 1];
65
66             for (int i = 0; i < nbTokens - 1; i++) {
67                 args[i] = st.nextToken();
68             }
69         }
70     }
71
72     public int getId() {
73         try {
74             // The ID begins with $, it is a variable
75
// We replace the variable with its value from the properties
76
if (id.indexOf("$") == 0) {
77                 parsedId = prop.getProperty(id.substring(1, id.length()));
78                 return Class
79                     .forName(getIdClass(parsedId))
80                     .getDeclaredField(getIdField(parsedId))
81                     .getInt(null);
82             }
83             // Else the ID is written entirely and we parse the string
84
else {
85                 return Class.forName(getIdClass(id)).getDeclaredField(
86                     getIdField(id)).getInt(
87                     null);
88             }
89
90         } catch (Exception JavaDoc e) {
91             System.out.println(
92                 "Error parsing data: A value maybe incorrect or not defined: ");
93             e.printStackTrace();
94             return -1;
95         }
96     }
97
98     public String JavaDoc[] getAction() {
99         return args;
100     }
101
102 /* public String[] getArgs() {
103         return args;
104     }
105 */

106 /* public int getNbArgs() {
107         if (args == null)
108             return 0;
109         else
110             return args.length;
111     }
112 */

113     public boolean isEndSession() {
114         return isEndSession;
115     }
116
117     private String JavaDoc getIdClass(String JavaDoc id) {
118         return id.substring(0, id.lastIndexOf("."));
119     }
120
121     private String JavaDoc getIdField(String JavaDoc id) {
122         return id.substring(id.lastIndexOf(".") + 1, id.length());
123     }
124
125     public void setProperties(Properties JavaDoc prop) {
126         this.prop = prop;
127     }
128 }
129
Popular Tags