commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r370756 - in /jakarta/commons/proper/betwixt/trunk/src: java/org/apache/commons/betwixt/ java/org/apache/commons/betwixt/digester/ test/org/apache/commons/betwixt/introspection/
Date Fri, 20 Jan 2006 08:44:16 GMT
Author: mvdb
Date: Fri Jan 20 00:44:05 2006
New Revision: 370756

URL: http://svn.apache.org/viewcvs?rev=370756&view=rev
Log:
Adding functionality to skip beanInfo classes completely.
Patch provided by Markus Härnvi.
Thanx!

Modified:
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/XMLIntrospector.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/AttributeRule.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/MappedPropertyRule.java
    jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/introspection/TestXMLIntrospector.java

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java?rev=370756&r1=370755&r2=370756&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java
Fri Jan 20 00:44:05 2006
@@ -64,6 +64,9 @@
 
     /** Should the existing bean info search path for java.reflect.Introspector be used?
*/
     private boolean useBeanInfoSearchPath = false;
+    
+    /** Should existing BeanInfo classes be used at all for java.reflect.Introspector */
+    private boolean ignoreAllBeanInfo = false;
 
     // pluggable strategies        
     /** The strategy used to detect matching singular and plural properties */
@@ -248,6 +251,28 @@
     public void setUseBeanInfoSearchPath(boolean useBeanInfoSearchPath) {
         this.useBeanInfoSearchPath = useBeanInfoSearchPath;
     }
+    
+    /**
+     * <p>Should existing BeanInfo classes be ignored by <code>java.reflect.Introspector</code></p>
+     * <p>
+     * Default is false.
+     * </p>
+     * 
+     * @return boolean if the BeanInfo classes should be used.
+     */
+    public boolean ignoreAllBeanInfo() {
+        return ignoreAllBeanInfo;
+    }
+    
+    /**
+     * Specifies if you want to ignore existing BeanInfo classes at all for introspection
+     * @see java.beans.Introspector for more details
+     * @param ignoreAllBeanInfo set to true to ignore all BeanInfo classes
+     */
+    public void setIgnoreAllBeanInfo(boolean ignoreAllBeanInfo) {
+        this.ignoreAllBeanInfo = ignoreAllBeanInfo;
+    }
+    
     
     /** 
      * A Factory method to lazily create a new strategy 

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/XMLIntrospector.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/XMLIntrospector.java?rev=370756&r1=370755&r2=370756&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/XMLIntrospector.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/XMLIntrospector.java
Fri Jan 20 00:44:05 2006
@@ -564,7 +564,13 @@
             
             xmlInfo = findByXMLDescriptor( aClass );
             if ( xmlInfo == null ) {
-                BeanInfo info = Introspector.getBeanInfo( aClass );
+                BeanInfo info;
+                if(getConfiguration().ignoreAllBeanInfo()) {
+                    info = Introspector.getBeanInfo( aClass, Introspector.IGNORE_ALL_BEANINFO
);
+                }
+                else {
+                    info = Introspector.getBeanInfo( aClass );
+                }
                 xmlInfo = introspect( info );
             }
             
@@ -1636,7 +1642,13 @@
                 for (int i=0, size=superinterfaces.length; i<size; i++) {
                     try {
                         
-                        BeanInfo beanInfo = Introspector.getBeanInfo(superinterfaces[i]);
+                        BeanInfo beanInfo;
+                        if( getConfiguration().ignoreAllBeanInfo() ) {
+                            beanInfo = Introspector.getBeanInfo( superinterfaces[i], Introspector.IGNORE_ALL_BEANINFO
);
+                        }
+                        else {
+                            beanInfo = Introspector.getBeanInfo( superinterfaces[i] );
+                        }
                         PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
                         for (int j=0, descriptorLength=descriptors.length; j<descriptorLength
; j++) {
                             if (!getConfiguration().getPropertySuppressionStrategy()

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java?rev=370756&r1=370755&r2=370756&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java
Fri Jan 20 00:44:05 2006
@@ -106,7 +106,13 @@
         if ( beanClass != null ) {
             try {
                 boolean attributesForPrimitives = getXMLInfoDigester().isAttributesForPrimitives();
-                BeanInfo beanInfo = Introspector.getBeanInfo( beanClass );
+                BeanInfo beanInfo;
+                if( getXMLIntrospector().getConfiguration().ignoreAllBeanInfo() ) {
+                    beanInfo = Introspector.getBeanInfo( beanClass, Introspector.IGNORE_ALL_BEANINFO
);
+                }
+                else {
+                    beanInfo = Introspector.getBeanInfo( beanClass );
+                }
                 PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
                 if ( descriptors != null ) {
                     for ( int i = 0, size = descriptors.length; i < size; i++ ) {

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/AttributeRule.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/AttributeRule.java?rev=370756&r1=370755&r2=370756&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/AttributeRule.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/AttributeRule.java
Fri Jan 20 00:44:05 2006
@@ -145,7 +145,13 @@
         if ( beanClass != null ) {
             String name = attributeDescriptor.getPropertyName();
             try {
-                BeanInfo beanInfo = Introspector.getBeanInfo( beanClass );
+                BeanInfo beanInfo;
+                if( getXMLIntrospector().getConfiguration().ignoreAllBeanInfo() ) {
+                    beanInfo = Introspector.getBeanInfo( beanClass, Introspector.IGNORE_ALL_BEANINFO
);
+                }
+                else {
+                    beanInfo = Introspector.getBeanInfo( beanClass );
+                }
                 PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
                 if ( descriptors != null ) {
                     for ( int i = 0, size = descriptors.length; i < size; i++ ) {

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/MappedPropertyRule.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/MappedPropertyRule.java?rev=370756&r1=370755&r2=370756&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/MappedPropertyRule.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/digester/MappedPropertyRule.java
Fri Jan 20 00:44:05 2006
@@ -63,7 +63,13 @@
                 // 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 );
+                BeanInfo beanInfo;
+                if( getXMLIntrospector().getConfiguration().ignoreAllBeanInfo() ) {
+                    beanInfo = Introspector.getBeanInfo( beanClass, Introspector.IGNORE_ALL_BEANINFO
);
+                }
+                else {
+                    beanInfo = Introspector.getBeanInfo( beanClass );
+                }
                 PropertyDescriptor[] descriptors = 
                     beanInfo.getPropertyDescriptors();
                 if ( descriptors != null ) {

Modified: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/introspection/TestXMLIntrospector.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/introspection/TestXMLIntrospector.java?rev=370756&r1=370755&r2=370756&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/introspection/TestXMLIntrospector.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/introspection/TestXMLIntrospector.java
Fri Jan 20 00:44:05 2006
@@ -293,6 +293,32 @@
 		assertEquals( "Element name correct", "rss", elementDescriptor.getLocalName());
     }
     
+    public void testIgnoreAllBeanInfo() throws Exception {
+        XMLIntrospector introspector = new XMLIntrospector();
+        introspector.getConfiguration().setIgnoreAllBeanInfo( false );
+        introspector.setRegistry(new NoCacheRegistry());
+        XMLBeanInfo info = introspector.introspect( BeanWithBeanInfoBean.class ); 
+        ElementDescriptor[] elementDescriptors = info.getElementDescriptor().getElementDescriptors();
+        // When BeanInfo is used the properties alpha and gamma will be found 
+        if ("alpha".equals(elementDescriptors[0].getPropertyName())) {
+            assertEquals("Second element name", "gamma" , elementDescriptors[1].getPropertyName());
+        } else {
+            assertEquals("First element name", "gamma" , elementDescriptors[0].getPropertyName());
+            assertEquals("Second element name", "alpha" , elementDescriptors[1].getPropertyName());
+        }
+
+        introspector.getConfiguration().setIgnoreAllBeanInfo( true );
+        info = introspector.introspect( BeanWithBeanInfoBean.class ); 
+        elementDescriptors = info.getElementDescriptor().getElementDescriptors();
+        // When BeanInfo is ignored the properties alpha and beta will be found
+        if ("alpha".equals(elementDescriptors[0].getPropertyName())) {
+            assertEquals("Second element name", "beta" , elementDescriptors[1].getPropertyName());
+        } else {
+            assertEquals("First element name", "beta" , elementDescriptors[0].getPropertyName());
+            assertEquals("Second element name", "alpha" , elementDescriptors[1].getPropertyName());
+        }
+    }
+    
 
 }
 



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