dain 2003/09/04 21:48:44
Modified: modules/common/src/java/org/apache/geronimo/common
Classes.java
Log:
Added support for user friendly array syntax like this some.array.Class[][][]
Revision Changes Path
1.5 +22 -3
incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/Classes.java
Index: Classes.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/Classes.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Classes.java 5 Sep 2003 02:33:56 -0000 1.4
+++ Classes.java 5 Sep 2003 04:48:44 -0000 1.5
@@ -57,7 +57,6 @@
package org.apache.geronimo.common;
import java.beans.PropertyEditor;
-import java.beans.PropertyEditorManager;
import java.io.File;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
@@ -70,6 +69,7 @@
import java.util.Map;
import org.apache.commons.lang.ClassUtils;
+import org.apache.geronimo.common.propertyeditor.PropertyEditors;
/**
* A collection of <code>Class</code> utilities.
@@ -368,6 +368,25 @@
return Array.newInstance(type, dim).getClass();
}
+ // Handle user friendly type[] syntax
+ if (className.endsWith("[]")) {
+ // get the base component class name and the arrayDimensions
+ int arrayDimension = 0;
+ String componentClassName = className;
+ while (componentClassName.endsWith("[]")) {
+ componentClassName = componentClassName.substring(0,
className.length() - 2);
+ arrayDimension++;
+ }
+
+ // load the base type
+ type = loadClass(componentClassName, classLoader);
+
+ // return the array type
+ int[] dim = new int[arrayDimension];
+ java.util.Arrays.fill(dim, 0);
+ return Array.newInstance(type, dim).getClass();
+ }
+
// Else we can not load (give up)
throw new ClassNotFoundException(className);
}
@@ -410,7 +429,7 @@
public static Object getValue(Class type, String value) {
// try a property editor
- PropertyEditor editor = PropertyEditorManager.findEditor(type);
+ PropertyEditor editor = PropertyEditors.findEditor(type);
if (editor != null) {
editor.setAsText(value);
return editor.getValue();