commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman" <ja...@carmanconsulting.com>
Subject RE: [lang] enhanced version of Class.forName
Date Tue, 06 Sep 2005 02:50:01 GMT
The code in "clazz" looks somewhat similar to what I have, but they used a
bunch of if/else statements rather than maps to do what I did.  I personally
like my implementation a bit better (well, DUH), though.  I couldn't find
any code in "reflect" which did what we are looking to do.  The obvious
place for it would be in ClassUtils, but I didn't see anything. 

-----Original Message-----
From: Martin Cooper [mailto:mfncooper@gmail.com] 
Sent: Monday, September 05, 2005 10:19 PM
To: Jakarta Commons Developers List
Cc: tomdzk@gmail.com
Subject: Re: [lang] enhanced version of Class.forName

This might be a good time to mention two dormant sandbox components that 
(tried to) address similar needs. One, at least, has a stated relationship 
with Lang.

http://svn.apache.org/viewcvs.cgi/jakarta/commons/dormant/clazz/trunk/
http://svn.apache.org/viewcvs.cgi/jakarta/commons/dormant/reflect/trunk/

--
Martin Cooper


On 9/5/05, James Carman <james@carmanconsulting.com> 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();
> 
> static
> {
> typeMap.put( "int", Integer.TYPE );
> typeMap.put( "boolean", Boolean.TYPE );
> typeMap.put( "float", Float.TYPE );
> typeMap.put( "long", Long.TYPE );
> typeMap.put( "short", Short.TYPE );
> typeMap.put( "byte", Byte.TYPE );
> typeMap.put( "double", Double.TYPE );
> typeMap.put( "char", Character.TYPE );
> 
> abbreviationMap.put( "int", "I" );
> abbreviationMap.put( "boolean", "Z" );
> abbreviationMap.put( "float", "F" );
> abbreviationMap.put( "long", "J" );
> abbreviationMap.put( "short", "S" );
> abbreviationMap.put( "byte", "B" );
> abbreviationMap.put( "double", "D" );
> abbreviationMap.put( "char", "C" );
> }
> 
> public static Class enhancedForName( String className ) throws
> ClassNotFoundException
> {
> Class clazz = ( Class )typeMap.get( className );
> if( clazz == null )
> {
> if( className.endsWith( "[]" ) )
> {
> final StringBuffer actualNameBuffer = new StringBuffer();
> while( className.endsWith( "[]" ) )
> {
> className = className.substring( 0, className.length() - 2 );
> actualNameBuffer.append( "[" );
> }
> final String abbreviation = ( String )abbreviationMap.get( className
> );
> if( abbreviation != null )
> {
> actualNameBuffer.append( abbreviation );
> }
> else
> {
> actualNameBuffer.append( "L" + className + ";" );
> }
> clazz = Class.forName( actualNameBuffer.toString() );
> }
> else
> {
> clazz = Class.forName( className );
> }
> }
> return clazz;
> }
> 
> -----Original Message-----
> From: Thomas Dudziak [mailto:tomdzk@gmail.com]
> Sent: Monday, September 05, 2005 5:05 PM
> To: Jakarta Commons Developers List
> Subject: [lang] enhanced version of Class.forName
> 
> 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 such a function (please correct me if
> I'm wrong here), I implemented it myself.
> Now I wonder, would this be useful enhancement to ClassUtils ? If so,
> I could provide a patch in BugZilla.
> 
> regards,
> Tom
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message