Author: clement
Date: Fri Jun 18 08:20:36 2010
New Revision: 955881
URL: http://svn.apache.org/viewvc?rev=955881&view=rev
Log:
FELIX-2420
Support Enum, in the configuration handler. The object is created by calling
valueOf with the given String.
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java?rev=955881&r1=955880&r2=955881&view=diff
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
Fri Jun 18 08:20:36 2010
@@ -21,6 +21,7 @@ package org.apache.felix.ipojo.util;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.ConfigurationException;
@@ -365,6 +366,25 @@ public class Property implements FieldIn
if (type.isArray()) {
return createArrayObject(type.getComponentType(),
ParseUtils.parseArrays(strValue));
}
+
+ // Enum :
+ if (type.getSuperclass() != null &&
type.getSuperclass().getName().equals("java.lang.Enum")) {
+ try {
+ Method valueOf = type.getMethod("valueOf", new Class[]
{String.class});
+ if (! valueOf.isAccessible()) {
+ valueOf.setAccessible(true);
+ }
+ // Invoke the static method
+ return valueOf.invoke(null, new String[] {strValue});
+ } catch (InvocationTargetException e) {
+ throw new ConfigurationException("Cannot create an enumerated
value for " + type
+ + " with " + strValue + " : " +
e.getTargetException());
+ } catch (Exception e) {
+ throw new ConfigurationException("Cannot create an enumerated
value for " + type
+ + " with " + strValue + " : " + e.getMessage());
+ }
+ }
+
// Else it is a neither a primitive type neither a String -> create
// the object by calling a constructor with a string in argument.
try {