1 28 29 30 package org.objectweb.jonas.newbean; 31 32 33 import org.apache.velocity.VelocityContext; 34 35 36 39 public class ParameterSet { 40 41 private Parameter beanNameParameter = null; 42 private Parameter beanFlavorParameter = null; 43 private Parameter sessionTypeParameter = null; 44 private Parameter persistenceManagerParameter = null; 45 private Parameter isLocalParameter = null; 46 private Parameter pkgNameParameter = null; 47 private Parameter jarNameParameter = null; 48 private Parameter pkClassParameter = null; 49 50 51 55 public ParameterSet(VelocityContext context) { 56 57 61 beanNameParameter = new Parameter(context) { 62 63 public String getPrompt() { 64 return "Bean Name"; 65 } 66 67 public String getArgKeyword() 68 { 69 return "-beanName"; 70 } 71 72 public boolean isValid() { 73 return (value.length() > 0); 74 } 75 76 public void export() { 77 vContext.put("beanName", value); 78 } 79 80 public Parameter getNextParameter() { 81 return beanFlavorParameter; 82 } 83 84 }; 85 86 87 91 beanFlavorParameter = new Parameter(context) { 92 93 private final Integer SESSION_BEAN = new Integer (0); 94 private final Integer ENTITY_BEAN = new Integer (1); 95 private final Integer MESSAGE_DRIVEN_BEAN = new Integer (2); 96 97 public String getPrompt() { 98 return "Bean type\n S Session bean\n E Entity bean\n MD Message-Driven bean"; 99 } 100 101 public String getArgKeyword() 102 { 103 return "-beanType"; 104 } 105 106 public void setValue(String input) { 107 value = input.toUpperCase(); 108 } 109 110 public boolean isValid() { 111 return (value.equals("S") 112 || value.equals("E") 113 || value.equals("MD")); 114 } 115 116 public void export() { 117 vContext.put("SESSION_BEAN", SESSION_BEAN); 118 vContext.put("ENTITY_BEAN", ENTITY_BEAN); 119 vContext.put("MESSAGE_DRIVEN_BEAN", MESSAGE_DRIVEN_BEAN); 120 Integer beanFlavor = null; 121 String beanType = null; 122 if (value.equals("S")) { 123 beanFlavor = SESSION_BEAN; 124 beanType = "S"; 125 } 126 else if (value.equals("E")) { 127 beanFlavor = ENTITY_BEAN; 128 beanType = "E"; 129 } 130 else if (value.equals("MD")) { 131 beanFlavor = MESSAGE_DRIVEN_BEAN; 132 beanType = "MD"; 133 } 134 vContext.put("beanFlavor", beanFlavor); 135 vContext.put("beanType", beanType); 136 } 137 138 public Parameter getNextParameter() { 139 Integer beanFlavor = (Integer )vContext.get("beanFlavor"); 140 if (beanFlavor == SESSION_BEAN) { 141 return sessionTypeParameter; 142 } 143 else if (beanFlavor == ENTITY_BEAN) { 144 return persistenceManagerParameter; 145 } 146 return pkgNameParameter; 147 } 148 149 }; 150 151 152 156 sessionTypeParameter = new Parameter(context) { 157 158 private final Integer STATELESS = new Integer (0); 159 private final Integer STATEFUL = new Integer (1); 160 161 public String getPrompt() { 162 return "Session type\n L Staless\n F Stateful"; 163 } 164 165 public String getArgKeyword() 166 { 167 return "-sessionType"; 168 } 169 170 public void setValue(String input) { 171 value = input.toUpperCase(); 172 } 173 174 public boolean isValid() { 175 return (value.equals("L") 176 || value.equals("F")); 177 } 178 179 public void export() { 180 vContext.put("STATELESS", STATELESS); 181 vContext.put("STATEFUL", STATEFUL); 182 Integer sessionType = null; 183 String beanType = (String )vContext.get("beanType"); 184 if (value.equals("L")) { 185 sessionType = STATELESS; 186 beanType += "L"; 187 } 188 else if (value.equals("F")) { 189 sessionType = STATEFUL; 190 beanType += "F"; 191 } 192 vContext.put("sessionType", sessionType); 193 vContext.put("beanType", beanType); 194 } 195 196 public Parameter getNextParameter() { 197 return isLocalParameter; 198 } 199 200 }; 201 202 203 207 persistenceManagerParameter = new Parameter(context) { 208 209 private final Integer BMP = new Integer (0); 210 private final Integer CMP1 = new Integer (1); 211 private final Integer CMP2 = new Integer (2); 212 213 public String getPrompt() { 214 return "Persistance manager\n B BMP\n C CMP 1.x\n C2 CMP 2.x"; 215 } 216 217 public String getArgKeyword() 218 { 219 return "-persistence"; 220 } 221 222 public void setValue(String input) { 223 value = input.toUpperCase(); 224 } 225 226 public boolean isValid() { 227 return (value.equals("C") 228 || value.equals("B") 229 || value.equals("C2")); 230 } 231 232 public void export() { 233 vContext.put("CMP1", CMP1); 234 vContext.put("CMP2", CMP2); 235 vContext.put("BMP", BMP); 236 Integer persistenceManager = null; 237 238 String beanType = (String )vContext.get("beanType"); 239 if (value.equals("C")) { 240 persistenceManager = CMP1; 241 beanType += "C"; 242 } 243 else if (value.equals("B")) { 244 persistenceManager = BMP; 245 beanType += "B"; 246 } 247 else if (value.equals("C2")) { 248 persistenceManager = CMP2; 249 beanType += "C2"; 250 } 251 vContext.put("persistenceManager", persistenceManager); 252 vContext.put("beanType", beanType); 253 } 254 255 public Parameter getNextParameter() { 256 return isLocalParameter; 257 } 258 259 }; 260 261 262 266 isLocalParameter = new Parameter(context) { 267 268 private final Boolean FALSE = Boolean.FALSE; 269 private final Boolean TRUE = Boolean.TRUE; 270 271 public String getPrompt() { 272 return "Bean location\n R Remote\n L Local"; 273 } 274 275 public String getArgKeyword() 276 { 277 return "-location"; 278 } 279 280 public void setValue(String input) { 281 value = input.toUpperCase(); 282 } 283 284 public boolean isValid() { 285 return (value.equals("R") 286 || value.equals("L")); 287 } 288 289 public void export() { 290 Boolean isLocal = null; 291 String beanType = (String )vContext.get("beanType"); 292 if (value.equals("L")) { 293 isLocal = TRUE; 294 beanType += "L"; 295 } 296 else if (value.equals("R")) { 297 isLocal = FALSE; 298 beanType += "R"; 299 } 300 vContext.put("isLocal", isLocal); 301 vContext.put("beanType", beanType); 302 } 303 304 public Parameter getNextParameter() { 305 return pkgNameParameter; 306 } 307 308 }; 309 310 311 315 pkgNameParameter = new Parameter(context) { 316 317 public String getPrompt() { 318 return "Package name"; 319 } 320 321 public String getArgKeyword() 322 { 323 return "-pkgName"; 324 } 325 326 public boolean isValid() { 327 return (value.length() > 0); 328 } 329 330 public void export() { 331 vContext.put("pkgName", value); 332 } 333 334 public Parameter getNextParameter() { 335 return jarNameParameter; 336 } 337 338 }; 339 340 341 345 jarNameParameter = new Parameter(context) { 346 347 public String getPrompt() { 348 return "Jar name"; 349 } 350 351 public String getArgKeyword() 352 { 353 return "-jarName"; 354 } 355 356 public void setValue(String input) { 357 if (input.endsWith(".jar")) { 358 value = input.substring(0, input.length() - 4); 359 } 360 else { 361 value = input; 362 } 363 } 364 365 public boolean isValid() { 366 return (value.length() > 0); 367 } 368 369 public void export() { 370 vContext.put("jarName", value); 371 } 372 373 public Parameter getNextParameter() { 374 final Integer ENTITY_BEAN = 375 (Integer )vContext.get("ENTITY_BEAN"); 376 Integer beanFlavor = 377 (Integer )vContext.get("beanFlavor"); 378 if (beanFlavor == ENTITY_BEAN) 379 return pkClassParameter; 380 else 381 return null; 382 } 383 384 }; 385 386 387 391 pkClassParameter = new Parameter(context) { 392 393 public String getPrompt() { 394 return "Primary Key class\n S String\n I Integer\n O Object"; 395 } 396 397 public String getArgKeyword() 398 { 399 return "-primaryKey"; 400 } 401 402 public void setValue(String input) { 403 value = input.toUpperCase(); 404 } 405 406 public boolean isValid() { 407 return (value.equals("S") 408 || value.equals("I") 409 || value.equals("O")); 410 } 411 412 public void export() { 413 String pkClass = null; 414 if (value.equals("S")) 415 pkClass = "java.lang.String"; 416 else if (value.equals("I")) 417 pkClass = "java.lang.Integer"; 418 else if (value.equals("O")) 419 pkClass = "java.lang.Object"; 420 vContext.put("pkClass", pkClass); 421 } 422 423 public Parameter getNextParameter() { 424 return null; 425 } 426 427 }; 428 429 } 430 431 432 436 public void walkThrough() { 437 beanNameParameter.walkThrough(); 438 } 439 440 } 441 | Popular Tags |