return new SingletonObjectFactory<T>(type.cast(valueOf.invoke(null, text)));
} catch (IllegalAccessException e) {
throw new AssertionError("getMethod returned an inaccessible method");
} catch (InvocationTargetException e) {
// FIXME we should throw something better
throw new LoaderException(e.getCause());
}
}
} catch (NoSuchMethodException e) {
// try something else
}
// does this type have a constructor that takes a String?
try {
Constructor<T> ctr = type.getConstructor(String.class);
return new SingletonObjectFactory<T>(ctr.newInstance(text));
} catch (NoSuchMethodException e) {
// try something else
} catch (IllegalAccessException e) {
throw new AssertionError("getConstructor returned an inaccessible method");
} catch (InstantiationException e) {
throw new LoaderException("Property type cannot be instantiated: " + type.getName());
} catch (InvocationTargetException e) {
// FIXME we should throw something better
throw new LoaderException(e.getCause());
}
// do we have a property editor for it?
PropertyEditor editor = PropertyEditorManager.findEditor(type);
if (editor != null) {
try {
editor.setAsText(text);
return new SingletonObjectFactory<T>((T) editor.getValue());
} catch (IllegalArgumentException e) {
// FIXME we should throw something better
throw new LoaderException(e);
}
}
// FIXME we should throw something better
throw new LoaderException("Do not have a way to parse a String into a " + type.getName());
}