View Javadoc

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