commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jon Steelman" <>
Subject RE: [Digester] enums in ConvertUtils.register
Date Wed, 15 Jun 2005 08:30:57 GMT
I wrote the following code that works on jdk1.5 *and* I expect to be
backwards compatible to jdk1.1:

public Object checkForEnum(String stringValue, Class clazz) {
    Class superclass = clazz.getSuperclass();
    System.out.println("superClass = " + superclass);
    if (superclass.getName().equals("java.lang.Enum")) {
        // Only makes it here if the jdk is 1.5+ and class is an enum
        Method valueOf = null;
        try {
            valueOf = clazz.getMethod("valueOf",new Class[]
        catch (NoSuchMethodException e) {
            // Should never get here! All enums have this dynamic method
        Object enm = null;
        try {
            enm = valueOf.invoke(null,new Object[]{stringValue});
        catch (IllegalAccessException e) {
            // Should never get here as the method is always public.
        catch (InvocationTargetException e) {
            // Should never get here as the target object is 
		// null thanks to method being static/
        // IllegalArgumentException is possible when the 
        return enm;

Can it be incorporated?


-----Original Message-----
From: Simon Kitching [] 
Sent: Wednesday, June 15, 2005 3:45 AM
To: Jakarta Commons Users List
Subject: RE: [Digester] enums in ConvertUtils.register

On Wed, 2005-06-15 at 03:19 -0400, Jon Steelman wrote:
> However, it brings up the point that ConvertUtils.convert(String,
> should automatically handle the case of the Class is an enum by using
> the enum's built in valueOf(String) method so that a custom Converter
> not required. Is this the forum to make that suggestion?

Yes, this is definitely the right place to discuss things like this.

The problem is that if we add that code to beanutils then beanutils will
no longer work in pre-1.5 jvms. Offhand I can't think of a reasonable
way to support 1.5 enums without breaking earlier java versions. And
having separate versions of beanutils for the two java platforms would
be a major nuisance.

Any ideas how this could be implemented?



To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message