1 27 28 package org.objectweb.clif.scenario.util.transitions; 29 30 import java.util.Properties ; 31 import java.util.StringTokenizer ; 32 33 public class Transition { 34 35 private String id; 36 private String [] args; 38 private boolean isEndSession = false; 39 private Properties prop; 40 41 private StringTokenizer st; 42 private int nbTokens; 43 private String parsedId; 44 45 46 public Transition() { 47 } 48 49 53 public void setTransition(String transition) { 54 if (transition == null) 55 isEndSession = true; 56 else { 57 isEndSession = false; 58 st = new StringTokenizer (transition, ";"); 59 nbTokens = st.countTokens(); 60 61 id = st.nextToken(); 62 64 args = new String [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 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 { 85 return Class.forName(getIdClass(id)).getDeclaredField( 86 getIdField(id)).getInt( 87 null); 88 } 89 90 } catch (Exception 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 [] getAction() { 99 return args; 100 } 101 102 106 113 public boolean isEndSession() { 114 return isEndSession; 115 } 116 117 private String getIdClass(String id) { 118 return id.substring(0, id.lastIndexOf(".")); 119 } 120 121 private String getIdField(String id) { 122 return id.substring(id.lastIndexOf(".") + 1, id.length()); 123 } 124 125 public void setProperties(Properties prop) { 126 this.prop = prop; 127 } 128 } 129 | Popular Tags |