The syntax for obtaining array classes using Class.forName is
rather wacked, but it does work. For example, to get the
class for an Object[], use
Class oaClass = Class.forName("[Ljava.lang.Object;");
Both the "[L" prefix and trailing ";" are required.
The javadoc for the Class.getName method describe the syntax
required.
xxxxxxxxxxxxxxxxxxxxxxxx
Scott Stark
Chief Technology Officer
JBoss Group, LLC
xxxxxxxxxxxxxxxxxxxxxxxx
>
> No new feature. Class.forName docs say you can load arrays but it is
> broken. Here is the code I use now:
>
> private Class convertToJavaClass(String name) throws DeploymentException {
> // Check primitive first
> for (int i = 0; i < PRIMITIVES.length; i++) {
> if(name.equals(PRIMITIVES[i])) {
> return PRIMITIVE_CLASSES[i];
> }
> }
>
> int arraySize = 0;
> while(name.endsWith("[]")) {
> name = name.substring(0, name.length()-2);
> arraySize++;
> }
>
> try {
> // get the base class
> Class c = entity.getClassLoader().loadClass(name);
>
> // if we have an array get the array class
> if(arraySize > 0) {
> int[] dimensions = new int[arraySize];
> for(int i=0; i<arraySize; i++) {
> dimensions[i]=1;
> }
> c = Array.newInstance(c, dimensions).getClass();
> }
>
> return c;
> } catch(ClassNotFoundException e) {
> throw new DeploymentException("Parameter class not found: " +
> name);
> }
> }
>
> This is lame but works.
>
> -dain
>
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development