Re: [JBoss-dev] Loading array class object by name

2002-02-25 Thread Neale Swinnerton

On Sun, Feb 24, 2002 at 09:42:21PM -0600, Dain Sundstrom wrote:
 Thanks Scott.  I thought I tried that one...
 
 Now do you know an easy way to convert java.lang.object[] or whatever to 
 the signature style [Ljava.lang.Object; (other then string 
 manipulation)?  Otherwise, I'll write a conversion function.

Hi,

There are some utils to do this included with apache's BCEL, I've submitted
a patch to replace the org.jboss.proxy.compiler.* (#519626) which uses them
a bit. 

If you do implement a conversion function you should note that Class.getName()
is inconsistent in behaviour (and IMHO doesn't behave as documented) wrt 
primitive types. There is a bug on bug parade (#4369208) which raises the
inconsistency javadoc - implementation. 

The 'problem' is that e.g. Class.getName(Character.TYPE) returns char rather
than C



-- 
regards


Neale Swinnerton


 
 -dain
 
 Scott M Stark wrote:
 
  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;);

___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



[JBoss-dev] Loading array class object by name

2002-02-24 Thread Dain Sundstrom

Hi all,

I need to load the java.lang.Class object for an array by name.  I have 
tried the following:

Class.forName(name, true, entity.getClassLoader());

Where name is java.lang.Object[], and I get a ClassNotFoundException.

Any ideas?

-dain


___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



Re: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Jason Dillon

What is the value for name you are using?

Why not just use Class.class?

Or if you really want to use Class.forName to load Class, then you 
should be able to use the system class loader.

Is this after yesterdays Server/ServerLoader change?

--jason


Dain Sundstrom wrote:

 Hi all,

 I need to load the java.lang.Class object for an array by name.  I 
 have tried the following:

 Class.forName(name, true, entity.getClassLoader());

 Where name is java.lang.Object[], and I get a ClassNotFoundException.

 Any ideas?

 -dain


 ___
 Jboss-development mailing list
 [EMAIL PROTECTED]
 https://lists.sourceforge.net/lists/listinfo/jboss-development




___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



Re: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Dain Sundstrom



Jason Dillon wrote:

 What is the value for name you are using?


In my test code java.lang.Object[]

 
 Why not just use Class.class?


Because I am trying to load a parameter type from an xml file that

just has the string name of the type.



 Or if you really want to use Class.forName to load Class, then you 
 should be able to use the system class loader.


 Is this after yesterdays Server/ServerLoader change?


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; iarraySize; 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



Re: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Jason Dillon

Try loading [Ljava.lang.Object; instead... which is the class name 
returned from Object[].class.getName();

--jason


Dain Sundstrom wrote:



 Jason Dillon wrote:

 What is the value for name you are using?



 In my test code java.lang.Object[]


 Why not just use Class.class?



 Because I am trying to load a parameter type from an xml file that

 just has the string name of the type.



 Or if you really want to use Class.forName to load Class, then you 
 should be able to use the system class loader.



 Is this after yesterdays Server/ServerLoader change?



 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; iarraySize; 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



Re: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Dain Sundstrom

Doesn't work.  I tried [Ljava/lang/Object; and both without the semicolon.

-dain

Jason Dillon wrote:

 Try loading [Ljava.lang.Object; instead... which is the class name 
 returned from Object[].class.getName();
 
 --jason
 
 
 Dain Sundstrom wrote:
 


 Jason Dillon wrote:

 What is the value for name you are using?




 In my test code java.lang.Object[]


 Why not just use Class.class?




 Because I am trying to load a parameter type from an xml file that

 just has the string name of the type.



 Or if you really want to use Class.forName to load Class, then you 
 should be able to use the system class loader.




 Is this after yesterdays Server/ServerLoader change?




 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; iarraySize; 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



Re: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Scott M Stark

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.


Scott Stark
Chief Technology Officer
JBoss Group, LLC


 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; iarraySize; 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



Re: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Jason Dillon

Hrm... did you try using ClassLoader.getSystemClassLoader() ?

--jason


Dain Sundstrom wrote:

 Doesn't work.  I tried [Ljava/lang/Object; and both without the 
 semicolon.

 -dain

 Jason Dillon wrote:

 Try loading [Ljava.lang.Object; instead... which is the class name 
 returned from Object[].class.getName();

 --jason


 Dain Sundstrom wrote:



 Jason Dillon wrote:

 What is the value for name you are using?





 In my test code java.lang.Object[]


 Why not just use Class.class?





 Because I am trying to load a parameter type from an xml file that

 just has the string name of the type.



 Or if you really want to use Class.forName to load Class, then you 
 should be able to use the system class loader.





 Is this after yesterdays Server/ServerLoader change?





 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; iarraySize; 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



RE: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Dean Jennings

try java.lang.reflect.Array class. On it is a newInstance Method which take
a class type.

-Original Message-
From: Dain Sundstrom [mailto:[EMAIL PROTECTED]]
Sent: Monday, 25 February 2002 12:09
To: Jason Dillon
Cc: JBoss-dev
Subject: Re: [JBoss-dev] Loading array class object by name


Doesn't work.  I tried [Ljava/lang/Object; and both without the semicolon.

-dain

Jason Dillon wrote:

 Try loading [Ljava.lang.Object; instead... which is the class name 
 returned from Object[].class.getName();
 
 --jason
 
 
 Dain Sundstrom wrote:
 


 Jason Dillon wrote:

 What is the value for name you are using?




 In my test code java.lang.Object[]


 Why not just use Class.class?




 Because I am trying to load a parameter type from an xml file that

 just has the string name of the type.



 Or if you really want to use Class.forName to load Class, then you 
 should be able to use the system class loader.




 Is this after yesterdays Server/ServerLoader change?




 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; iarraySize; 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

___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



Re: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Jason Dillon

Oh ya... can you load java.lang.Object or java.lang.Class?  If so then 
there shouldn't be a cl issue.

--jason


Dean Jennings wrote:

try java.lang.reflect.Array class. On it is a newInstance Method which take
a class type.

-Original Message-
From: Dain Sundstrom [mailto:[EMAIL PROTECTED]]
Sent: Monday, 25 February 2002 12:09
To: Jason Dillon
Cc: JBoss-dev
Subject: Re: [JBoss-dev] Loading array class object by name


Doesn't work.  I tried [Ljava/lang/Object; and both without the semicolon.

-dain

Jason Dillon wrote:

Try loading [Ljava.lang.Object; instead... which is the class name 
returned from Object[].class.getName();

--jason


Dain Sundstrom wrote:


Jason Dillon wrote:

What is the value for name you are using?




In my test code java.lang.Object[]


Why not just use Class.class?




Because I am trying to load a parameter type from an xml file that

just has the string name of the type.



Or if you really want to use Class.forName to load Class, then you 
should be able to use the system class loader.



Is this after yesterdays Server/ServerLoader change?




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; iarraySize; 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




___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



RE: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Dean Jennings

What has to happen is you need a Class.forName or however you are trying to
load the class into the clasloader. Then afterward you instanstiate an Array
of that class type by using java.lang.reflect.Array.newInstance(class, x)
where x is your dimensions. So to answer your question it uses a
java.lang.Class.

-Original Message-
From: Jason Dillon [mailto:[EMAIL PROTECTED]]
Sent: Monday, 25 February 2002 12:27
To: Dean Jennings
Cc: 'Dain Sundstrom'; JBoss-dev
Subject: Re: [JBoss-dev] Loading array class object by name


Oh ya... can you load java.lang.Object or java.lang.Class?  If so then 
there shouldn't be a cl issue.

--jason


Dean Jennings wrote:

try java.lang.reflect.Array class. On it is a newInstance Method which take
a class type.

-Original Message-
From: Dain Sundstrom [mailto:[EMAIL PROTECTED]]
Sent: Monday, 25 February 2002 12:09
To: Jason Dillon
Cc: JBoss-dev
Subject: Re: [JBoss-dev] Loading array class object by name


Doesn't work.  I tried [Ljava/lang/Object; and both without the semicolon.

-dain

Jason Dillon wrote:

Try loading [Ljava.lang.Object; instead... which is the class name 
returned from Object[].class.getName();

--jason


Dain Sundstrom wrote:


Jason Dillon wrote:

What is the value for name you are using?




In my test code java.lang.Object[]


Why not just use Class.class?




Because I am trying to load a parameter type from an xml file that

just has the string name of the type.



Or if you really want to use Class.forName to load Class, then you 
should be able to use the system class loader.



Is this after yesterdays Server/ServerLoader change?




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; iarraySize; 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




___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



Re: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Dain Sundstrom

Thanks Scott.  I thought I tried that one...

Now do you know an easy way to convert java.lang.object[] or whatever to 
the signature style [Ljava.lang.Object; (other then string 
manipulation)?  Otherwise, I'll write a conversion function.

-dain

Scott M Stark wrote:

 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.
 
 
 Scott Stark
 Chief Technology Officer
 JBoss Group, LLC
 
 
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; iarraySize; 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
 



___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



Re: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Hiram Chirino

It does not matter which classloader you use. The classes loaded by the 
SystemClassLoader will allways be available due to the ClassLoader parent 
delegation.

Regards,
Hiram


From: Jason Dillon [EMAIL PROTECTED]
To: Dain Sundstrom [EMAIL PROTECTED]
CC: JBoss-dev [EMAIL PROTECTED]
Subject: Re: [JBoss-dev] Loading array class object by name
Date: Sun, 24 Feb 2002 18:18:15 -0800

Hrm... did you try using ClassLoader.getSystemClassLoader() ?

--jason


Dain Sundstrom wrote:

Doesn't work.  I tried [Ljava/lang/Object; and both without the
semicolon.

-dain

Jason Dillon wrote:

Try loading [Ljava.lang.Object; instead... which is the class name
returned from Object[].class.getName();

--jason


Dain Sundstrom wrote:



Jason Dillon wrote:

What is the value for name you are using?





In my test code java.lang.Object[]


Why not just use Class.class?





Because I am trying to load a parameter type from an xml file that

just has the string name of the type.



Or if you really want to use Class.forName to load Class, then you
should be able to use the system class loader.





Is this after yesterdays Server/ServerLoader change?





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; iarraySize; 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



_
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



Re: [JBoss-dev] Loading array class object by name

2002-02-24 Thread Juha Lindfors

 Now do you know an easy way to convert
 java.lang.object[] or whatever to 
 the signature style [Ljava.lang.Object; (other then
 string 
 manipulation)?  Otherwise, I'll write a conversion
 function.

class literal works also on arrays. You can always write

System.out.println(String[][][][][].class.getName());

which yields

[Ljava.lang.String;

If you're dealing with an instance of an array, you can always use the 
Object.getClass() method since all array instances are objects in Java.

-- Juha


_
View thread online: http://main.jboss.org/thread.jsp?forum=66thread=9544

___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development