You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@apache.org on 2001/02/01 18:28:19 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node PropertyExecutor.java
geirm 01/02/01 09:28:18
Modified: src/java/org/apache/velocity/runtime/parser/node
PropertyExecutor.java
Log:
Added a small fix to [supposedly] be more beanlike in our introspection, capitalizing the
first letter of the property when looking for a get<property> method the second time,
after the first attempt fails.
Now, since I love symmetry, I did the inverse as well, lowercasing the first letter of
the property the second time if it was uppercase the first time.
I really don't like this much :)
Will post comments to list.
Revision Changes Path
1.4 +35 -0 jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
Index: PropertyExecutor.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PropertyExecutor.java 2001/01/06 22:08:34 1.3
+++ PropertyExecutor.java 2001/02/01 17:28:15 1.4
@@ -77,8 +77,43 @@
}
catch (NoSuchMethodException nsme)
{
+ /*
+ * ok, to be more bean-spec-like,
+ * let try with the first letter of the property
+ * altered to the other case (upper <-> lower)
+ *
+ * I am not thrilled about this - this is an inverted
+ * interpretation of the bean spec : the bean spec really
+ * talks about the *other* direction, defining the property
+ * that is related to a get<id>() set<id>() pair. We are going
+ * the other way, I believe.
+ *
+ * Taking an uppercase to a lower is getting even further afield
+ * I think, but symmetric and what people may expect.
+ */
+
+ StringBuffer sb = new StringBuffer( "get" );
+ sb.append( property );
+
+ if( Character.isLowerCase( sb.charAt(3)))
+ {
+ sb.setCharAt( 3 , Character.toUpperCase( sb.charAt( 3 ) ) );
+ }
+ else
+ {
+ sb.setCharAt( 3 , Character.toLowerCase( sb.charAt( 3 ) ) );
+ }
+
+ try
+ {
+ method = c.getMethod( sb.toString(), null);
+ }
+ catch ( NoSuchMethodException nsme2 )
+ {
+ }
}
}
+
/**
* Get the value of the specified property.