It would be simpler and faster to just do:
- Method m = c.getMethod("set" + identifier, params);
+ String setterName = "set" +
+ Character.toUpperCase( identifier.charAt(0) ) +
+ identifier.substring(1);
+ Method m = c.getMethod(setterName, params);
This change is to assist users of beans to be able to just
call #set( $foo.bar = "woobie" ) to call foo.setBar("woobie")
method. It was sort of strange to be required to do
#set( $foo.Bar = "woobie" ) and it was already causing some
problems and questions...
It is a bean rule that the character after set is uppercase!
See http://java.sun.com/beans/docs/spec.html section 8.3 of
beans_101.pdf.
I believe we are not yet in a required backward compatibility state,
and anyone thad did a setxxx(...) instead of setXxx(...) should
rewrite his code to conform to standard Java (and beans) conventions.
Otherwise if he really wants to call a setxxx(), then he has to write
it explicetely: #call( $foo.setbar("woobie") )
(here I used my #macro( call $foo )#if($foo)#**##end#end ).
:) Christoph
[EMAIL PROTECTED] wrote:
>
> geirm 01/02/01 10:22:33
>
> Modified: src/java/org/apache/velocity/runtime/parser/node
> ASTReference.java
> Log:
> Added support for using lower-case property identifiers in #set() to match the
> ability to get values that way.
>
> So
>
> #set($foo.bar = "hi")
>
> will try to call setbar("hi") and then setBar("hi")
This is not conform and anyone that did a setbar("hi") should rewrite his
code.
>
> Revision Changes Path
> 1.20 +24 -3
>jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
>
> Index: ASTReference.java
> ===================================================================
> RCS file:
>/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java,v
> retrieving revision 1.19
> retrieving revision 1.20
> diff -u -r1.19 -r1.20
> --- ASTReference.java 2001/01/18 05:08:18 1.19
> +++ ASTReference.java 2001/02/01 18:22:30 1.20
> @@ -79,7 +79,7 @@
> * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
> * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
> * @author <a href="mailto:[EMAIL PROTECTED]">Christoph Reck</a>
> - * @version $Id: ASTReference.java,v 1.19 2001/01/18 05:08:18 geirm Exp $
> + * @version $Id: ASTReference.java,v 1.20 2001/02/01 18:22:30 geirm Exp $
> */
>
> public class ASTReference extends SimpleNode
> @@ -300,12 +300,33 @@
>
> Class[] params = { value.getClass() };
> Class c = result.getClass();
> - Method m = c.getMethod("set" + identifier, params);
> + Method m = null;
>
> + try
> + {
> + m = c.getMethod("set" + identifier, params);
> + }
> + catch( NoSuchMethodException nsme2)
> + {
> + StringBuffer sb = new StringBuffer( "set" );
> + sb.append( identifier );
> +
> + if( Character.isLowerCase( sb.charAt(3)))
> + {
> + sb.setCharAt( 3 , Character.toUpperCase( sb.charAt( 3 ) ) );
> + }
> + else
> + {
> + sb.setCharAt( 3 , Character.toLowerCase( sb.charAt( 3 ) ) );
> + }
> +
> + m = c.getMethod( sb.toString(), params);
> + }
> +
> /*
> * and if we get here, getMethod() didn't chuck an exception...
> */
> -
> +
> Object[] args = { value };
> m.invoke(result, args);
> }
>
>
>
--
==============================================================
Deutsches Zentrum fuer Luft- und Raumfahrt (DLR)
Deutsches Fernerkundungs Datenzentrum (DFD)
DLR-DFD, Muenchner Strasse 20, D-82234 Wessling, Germany
============= Currenlty relocated to ESA-ESRIN ===============
ESA ESRIN Tel: +39 06 941 80 589
c/o Christoph Reck (DLR) Fax: +39 06 941 80 512
Via Galileo Galilei mailto:[EMAIL PROTECTED]
I-00044 Frascati (Roma) http://www.dfd.dlr.de
==============================================================