Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
ValueSuppressionStrategy |
|
| 1.0;1 |
1 | 935 | /* |
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 | import org.apache.commons.betwixt.ElementDescriptor; |
|
20 | ||
21 | /** |
|
22 | * Determines whether the expression of an attribute with a values |
|
23 | * should be suppressed. |
|
24 | * |
|
25 | * @since 0.7 |
|
26 | * @author <a href='http://commons.apache.org'>Apache Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a> |
|
27 | */ |
|
28 | 2857 | public abstract class ValueSuppressionStrategy { |
29 | ||
30 | /** |
|
31 | * Strategy allows all values to be expressed for all attributes |
|
32 | */ |
|
33 | 935 | public static final ValueSuppressionStrategy ALLOW_ALL_VALUES = new ValueSuppressionStrategy() { |
34 | public boolean suppressAttribute(AttributeDescriptor attributeDescriptor, String value) { |
|
35 | 156 | return false; |
36 | } |
|
37 | }; |
|
38 | ||
39 | /** |
|
40 | * Suppresses all null values. |
|
41 | */ |
|
42 | 935 | public static final ValueSuppressionStrategy SUPPRESS_EMPTY = new ValueSuppressionStrategy() { |
43 | public boolean suppressAttribute(AttributeDescriptor attributeDescriptor, String value) { |
|
44 | 7267 | return "".equals(value); |
45 | } |
|
46 | }; |
|
47 | ||
48 | /** |
|
49 | * Default strategy is {@link #SUPPRESS_EMPTY}. |
|
50 | */ |
|
51 | 935 | public static final ValueSuppressionStrategy DEFAULT = SUPPRESS_EMPTY; |
52 | ||
53 | ||
54 | /** |
|
55 | * Should the given attribute value be suppressed? |
|
56 | * @param attributeDescriptor <code>AttributeDescriptor</code> describing the attribute, not null |
|
57 | * @param value <code>Object</code> value, possibly null |
|
58 | * @return true if the attribute should not be written for the given value |
|
59 | */ |
|
60 | public abstract boolean suppressAttribute(AttributeDescriptor attributeDescriptor, String value); |
|
61 | ||
62 | /** |
|
63 | * <p> |
|
64 | * Should be given element value be suppressed? |
|
65 | * </p><p> |
|
66 | * <strong>Note:</strong> to preserve binary compatibility, |
|
67 | * this method contains an implementation that returns false. |
|
68 | * Subclasses should not rely upon this behaviour as (in future) |
|
69 | * this may be made abstract. |
|
70 | * </p> |
|
71 | * @param element <code>ElementDescriptor</code> describing the element, not null |
|
72 | * @param namespaceUri the namespace of the element to be written |
|
73 | * @param localName the local name of the element to be written |
|
74 | * @param qualifiedName the qualified name of the element to be written |
|
75 | * @param value <code>Object</code> value, possibly null |
|
76 | * @return true if the element should be suppressed (in other words, not written) |
|
77 | * for the given value |
|
78 | */ |
|
79 | public boolean suppressElement(ElementDescriptor element, String namespaceUri, String localName, String qualifiedName, Object value) { |
|
80 | 17126 | return false; |
81 | } |
|
82 | } |