335 * This method attempts to create an object of the given "type"
336 * using the "value" parameter.
337 * e.g. calling createObjectFromString("java.lang.Integer", "10")
338 * will return an Integer object initialized to 10.
339 */
340 public static Object createObjectFromString(String type, String value)
341 throws Exception {
342 Object result;
343 if (primitiveToWrapper.containsKey(type)) {
344 if (type.equals(Character.TYPE.getName())) {
345 result = new Character(value.charAt(0));
346 } else {
347 result = newStringConstructor(
348 ((Class<?>) primitiveToWrapper.get(type)).getName(),
349 value);
350 }
351 } else if (type.equals(Character.class.getName())) {
352 result = new Character(value.charAt(0));
353 } else if (Number.class.isAssignableFrom(Utils.getClass(type))) {
354 result = createNumberFromStringValue(value);
355 } else if (value == null || value.toString().equals("null")) {
356 // hack for null value
357 result = null;
358 } else {
359 // try to create a Java object using
360 // the one-string-param constructor
361 result = newStringConstructor(type, value);
362 }
363 return result;
364 }
365
366 /**
367 * This method is responsible for converting the inputs given by the user
368 * into a useful object array for passing into a parameter array.
369 */
370 public static Object[] getParameters(XTextField[] inputs, String[] params)
371 throws Exception {
372 Object result[] = new Object[inputs.length];
373 Object userInput;
374 for (int i = 0; i < inputs.length; i++) {
375 userInput = inputs[i].getValue();
|
335 * This method attempts to create an object of the given "type"
336 * using the "value" parameter.
337 * e.g. calling createObjectFromString("java.lang.Integer", "10")
338 * will return an Integer object initialized to 10.
339 */
340 public static Object createObjectFromString(String type, String value)
341 throws Exception {
342 Object result;
343 if (primitiveToWrapper.containsKey(type)) {
344 if (type.equals(Character.TYPE.getName())) {
345 result = new Character(value.charAt(0));
346 } else {
347 result = newStringConstructor(
348 ((Class<?>) primitiveToWrapper.get(type)).getName(),
349 value);
350 }
351 } else if (type.equals(Character.class.getName())) {
352 result = new Character(value.charAt(0));
353 } else if (Number.class.isAssignableFrom(Utils.getClass(type))) {
354 result = createNumberFromStringValue(value);
355 } else if (value == null || value.equals("null")) {
356 // hack for null value
357 result = null;
358 } else {
359 // try to create a Java object using
360 // the one-string-param constructor
361 result = newStringConstructor(type, value);
362 }
363 return result;
364 }
365
366 /**
367 * This method is responsible for converting the inputs given by the user
368 * into a useful object array for passing into a parameter array.
369 */
370 public static Object[] getParameters(XTextField[] inputs, String[] params)
371 throws Exception {
372 Object result[] = new Object[inputs.length];
373 Object userInput;
374 for (int i = 0; i < inputs.length; i++) {
375 userInput = inputs[i].getValue();
|