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 org.apache.commons.betwixt.AttributeDescriptor;
19  
20  /***
21   * Determines whether the expression of an attribute with a values 
22   * should be suppressed.
23   *
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 ValueSuppressionStrategy {
28      
29      /***
30       * Strategy allows all values to be expressed for all attributes
31       */
32      public static final ValueSuppressionStrategy ALLOW_ALL_VALUES = new ValueSuppressionStrategy() {
33          public boolean suppressAttribute(AttributeDescriptor attributeDescriptor, String value) {
34              return true;
35          }
36      };
37  
38      /***
39       * Suppresses all null values.
40       */
41      public static final ValueSuppressionStrategy SUPPRESS_EMPTY = new ValueSuppressionStrategy() {
42          public boolean suppressAttribute(AttributeDescriptor attributeDescriptor, String value) {
43              return "".equals(value);
44          } 
45      };
46      
47      /***
48       * Default strategy is {@link #SUPPRESS_EMPTY}.
49       */
50      public static final ValueSuppressionStrategy DEFAULT = SUPPRESS_EMPTY;
51  
52      
53      /***
54       * Should the given attribute value be suppressed?
55       * @param attributeDescriptor <code>AttributeDescriptor</code> describing the attribute, not null
56       * @param value <code>Object</code> value, possibly null
57       * @return true if the attribute should not be written for the given value
58       */
59      public abstract boolean suppressAttribute(AttributeDescriptor attributeDescriptor, String value);
60  
61  }