[lang] enhanced version of Class.forName

2005-09-05 Thread Thomas Dudziak
Hi folks, I had this problem that I needed to create class objects for things like "int" and "boolean", eg. the type specification that you would use for a variable declaration or method parameter. Since the normal Class.forName does not handle this really well, and commons-lang does not provide s

Re: [lang] enhanced version of Class.forName

2005-09-05 Thread Wade Chandler
--- Thomas Dudziak <[EMAIL PROTECTED]> wrote: > Hi folks, > > I had this problem that I needed to create class > objects for things > like "int" and "boolean", eg. the type specification > that you would > use for a variable declaration or method parameter. > Since the normal Class.forName does n

Re: [lang] enhanced version of Class.forName

2005-09-05 Thread Thomas Dudziak
(Ups, only replied to Wade, not the list) On 9/5/05, Wade Chandler <[EMAIL PROTECTED]> wrote: > What's a use case for it Tom? curious. I just checked-in an enhancement for OJB that allows to specify which constructor/factory-method to utilize for constructing objects read from the database. The

Re: [lang] enhanced version of Class.forName

2005-09-05 Thread Henri Yandell
Deja Vu :) +1 Jan-2005:http://mail-archives.apache.org/mod_mbox/jakarta-commons-dev/200501.mbox/[EMAIL PROTECTED] Feb-2005:http://mail-archives.apache.org/mod_mbox/jakarta-commons-dev/200502.mbox/[EMAIL PROTECTED] Various ClassLoader issues raised by Stephen, we agreed to hold off until after 2

RE: [lang] enhanced version of Class.forName

2005-09-05 Thread James Carman
meBuffer.append( "L" + className + ";" ); } clazz = Class.forName( actualNameBuffer.toString() ); } else { clazz = Class.forName( className ); } } return clazz; } -Original Message- From: Thomas Dudziak [mailto:[EMAIL PROTECTED] Sen

Re: [lang] enhanced version of Class.forName

2005-09-05 Thread Martin Cooper
tring abbreviation = ( String )abbreviationMap.get( className > ); > if( abbreviation != null ) > { > actualNameBuffer.append( abbreviation ); > } > else > { > actualNameBuffer.append( "L" + className + ";" ); > } > clazz = Class.forName(

RE: [lang] enhanced version of Class.forName

2005-09-05 Thread James Carman
oking to do. The obvious place for it would be in ClassUtils, but I didn't see anything. -Original Message- From: Martin Cooper [mailto:[EMAIL PROTECTED] Sent: Monday, September 05, 2005 10:19 PM To: Jakarta Commons Developers List Cc: [EMAIL PROTECTED] Subject: Re: [lang] enhanced

RE: [lang] enhanced version of Class.forName

2005-09-05 Thread James Carman
irst place)? -Original Message- From: Henri Yandell [mailto:[EMAIL PROTECTED] Sent: Monday, September 05, 2005 8:26 PM To: Jakarta Commons Developers List; [EMAIL PROTECTED] Subject: Re: [lang] enhanced version of Class.forName Deja Vu :) +1 Jan-2005:http://mail-archives.apache.org/mod

RE: [lang] enhanced version of Class.forName

2005-09-05 Thread James Carman
Sorry, I meant "forCanonicalName" of course. -Original Message- From: James Carman [mailto:[EMAIL PROTECTED] Sent: Monday, September 05, 2005 11:26 PM To: 'Jakarta Commons Developers List'; [EMAIL PROTECTED] Subject: RE: [lang] enhanced version of Class.forName I ha

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Thomas Dudziak
On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > I would say that this is something that would be very useful. We did > something similar in HiveMind. I can imagine an implementation like: > > private static Map typeMap = new HashMap(); > private static Map abbreviationMap = new HashMap();

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Henning P. Schmiedehausen
ffer.append( "[" ); > } > final String abbreviation = ( String )abbreviationMap.get( className >); > if( abbreviation != null ) > { >actualNameBuffer.append( abbreviation ); > } > else > { >actualNameBuffer.ap

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread Jörg Schaible
Hi Thomas, Thomas Dudziak wrote on Tuesday, September 06, 2005 9:09 AM: [snip] > > * the direct usage of types (Integer.TYPE etc.) has obviously > problems in environments with multiple class loaders (eg. > Class.forName(String name, boolean initialize, ClassLoader > classLoader); likewise there

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Thomas Dudziak
On 9/6/05, Jörg Schaible <[EMAIL PROTECTED]> wrote: > Thomas Dudziak wrote on Tuesday, September 06, 2005 9:09 AM: > > [snip] > > > > * the direct usage of types (Integer.TYPE etc.) has obviously > > problems in environments with multiple class loaders (eg. > > Class.forName(String name, boolean

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Knut Wannheden
On 9/6/05, Thomas Dudziak <[EMAIL PROTECTED]> wrote: > On 9/6/05, Jörg Schaible <[EMAIL PROTECTED]> wrote: > > > Thomas Dudziak wrote on Tuesday, September 06, 2005 9:09 AM: > > > > [snip] > > > > > > * the direct usage of types (Integer.TYPE etc.) has obviously > > > problems in environments with

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread James Carman
iginal Message- From: Henning P. Schmiedehausen [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 06, 2005 3:30 AM To: commons-dev@jakarta.apache.org Subject: Re: [lang] enhanced version of Class.forName "James Carman" <[EMAIL PROTECTED]> writes: >I would say that this is s

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread James Carman
PROTECTED] Sent: Tuesday, September 06, 2005 3:09 AM To: Jakarta Commons Developers List Subject: Re: [lang] enhanced version of Class.forName On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > I would say that this is something that would be very useful. We did > something similar in HiveM

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Thomas Dudziak
On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > 1. In an environment where a SecurityManager is installed (if you're > running code that is going to try to replace system classes, I'd suggest > it), code has to be given the permission to instantiate a ClassLoader. > Also, that ClassLoader ha

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread James Carman
classloader if it really is safer. -Original Message- From: Thomas Dudziak [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 06, 2005 8:59 AM To: Jakarta Commons Developers List Subject: Re: [lang] enhanced version of Class.forName On 9/6/05, James Carman <[EMAIL PROTECTED]>

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Thomas Dudziak
On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > 1. If you're going to use that logic, then who is to say that the > String.equals() or String.hashCode() method is implemented correctly? > You're using a HashMap (so am I) that has Strings as keys. In your scenario > (EvilClassLoader), the St

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread James Carman
] enhanced version of Class.forName On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > 1. If you're going to use that logic, then who is to say that the > String.equals() or String.hashCode() method is implemented correctly? > You're using a HashMap (so am I) that has

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread James Carman
sday, September 06, 2005 9:24 AM To: Jakarta Commons Developers List Subject: Re: [lang] enhanced version of Class.forName On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > 1. If you're going to use that logic, then who is to say that the > String.equals() or String.hashCode

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Thomas Dudziak
On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > Well, I just tried your code against my test cases and it fails in two > ways... > > 1. It doesn't throw an IllegalArgumentException when you pass in null. > 2. It doesn't hand the actual java class names for array types (i.e. > [[Ljava.lang.S

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Thomas Dudziak
On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > Okay, I caved (or compromised)! :-) I re-wrote the method to use your > little trick of loading the array version of the class and taking the > component type. The only problem I have with this is that I'm passing the > "initialize" parameter i

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread James Carman
September 06, 2005 10:12 AM To: Jakarta Commons Developers List Subject: Re: [lang] enhanced version of Class.forName On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > Okay, I caved (or compromised)! :-) I re-wrote the method to use your > little trick of loading the array version o

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Thomas Dudziak
On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > 1. Well, it's not exactly the same thing. I'm talking about when they pass > in just "boolean" or "int". In that case, we construct the name "[B" or > "[I" and pass that to Class.forName() with the "initialize" parameter, > thereby telling it

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread James Carman
ed in (i.e. transforming it into the proper format)? -Original Message- From: Thomas Dudziak [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 06, 2005 10:39 AM To: Jakarta Commons Developers List Subject: Re: [lang] enhanced version of Class.forName On 9/6/05, James Carman <[EMAIL PROTECTED

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Thomas Dudziak
On 9/6/05, James Carman <[EMAIL PROTECTED]> wrote: > Do you think we need to go through the trouble of throwing an > IllegalArgumentException if it's not a well-formed class name (starts with > character, blah blah blah)? Or, can we just let it throw a > ClassNotFoundException after doing as much

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Emmanuel Bourg
James Carman wrote: Do you think we need to go through the trouble of throwing an IllegalArgumentException if it's not a well-formed class name (starts with character, blah blah blah)? Or, can we just let it throw a ClassNotFoundException after doing as much as we can with the string that's pass

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread James Carman
PROTECTED] Sent: Tuesday, September 06, 2005 11:04 AM To: Jakarta Commons Developers List Subject: Re: [lang] enhanced version of Class.forName James Carman wrote: > Do you think we need to go through the trouble of throwing an > IllegalArgumentException if it's not a well-formed class

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread Gary Gregory
IMO, you let the underlying JRE API throw the exception. Gary > -Original Message- > From: James Carman [mailto:[EMAIL PROTECTED] > Sent: Tuesday, September 06, 2005 8:28 AM > To: 'Jakarta Commons Developers List' > Subject: RE: [lang] enhanced version of Clas

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Henning P. Schmiedehausen
=?iso-8859-1?Q?J=F6rg_Schaible?= <[EMAIL PROTECTED]> writes: >Hi Henning, Hi Jörg, >Well, looking into the JDK source I see no real advantage of not using >endsWith. x.endsWith("[]") will exactly do 2 character compares (if the string >matches), as well as your code above. And it only has one

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Martin Cooper
ntext class loader. -- Martin Cooper -Original Message- > From: Thomas Dudziak [mailto:[EMAIL PROTECTED] > Sent: Tuesday, September 06, 2005 3:09 AM > To: Jakarta Commons Developers List > Subject: Re: [lang] enhanced version of Class.forName > > On 9/6/05, James Ca

Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Stephen Colebourne
James Carman wrote: Well, what does the [lang] "team" think about this approach (just letting Class.forName() throw the ClassNotFoundException)? Does this work for you guys? I have added a patch to issue 36512 which includes code to implement it this way (my latest patch). Are there any votes

RE: [lang] enhanced version of Class.forName

2005-09-06 Thread James Carman
ite this method), but we might want to be consistent. I don't know. -Original Message- From: Stephen Colebourne [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 06, 2005 4:25 PM To: Jakarta Commons Developers List Subject: Re: [lang] enhanced version of Class.forName James Carman

RE: Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Jörg Schaible
Hi Henning, Henning P. Schmiedehausen wrote on Tuesday, September 06, 2005 9:30 AM: > "James Carman" <[EMAIL PROTECTED]> writes: > >> I would say that this is something that would be very useful. We did >> something similar in HiveMind. I can imagine an implementation like: > > I always wonde

RE: Re: [lang] enhanced version of Class.forName

2005-09-06 Thread Jörg Schaible
Hi Henning, Henning P. Schmiedehausen wrote on Tuesday, September 06, 2005 6:09 PM: [snip] > => charAt is 3-4 times faster when not matching and almost twice as >fast when matching. For the short case it is even faster. > > Get Test Class Source code from > http://henning.schmiedehausen.org