commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester MappedPropertyRule.java
Date Fri, 06 Aug 2004 19:40:25 GMT
rdonkin     2004/08/06 12:40:25

  Modified:    betwixt/src/java/org/apache/commons/betwixt
                        XMLIntrospector.java
               betwixt/src/java/org/apache/commons/betwixt/digester
                        MappedPropertyRule.java
  Log:
  Improved support for superinterface introspection
  
  Revision  Changes    Path
  1.32      +31 -0     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java
  
  Index: XMLIntrospector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- XMLIntrospector.java	14 Jul 2004 21:38:17 -0000	1.31
  +++ XMLIntrospector.java	6 Aug 2004 19:40:25 -0000	1.32
  @@ -1320,6 +1320,9 @@
                           }
                       }            
                   }
  +                
  +                addAllSuperinterfaces(beanClass, propertyDescriptors);
  +                
                   // what happens when size is zero?
                   properties = new BeanProperty[ propertyDescriptors.size() ];
                   int count = 0;
  @@ -1330,6 +1333,34 @@
               }
               return properties;
           }
  +        
  +        /**
  +         * Adds all super interfaces.
  +         * Super interface methods are not returned within the usual 
  +         * bean info for an interface.
  +         * @param clazz <code>Class</code>, not null
  +         * @param propertyDescriptors <code>ArrayList</code> of <code>PropertyDescriptor</code>s',
not null
  +         */
  +        private void addAllSuperinterfaces(Class clazz, ArrayList propertyDescriptors)
{
  +            if (clazz.isInterface()) {
  +                Class[] superinterfaces = clazz.getInterfaces();
  +                for (int i=0, size=superinterfaces.length; i<size; i++) {
  +                    try {
  +                        
  +                        BeanInfo beanInfo = Introspector.getBeanInfo(superinterfaces[i]);
  +                        PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
  +                        for (int j=0, descriptorLength=descriptors.length; j<descriptorLength
; j++) {
  +                            propertyDescriptors.add(descriptors[j]);
  +                        }
  +                        addAllSuperinterfaces(superinterfaces[i], propertyDescriptors);
  +                        
  +                    } catch (IntrospectionException ex) {
  +                        log.info("Introspection on superinterface failed.", ex);
  +                    }
  +                }
  +            }
  +        }
  +        
       }
       
       /** Implementation for DynaClasses */
  
  
  
  1.8       +15 -0     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/MappedPropertyRule.java
  
  Index: MappedPropertyRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/MappedPropertyRule.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MappedPropertyRule.java	4 Jul 2004 16:40:49 -0000	1.7
  +++ MappedPropertyRule.java	6 Aug 2004 19:40:25 -0000	1.8
  @@ -60,6 +60,9 @@
                   log.trace("Searching for property " + propertyName + " on " + beanClass);
               }
               try {
  +                // TODO: replace this call to introspector to an object call
  +                // which finds all property descriptors for a class
  +                // this allows extra property descriptors to be added 
                   BeanInfo beanInfo = Introspector.getBeanInfo( beanClass );
                   PropertyDescriptor[] descriptors = 
                       beanInfo.getPropertyDescriptors();
  @@ -72,6 +75,18 @@
                           }
                       }
                   }
  +                // for interfaces, check all super interfaces
  +                if (beanClass.isInterface()) {
  +                    Class[] superinterfaces = beanClass.getInterfaces();
  +                    for (int i=0, size=superinterfaces.length; i<size; i++) {
  +                        PropertyDescriptor descriptor = getPropertyDescriptor(superinterfaces[i],
propertyName);
  +                        if (descriptor != null)
  +                        {
  +                            return descriptor;
  +                        }
  +                    }
  +                }
  +                
                   log.trace("No match found.");
                   return null;
               } catch (Exception e) {
  
  
  

---------------------------------------------------------------------
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