1 18 19 package cowsultants.itracker.ejb.client.models; 20 21 import java.util.*; 22 23 26 public class ScheduledTaskModel extends GenericModel implements Cloneable { 27 public int[] hours = new int[] { -1 }; 28 public int[] mins = new int[] { -1 }; 29 public int[] mdays = new int[] { -1 }; 30 public int[] months = new int[] { -1 }; 31 public int[] wdays = new int[] { -1 }; 32 public Date lastRun = null; 33 34 public String className = null; 35 public String [] args = new String [0]; 36 37 public ScheduledTaskModel() { 38 } 39 40 public int[] getHours() { 41 return hours; 42 } 43 44 public void setHours(int[] value) { 45 hours = value; 46 } 47 48 public void setHours(String value) { 49 hours = parseString(value); 50 } 51 52 public int[] getMinutes() { 53 return mins; 54 } 55 56 public void setMinutes(int[] value) { 57 mins = value; 58 } 59 60 public void setMinutes(String value) { 61 mins = parseString(value); 62 } 63 64 public int[] getDaysOfMonth() { 65 return mdays; 66 } 67 68 public void setDaysOfMonth(int[] value) { 69 mdays = value; 70 } 71 72 public void setDaysOfMonth(String value) { 73 mdays = parseString(value); 74 } 75 76 public int[] getMonths() { 77 return months; 78 } 79 80 public void setMonths(int[] value) { 81 months = value; 82 } 83 84 public void setMonths(String value) { 85 months = parseString(value); 86 } 87 88 public int[] getWeekdays() { 89 return wdays; 90 } 91 92 public void setWeekdays(int[] value) { 93 wdays = value; 94 } 95 96 public void setWeekdays(String value) { 97 wdays = parseString(value); 98 } 99 100 public Date getLastRun() { 101 return lastRun; 102 } 103 104 public void setLastRun(Date value) { 105 lastRun = value; 106 } 107 108 public String getClassName() { 109 return className; 110 } 111 112 public void setClassName(String value) { 113 className = value; 114 } 115 116 public String [] getArgs() { 117 return args; 118 } 119 120 public void setArgs(String [] value) { 121 args = value; 122 } 123 124 public void setArgs(String value) { 125 if(value != null && ! "".equals(value)) { 126 Vector argsVector = new Vector(); 127 StringTokenizer token = new StringTokenizer(value, " "); 128 while(token.hasMoreElements()) { 129 argsVector.addElement((String ) token.nextElement()); 130 } 131 args = new String [argsVector.size()]; 132 argsVector.copyInto(args); 133 } 134 } 135 136 public String getArgsAsString() { 137 if(args == null || args.length == 0) { 138 return ""; 139 } 140 141 StringBuffer buf = new StringBuffer (); 142 for(int i = 0; i < args.length; i++) { 143 buf.append((i == 0 ? "" : " ")); 144 buf.append(args[i]); 145 } 146 return buf.toString(); 147 } 148 149 155 public int[] parseString(String value) { 156 int[] valuesArray = new int[] { -1 }; 157 158 if(value != null && ! "".equals(value)) { 159 Vector valuesVector = new Vector(); 160 StringTokenizer token = new StringTokenizer(value, ","); 161 while(token.hasMoreElements()) { 162 String element = (String ) token.nextElement(); 163 try { 164 Integer intElement = new Integer (element.trim()); 165 valuesVector.addElement(intElement); 166 } catch(NumberFormatException nfe) { 167 } 168 } 169 valuesArray = new int[valuesVector.size()]; 170 for(int i = 0; i < valuesVector.size(); i++) { 171 valuesArray[i] = ((Integer ) valuesVector.elementAt(i)).intValue(); 172 } 173 } 174 return valuesArray; 175 } 176 177 183 public String joinString(int[] values) { 184 StringBuffer buf = new StringBuffer (); 185 if(values != null) { 186 for(int i = 0; i < values.length; i++) { 187 buf.append((i == 0 ? "" : ",")); 188 buf.append(Integer.toString(values[i])); 189 } 190 } 191 return buf.toString(); 192 } 193 194 public boolean isAll(int[] array) { 195 if(array != null) { 196 for(int i = 0; i < array.length; i++) { 197 if(array[i] == -1) { 198 return true; 199 } 200 } 201 } 202 return false; 203 } 204 205 public Object clone() { 206 Object clone = null; 207 ScheduledTaskModel clonedTask = null; 208 try { 209 clone = super.clone(); 210 } catch(CloneNotSupportedException e) { 211 } 212 213 clonedTask = (ScheduledTaskModel) clone; 214 215 if(clonedTask != null) { 216 if(id != null) { 217 clonedTask.id = new Integer (id.intValue()); 218 } 219 220 if(hours != null) { 221 clonedTask.hours = new int[hours.length]; 222 for(int i = 0; i < hours.length; i++) { 223 clonedTask.hours[i] = hours[i]; 224 } 225 } 226 if(mins != null) { 227 clonedTask.mins = new int[mins.length]; 228 for(int i = 0; i < mins.length; i++) { 229 clonedTask.mins[i] = mins[i]; 230 } 231 } 232 if(mdays != null) { 233 clonedTask.mdays = new int[mdays.length]; 234 for(int i = 0; i < mdays.length; i++) { 235 clonedTask.mdays[i] = mdays[i]; 236 } 237 } 238 if(months != null) { 239 clonedTask.months = new int[months.length]; 240 for(int i = 0; i < months.length; i++) { 241 clonedTask.months[i] = months[i]; 242 } 243 } 244 if(wdays != null) { 245 clonedTask.wdays = new int[wdays.length]; 246 for(int i = 0; i < wdays.length; i++) { 247 clonedTask.wdays[i] = wdays[i]; 248 } 249 } 250 251 if(className != null) { 252 clonedTask.className = new String (className); 253 } 254 if(args != null) { 255 clonedTask.args = new String [args.length]; 256 for(int i = 0; i < args.length; i++) { 257 clonedTask.args[i] = args[i]; 258 } 259 } 260 261 if(lastRun != null) { 262 clonedTask.lastRun = (Date) lastRun.clone(); 263 } 264 } 265 return clonedTask; 266 } 267 268 public String toString() { 269 return "Id: " + getId() + " Class: " + getClassName(); 270 } 271 } 272 | Popular Tags |