PropertyDescriptorWrapper.java
001 package net.sourceforge.pmd.lang.rule.properties;
002 
003 import java.util.Map;
004 
005 import net.sourceforge.pmd.PropertyDescriptor;
006 import net.sourceforge.pmd.Rule;
007 
008 /**
009  * This class serves as a wrapper class for a PropertyDescriptor instance.
010  * It exists to allowing the {@link PropertyDescriptorFactory} to readily
011  * flag properties it has created, versus those created by Rule classes.
012  * This is used in the encoding of a Rule to XML format to distinguish Rule
013  * defined PropertyDescriptors and those which were originally defined in XML.
014  
015  @param <T> The type of the underlying PropertyDescriptor.
016  */
017 public class PropertyDescriptorWrapper<T> implements PropertyDescriptor<T> {
018     private final PropertyDescriptor<T> propertyDescriptor;
019 
020     public PropertyDescriptorWrapper(PropertyDescriptor<T> propertyDescriptor) {
021   if (propertyDescriptor == null) {
022       throw new IllegalArgumentException("PropertyDescriptor cannot be null.");
023   }
024   this.propertyDescriptor = propertyDescriptor;
025     }
026 
027     public PropertyDescriptor<T> getPropertyDescriptor() {
028   return propertyDescriptor;
029     }
030 
031     public String asDelimitedString(T value) {
032   return propertyDescriptor.asDelimitedString(value);
033     }
034 
035     public Object[][] choices() {
036   return propertyDescriptor.choices();
037     }
038 
039     public int compareTo(PropertyDescriptor<?> o) {
040   return propertyDescriptor.compareTo(o);
041     }
042 
043     public T defaultValue() {
044   return propertyDescriptor.defaultValue();
045     }
046 
047     public String description() {
048   return propertyDescriptor.description();
049     }
050 
051     public String errorFor(Object value) {
052   return propertyDescriptor.errorFor(value);
053     }
054 
055     public boolean isMultiValue() {
056   return propertyDescriptor.isMultiValue();
057     }
058 
059     public boolean isRequired() {
060   return propertyDescriptor.isRequired();
061     }
062 
063     public char multiValueDelimiter() {
064   return propertyDescriptor.multiValueDelimiter();
065     }
066 
067     public String name() {
068   return propertyDescriptor.name();
069     }
070 
071     public int preferredRowCount() {
072   return propertyDescriptor.preferredRowCount();
073     }
074 
075     public String propertyErrorFor(Rule rule) {
076   return propertyDescriptor.propertyErrorFor(rule);
077     }
078 
079     public Class<T> type() {
080   return propertyDescriptor.type();
081     }
082 
083     public float uiOrder() {
084   return propertyDescriptor.uiOrder();
085     }
086 
087     public T valueFrom(String propertyStringthrows IllegalArgumentException {
088   return propertyDescriptor.valueFrom(propertyString);
089     }
090 
091     public Map<String, String> attributeValuesById() {
092         return propertyDescriptor.attributeValuesById();
093     }
094 
095     @Override
096     public boolean equals(Object obj) {
097       if (obj instanceof PropertyDescriptorWrapper) {
098           return this.getPropertyDescriptor().equals(((PropertyDescriptorWrapperobj).getPropertyDescriptor());
099       
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 }