View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.rule.properties;
5   
6   import java.util.Map;
7   
8   import net.sourceforge.pmd.PropertyDescriptor;
9   import net.sourceforge.pmd.Rule;
10  
11  /**
12   * This class serves as a wrapper class for a PropertyDescriptor instance. It
13   * exists to allowing the {@link PropertyDescriptorFactory} to readily flag
14   * properties it has created, versus those created by Rule classes. This is used
15   * in the encoding of a Rule to XML format to distinguish Rule defined
16   * PropertyDescriptors and those which were originally defined in XML.
17   * 
18   * @param <T> The type of the underlying PropertyDescriptor.
19   */
20  public class PropertyDescriptorWrapper<T> implements PropertyDescriptor<T> {
21      private final PropertyDescriptor<T> propertyDescriptor;
22  
23      public PropertyDescriptorWrapper(PropertyDescriptor<T> propertyDescriptor) {
24          if (propertyDescriptor == null) {
25              throw new IllegalArgumentException("PropertyDescriptor cannot be null.");
26          }
27          this.propertyDescriptor = propertyDescriptor;
28      }
29  
30      public PropertyDescriptor<T> getPropertyDescriptor() {
31          return propertyDescriptor;
32      }
33  
34      public String asDelimitedString(T value) {
35          return propertyDescriptor.asDelimitedString(value);
36      }
37  
38      public Object[][] choices() {
39          return propertyDescriptor.choices();
40      }
41  
42      public int compareTo(PropertyDescriptor<?> o) {
43          return propertyDescriptor.compareTo(o);
44      }
45  
46      public T defaultValue() {
47          return propertyDescriptor.defaultValue();
48      }
49  
50      public String description() {
51          return propertyDescriptor.description();
52      }
53  
54      public String errorFor(Object value) {
55          return propertyDescriptor.errorFor(value);
56      }
57  
58      public boolean isMultiValue() {
59          return propertyDescriptor.isMultiValue();
60      }
61  
62      public boolean isRequired() {
63          return propertyDescriptor.isRequired();
64      }
65  
66      public char multiValueDelimiter() {
67          return propertyDescriptor.multiValueDelimiter();
68      }
69  
70      public String name() {
71          return propertyDescriptor.name();
72      }
73  
74      public int preferredRowCount() {
75          return propertyDescriptor.preferredRowCount();
76      }
77  
78      public String propertyErrorFor(Rule rule) {
79          return propertyDescriptor.propertyErrorFor(rule);
80      }
81  
82      public Class<T> type() {
83          return propertyDescriptor.type();
84      }
85  
86      public float uiOrder() {
87          return propertyDescriptor.uiOrder();
88      }
89  
90      public T valueFrom(String propertyString) throws IllegalArgumentException {
91          return propertyDescriptor.valueFrom(propertyString);
92      }
93  
94      public Map<String, String> attributeValuesById() {
95          return propertyDescriptor.attributeValuesById();
96      }
97  
98      @Override
99      public boolean equals(Object obj) {
100         if (obj instanceof PropertyDescriptorWrapper) {
101             return this.getPropertyDescriptor().equals(((PropertyDescriptorWrapper<?>) obj).getPropertyDescriptor());
102         }
103         return this.getPropertyDescriptor().equals(obj);
104     }
105 
106     @Override
107     public int hashCode() {
108         return this.getPropertyDescriptor().hashCode();
109     }
110 
111     @Override
112     public String toString() {
113         return "wrapped:" + propertyDescriptor.toString();
114     }
115 }