rdonkin     2004/10/06 14:38:06

  Modified:    betwixt/src/java/org/apache/commons/betwixt
                        XMLIntrospector.java
               betwixt/src/java/org/apache/commons/betwixt/digester
                        AddDefaultsRule.java
               betwixt/src/java/org/apache/commons/betwixt/strategy
                        PropertySuppressionStrategy.java
               betwixt/src/test/org/apache/commons/betwixt/derived
                        TestWriteClass.java
               betwixt/xdocs/guide binding.xml
  Log:
  Improved PropertySuppressionStrategy interface and documentation. Issue #31553. 
Submitted by Christoph Gaffga.
  
  Revision  Changes    Path
  1.38      +12 -3     
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.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- XMLIntrospector.java      4 Oct 2004 22:27:12 -0000       1.37
  +++ XMLIntrospector.java      6 Oct 2004 21:38:05 -0000       1.38
  @@ -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( 
  +                                            beanClass,
  +                                            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(
  +                                               beanClass,
  +                                                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(
  +                                               beanClass,
  +                                            descriptors[j].getPropertyType(),
  +                                            descriptors[j].getName())) {
                                   propertyDescriptors.add( descriptors[j] );
                               }
                           }
  
  
  
  1.15      +4 -1      
jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java
  
  Index: AddDefaultsRule.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- AddDefaultsRule.java      4 Oct 2004 21:50:35 -0000       1.14
  +++ AddDefaultsRule.java      6 Oct 2004 21:38:05 -0000       1.15
  @@ -110,7 +110,10 @@
                               continue;
                           }
                           if 
(!getXMLIntrospector().getConfiguration().getPropertySuppressionStrategy()
  -                                .suppressProperty(descriptor.getPropertyType(), 
descriptor.getName())) {
  +                                .suppressProperty(
  +                                        beanClass,
  +                                        descriptor.getPropertyType(),
  +                                        descriptor.getName())) {
                                Descriptor nodeDescriptor = 
                                                
getXMLIntrospector().createXMLDescriptor(new BeanProperty(descriptor));
                                if ( nodeDescriptor != null ) {
  
  
  
  1.2       +4 -3      
jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/PropertySuppressionStrategy.java
  
  Index: PropertySuppressionStrategy.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/PropertySuppressionStrategy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PropertySuppressionStrategy.java  4 Oct 2004 21:52:13 -0000       1.1
  +++ PropertySuppressionStrategy.java  6 Oct 2004 21:38:05 -0000       1.2
  @@ -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 
) ) {
  @@ -39,10 +39,11 @@
       };
       
       /**
  -     * Should the given property be supressed?
  +     * Should the given property be suppressed?
  +     * @param classContainingTheProperty <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 classContainingTheProperty, 
Class propertyType, String propertyName);
   }
  
  
  
  1.2       +1 -1      
jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/derived/TestWriteClass.java
  
  Index: TestWriteClass.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/derived/TestWriteClass.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestWriteClass.java       4 Oct 2004 21:52:40 -0000       1.1
  +++ TestWriteClass.java       6 Oct 2004 21:38:05 -0000       1.2
  @@ -63,7 +63,7 @@
           
writer.getXMLIntrospector().getConfiguration().setPropertySuppressionStrategy(
                   new PropertySuppressionStrategy() {
   
  -                    public boolean suppressProperty(Class propertyType, String 
propertyName) {
  +                    public boolean suppressProperty(Class 
classContainingThePropety, Class propertyType, String propertyName) {
                           if ("class".equals(propertyName)) {
                               return true;
                           }
  
  
  
  1.11      +39 -5     jakarta-commons/betwixt/xdocs/guide/binding.xml
  
  Index: binding.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/xdocs/guide/binding.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- binding.xml       4 Oct 2004 21:49:20 -0000       1.10
  +++ binding.xml       6 Oct 2004 21:38:06 -0000       1.11
  @@ -501,8 +501,39 @@
   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 contains 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 classContainingTheProperty,
  +                     Class propertyType, String propertyName) {
  +                 if (Class.class.equals(propertyType) 
  +                         && "class".equals(propertyName)) {
  +                         
  +                     if (!Throwable.class
  +                                .isAssignableFrom(classContainingTheProperty)) {
  +                        return true;
  +                     }
  +                 }
  +                 return false;
  +             }
  +         });
  +]]></source></p>
       </subsection>
   </section>
   
  @@ -548,13 +579,15 @@
   For example, to delegate to <code>ConvertUtils</code> for <em>all</em> conversions 
in a read:
   <code><pre>
       BeanReader reader = new BeanReader();
  -    reader.getBindingConfiguration().setObjectStringConverter(new 
ConvertUtilsObjectStringConverter());
  +    reader.getBindingConfiguration()
  +        .setObjectStringConverter(new ConvertUtilsObjectStringConverter());
       reader.parse...
   </pre></code>
   and in a write:
   <code><pre>
       BeanWriter writer = new BeanWriter();
  -    writer.getBindingConfiguration().setObjectStringConverter(new 
ConvertUtilsObjectStringConverter());
  +    writer.getBindingConfiguration()
  +        .setObjectStringConverter(new ConvertUtilsObjectStringConverter());
       writer.write...
   </pre></code>
           </p>
  @@ -720,7 +753,8 @@
                "     </betwixt-config>";
                    BeanWriter beanWriter = new BeanWriter(outputWriter);
   ...
  -                 beanWriter.getXMLIntrospector().register(new InputSource(new 
StringReader(MAPPING)));
  +                 beanWriter.getXMLIntrospector()
  +                 .register(new InputSource(new StringReader(MAPPING)));
                    beanWriter.write(partyBean);
   ]]>
           </source>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to