DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=31553>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=31553 [betwixt][Patch] PropertySuppressionStrategy.suppressProperty include the bean containing the property Summary: [betwixt][Patch] PropertySuppressionStrategy.suppressProperty include the bean containing the property Product: Commons Version: Nightly Builds Platform: All URL: http://jakarta.apache.org/commons/betwixt/guide/binding. html#Ignoring%20Properties OS/Version: Other Status: NEW Severity: Enhancement Priority: Other Component: Betwixt AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] CC: [EMAIL PROTECTED] In my usecase I need to show/hide the class property depending on the bean that conatins the property. So I cant decide when I have only the propertyType and the propertyName as parameters to the suppressProperty method. I extended it to have also the type of the bean containing the property for decision making. I also added a sample usage of this strategy to the xdocs. I tested it, for me it works, problem is only that it's not binary compatible with last Version of PropertySuppressionStrategy. A possible solution to this might that null is allowed as parameter classContainingThePropety to the suppressProperty method. Then we could have a method: public boolean suppressProperty(Class propertyType, String propertyName) { return suppressProperty(null, propertyType, propertyName); } but I don't like the idea to possible handle NullPointerExceptions here. Here is my patch: Index: src/java/org/apache/commons/betwixt/XMLIntrospector.java =================================================================== RCS file: /home/cvspublic/jakarta- commons/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java,v retrieving revision 1.37 diff -u -r1.37 XMLIntrospector.java --- src/java/org/apache/commons/betwixt/XMLIntrospector.java 4 Oct 2004 22:27:12 -0000 1.37 +++ src/java/org/apache/commons/betwixt/XMLIntrospector.java 5 Oct 2004 22:51:20 -0000 @@ -1431,7 +1431,10 @@ if ( descriptors != null ) { for (int i=0, size=descriptors.length; i<size; i++) { if (!getConfiguration().getPropertySuppressionStrategy () - .suppressProperty( descriptors [i].getPropertyType(), descriptors[i].getName())) { + .suppressProperty( + this.beanInfo.getBeanDescriptor ().getBeanClass(), + descriptors[i].getPropertyType(), + descriptors[i].getName())) { propertyDescriptors.add( descriptors[i] ); } } @@ -1446,7 +1449,10 @@ if ( descriptors != null ) { for (int j=0, innerSize=descriptors.length; j<innerSize; j++) { if (!getConfiguration ().getPropertySuppressionStrategy() - .suppressProperty( descriptors [j].getPropertyType(), descriptors[j].getName())) { + .suppressProperty( + additionalInfo.getBeanDescriptor().getBeanClass(), + descriptors[j].getPropertyType (), + descriptors[j].getName())) { propertyDescriptors.add( descriptors[j] ); } } @@ -1484,7 +1490,10 @@ PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); for (int j=0, descriptorLength=descriptors.length; j<descriptorLength ; j++) { if (!getConfiguration ().getPropertySuppressionStrategy() - .suppressProperty( descriptors [j].getPropertyType(), descriptors[j].getName())) { + .suppressProperty( + beanInfo.getBeanDescriptor ().getBeanClass(), + descriptors[j].getPropertyType(), + descriptors[j].getName())) { propertyDescriptors.add( descriptors[j] ); } } Index: src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java =================================================================== RCS file: /home/cvspublic/jakarta- commons/betwixt/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.ja va,v retrieving revision 1.14 diff -u -r1.14 AddDefaultsRule.java --- src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java 4 Oct 2004 21:50:35 -0000 1.14 +++ src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java 5 Oct 2004 22:51:20 -0000 @@ -110,7 +110,10 @@ continue; } if (!getXMLIntrospector().getConfiguration ().getPropertySuppressionStrategy() - .suppressProperty(descriptor.getPropertyType (), descriptor.getName())) { + .suppressProperty( + beanInfo.getBeanDescriptor ().getBeanClass(), + descriptor.getPropertyType(), + descriptor.getName())) { Descriptor nodeDescriptor = getXMLIntrospector ().createXMLDescriptor(new BeanProperty(descriptor)); if ( nodeDescriptor != null ) { Index: src/java/org/apache/commons/betwixt/strategy/PropertySuppressionStrategy.java =================================================================== RCS file: /home/cvspublic/jakarta- commons/betwixt/src/java/org/apache/commons/betwixt/strategy/PropertySuppressio nStrategy.java,v retrieving revision 1.1 diff -u -r1.1 PropertySuppressionStrategy.java --- src/java/org/apache/commons/betwixt/strategy/PropertySuppressionStrategy.java 4 Oct 2004 21:52:13 -0000 1.1 +++ src/java/org/apache/commons/betwixt/strategy/PropertySuppressionStrategy.java 5 Oct 2004 22:51:20 -0000 @@ -28,7 +28,7 @@ * found on every object. */ public static final PropertySuppressionStrategy DEFAULT = new PropertySuppressionStrategy() { - public boolean suppressProperty(Class propertyType, String propertyName) { + public boolean suppressProperty(Class clazz, Class propertyType, String propertyName) { boolean result = false; // ignore class properties if ( Class.class.equals( propertyType) && "class".equals( propertyName ) ) { @@ -40,9 +40,10 @@ /** * Should the given property be supressed? + * @param classContainingThePropety <code>Class</code> giving the type of the bean containing the property <code>propertyName</code> * @param propertyType <code>Class</code> giving the type of the property, not null * @param propertyName the name of the property, not null * @return true when the given property should be suppressed */ - public abstract boolean suppressProperty(Class propertyType, String propertyName); + public abstract boolean suppressProperty(Class classContainingThePropety, Class propertyType, String propertyName); } Index: xdocs/guide/binding.xml =================================================================== RCS file: /home/cvspublic/jakarta-commons/betwixt/xdocs/guide/binding.xml,v retrieving revision 1.10 diff -u -r1.10 binding.xml --- xdocs/guide/binding.xml 4 Oct 2004 21:49:20 -0000 1.10 +++ xdocs/guide/binding.xml 5 Oct 2004 22:51:22 -0000 @@ -501,8 +501,36 @@ or a certain type. For example, the default Betwixt configuration ignores all properties called 'class'. The <code>PropertySuppressionStrategy</code> pluggable strategy can be set on the <code>IntrospectionConfiguration</code> and allows course grained rules -concerning which properties are to be ignored to be set. - </p> +concerning which properties are to be ignored to be set.</p> + <p> +The following example shows a <code>PropertySuppressionStrategy</code> that shows all +properties, including the class property: +<source><![CDATA[ +beanWriter.getXMLIntrospector().getConfiguration ().setPropertySuppressionStrategy( + new PropertySuppressionStrategy() { + public boolean suppressProperty(Class clazz, Class type, String name) { + return false; + } + }); +]]></source></p> + <p> +Here is another example making the choice dependant on what class containes the +property. This one shows the class property only for classes like +<code>Throwable</code>, <code>Exception</code>, <code>Error</code> and so on: +<source><![CDATA[ +beanWriter.getXMLIntrospector().getConfiguration ().setPropertySuppressionStrategy( + new PropertySuppressionStrategy() { + public boolean suppressProperty(Class classContainingThePropety, + Class propertyType, String propertyName) { + if (Class.class.equals(propertyType) + && "class".equals(propertyName) + && !Throwable.class.isAssignableFrom(clazz) ) { + return true; + } + return false; + } + }); +]]></source></p> </subsection> </section> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
