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 <[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(); > > 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:[EMAIL PROTECTED] > 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
