You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2008/05/23 14:19:59 UTC

svn commit: r659513 - /myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/converter/enumeration/EnumConverter.java

Author: imario
Date: Fri May 23 05:19:58 2008
New Revision: 659513

URL: http://svn.apache.org/viewvc?rev=659513&view=rev
Log:
make enum converter work with enum-inheritance

Modified:
    myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/converter/enumeration/EnumConverter.java

Modified: myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/converter/enumeration/EnumConverter.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/converter/enumeration/EnumConverter.java?rev=659513&r1=659512&r2=659513&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/converter/enumeration/EnumConverter.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/converter/enumeration/EnumConverter.java Fri May 23 05:19:58 2008
@@ -49,12 +49,24 @@
 			throw new IllegalArgumentException(value + " do not point to an enum");
 		}
 
-		String clazz = value.substring(0, pos);
+		String className = value.substring(0, pos);
+		Class clazz;
 		int ordinal = Integer.parseInt(value.substring(pos+1), 10);
 
 		try
 		{
-			Enum[] enums = (Enum[]) ClassUtils.classForName(clazz).getEnumConstants();
+			clazz = ClassUtils.classForName(className);
+			// if the clazz is not an enum it might be an enum which is inherited. In this case try to find the superclass.
+			while (clazz != null && !clazz.isEnum())
+			{
+				clazz = clazz.getSuperclass();
+			}
+			if (clazz == null)
+			{
+				throw new IllegalArgumentException("class " + className + " couldn't be treated as enum");
+			}
+
+			Enum[] enums = (Enum[]) clazz.getEnumConstants();
 			if (enums.length >= ordinal)
 			{
 				return enums[ordinal];
@@ -84,4 +96,4 @@
 
 		return e.toString();
 	}
-}
\ No newline at end of file
+}