View Javadoc

1   /*
2    * Copyright 2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */ 
16  package org.apache.commons.betwixt.strategy;
17  
18  import java.util.Collection;
19  
20  /***
21   * Pluggable strategy specifying whether property's should be surpressed.
22   * Implementations can be used to give rules about which properties 
23   * should be ignored by Betwixt when introspecting.
24   * @since 0.7
25   * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a>
26   */
27  public abstract class PropertySuppressionStrategy {
28  
29      /***
30       * Default implementation supresses the class property
31       * found on every object. Also, the <code>isEmpty</code>
32       * property is supressed for implementations of <code>Collection</code>.
33       */
34      public static final PropertySuppressionStrategy DEFAULT = new PropertySuppressionStrategy() {
35          public boolean suppressProperty(Class clazz, Class propertyType, String propertyName) {
36              boolean result = false;
37              // ignore class properties
38              if ( Class.class.equals( propertyType) && "class".equals( propertyName ) ) {
39                  result = true;
40              }
41              // ignore isEmpty for collection subclasses
42              if ( "empty".equals( propertyName ) && Collection.class.isAssignableFrom( clazz )) {
43                  result = true;
44              }
45              
46              return result;
47          }
48      };
49      
50      /***
51       * Should the given property be suppressed?
52       * @param classContainingTheProperty <code>Class</code> giving the type of the bean containing the property <code>propertyName</code>
53       * @param propertyType <code>Class</code> giving the type of the property, not null
54       * @param propertyName the name of the property, not null
55       * @return true when the given property should be suppressed
56       */
57      public abstract boolean suppressProperty(Class classContainingTheProperty, Class propertyType, String propertyName);
58  }