You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Diego Tognola <dt...@agentissoftware.com> on 2002/08/26 09:43:43 UTC
[PATCH] "add.." methods not belonging to bean properties (see user-list, 8/22/2002)
Index: XMLIntrospectorHelper.java
===================================================================
RCS file:
/home/cvspublic/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/
digester/XMLIntrospectorHelper.java,v
retrieving revision 1.6
diff -u -r1.6 XMLIntrospectorHelper.java
--- XMLIntrospectorHelper.java 14 Aug 2002 20:26:22 -0000 1.6
+++ XMLIntrospectorHelper.java 26 Aug 2002 07:38:27 -0000
@@ -66,6 +66,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.ArrayList;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
@@ -341,17 +342,33 @@
// lets iterate over all methods looking for one of the form
// add*(PropertyType)
if ( beanClass != null ) {
+
+ PropertyDescriptor[] propDescriptors = null;
+ try {
+ propDescriptors =
Introspector.getBeanInfo(beanClass).getPropertyDescriptors();
+ }
+ catch (IntrospectionException e) {
+ log.error(e);
+ }
+ ArrayList propNames = new ArrayList();
+ for (int i=0; i<propDescriptors.length; i++) {
+ propNames.add(propDescriptors[i].getName());
+ }
+
Method[] methods = beanClass.getMethods();
for ( int i = 0, size = methods.length; i < size; i++ ) {
Method method = methods[i];
String name = method.getName();
- if ( name.startsWith( "add" ) ) {
+
+ String propertyName = Introspector.decapitalize(
name.substring(3) );
+ boolean isBeanProperty = (propNames.indexOf(propertyName)
>= 0);
+ if ( name.startsWith( "add" ) && isBeanProperty) {
+
// XXX: should we filter out non-void returning
methods?
// some beans will return something as a helper
Class[] types = method.getParameterTypes();
if ( types != null && types.length == 1 ) {
- String propertyName = Introspector.decapitalize(
name.substring(3) );
-
+
// now lets try find the ElementDescriptor which
displays
// a property which starts with propertyName
// and if so, we'll set a new Updater on it if
there
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: [PATCH] "add.." methods not belonging to bean properties (see user-list, 8/22/2002)
Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
hi Diego
this patch (seems to) break the unit tests. it could be that it has
side-effects or it might possibly be that the patch got mangled in transit.
(i've taken a look into it and i think that maybe it'll take something
quite a bit complication to provide a comprehensive solution.)
- robert
On Monday, August 26, 2002, at 08:43 AM, Diego Tognola wrote:
> Index: XMLIntrospectorHelper.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-
> commons/betwixt/src/java/org/apache/commons/betwixt/
> digester/XMLIntrospectorHelper.java,v
> retrieving revision 1.6
> diff -u -r1.6 XMLIntrospectorHelper.java
> --- XMLIntrospectorHelper.java 14 Aug 2002 20:26:22 -0000 1.6
> +++ XMLIntrospectorHelper.java 26 Aug 2002 07:38:27 -0000
> @@ -66,6 +66,7 @@
> import java.util.HashMap;
> import java.util.Iterator;
> import java.util.Map;
> +import java.util.ArrayList;
>
> import org.apache.commons.logging.LogFactory;
> import org.apache.commons.logging.Log;
> @@ -341,17 +342,33 @@
> // lets iterate over all methods looking for one of the form
> // add*(PropertyType)
> if ( beanClass != null ) {
> +
> + PropertyDescriptor[] propDescriptors = null;
> + try {
> + propDescriptors =
> Introspector.getBeanInfo(beanClass).getPropertyDescriptors();
> + }
> + catch (IntrospectionException e) {
> + log.error(e);
> + }
> + ArrayList propNames = new ArrayList();
> + for (int i=0; i<propDescriptors.length; i++) {
> + propNames.add(propDescriptors[i].getName());
> + }
> +
> Method[] methods = beanClass.getMethods();
> for ( int i = 0, size = methods.length; i < size; i++ ) {
> Method method = methods[i];
> String name = method.getName();
> - if ( name.startsWith( "add" ) ) {
> +
> + String propertyName = Introspector.decapitalize(
> name.substring(3) );
> + boolean isBeanProperty = (propNames.indexOf(propertyName)
>> = 0);
> + if ( name.startsWith( "add" ) && isBeanProperty) {
> +
> // XXX: should we filter out non-void returning
> methods?
> // some beans will return something as a helper
> Class[] types = method.getParameterTypes();
> if ( types != null && types.length == 1 ) {
> - String propertyName = Introspector.decapitalize(
> name.substring(3) );
> -
> +
> // now lets try find the ElementDescriptor which
> displays
> // a property which starts with propertyName
> // and if so, we'll set a new Updater on it if
> there
>
>
> --
> To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@jakarta.apache.
> org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.
> org>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>