267 extraNumericalTypes.contains(type)) {
268 return "0";
269 }
270 if (booleanTypes.contains(type)) {
271 return "true";
272 }
273 type = getReadableClassName(type);
274 int i = type.lastIndexOf('.');
275 if (i > 0) {
276 return type.substring(i + 1, type.length());
277 } else {
278 return type;
279 }
280 }
281
282 /**
283 * Try to create a Java object using a one-string-param constructor.
284 */
285 public static Object newStringConstructor(String type, String param)
286 throws Exception {
287 Constructor c = Utils.getClass(type).getConstructor(String.class);
288 try {
289 return c.newInstance(param);
290 } catch (InvocationTargetException e) {
291 Throwable t = e.getTargetException();
292 if (t instanceof Exception) {
293 throw (Exception) t;
294 } else {
295 throw e;
296 }
297 }
298 }
299
300 /**
301 * Try to convert a string value into a numerical value.
302 */
303 private static Number createNumberFromStringValue(String value)
304 throws NumberFormatException {
305 final String suffix = value.substring(value.length() - 1);
306 if ("L".equalsIgnoreCase(suffix)) {
307 return Long.valueOf(value.substring(0, value.length() - 1));
|
267 extraNumericalTypes.contains(type)) {
268 return "0";
269 }
270 if (booleanTypes.contains(type)) {
271 return "true";
272 }
273 type = getReadableClassName(type);
274 int i = type.lastIndexOf('.');
275 if (i > 0) {
276 return type.substring(i + 1, type.length());
277 } else {
278 return type;
279 }
280 }
281
282 /**
283 * Try to create a Java object using a one-string-param constructor.
284 */
285 public static Object newStringConstructor(String type, String param)
286 throws Exception {
287 Constructor<?> c = Utils.getClass(type).getConstructor(String.class);
288 try {
289 return c.newInstance(param);
290 } catch (InvocationTargetException e) {
291 Throwable t = e.getTargetException();
292 if (t instanceof Exception) {
293 throw (Exception) t;
294 } else {
295 throw e;
296 }
297 }
298 }
299
300 /**
301 * Try to convert a string value into a numerical value.
302 */
303 private static Number createNumberFromStringValue(String value)
304 throws NumberFormatException {
305 final String suffix = value.substring(value.length() - 1);
306 if ("L".equalsIgnoreCase(suffix)) {
307 return Long.valueOf(value.substring(0, value.length() - 1));
|