1 package net.sourceforge.pmd.properties; 2 3 import net.sourceforge.pmd.util.ClassUtil; 4 5 6 12 public class TypeProperty extends StringProperty { 13 14 private static final char delimiter = '|'; 15 16 23 public TypeProperty(String theName, String theDescription, Class theDefault, float theUIOrder) { 24 super(theName, theDescription, theDefault, theUIOrder, delimiter); 25 26 maxValueCount(1); 27 } 28 29 36 public TypeProperty(String theName, String theDescription, Class [] theDefaults, float theUIOrder) { 37 super(theName, theDescription, theDefaults, theUIOrder, delimiter); 38 39 maxValueCount(Integer.MAX_VALUE); 40 } 41 42 47 public Class type() { 48 return Class .class; 49 } 50 51 56 protected String asString(Object value) { 57 return value == null ? "" : ((Class )value).getName(); 58 } 59 60 65 private Class classFrom(String className) { 66 67 Class cls = ClassUtil.getTypeFor(className); 68 if (cls != null) return cls; 69 70 try { 71 return Class.forName(className); 72 } catch (Exception ex) { 73 throw new IllegalArgumentException (className); 74 } 75 } 76 77 83 public Object valueFrom(String valueString) { 84 85 if (maxValueCount() == 1) return classFrom(valueString); 86 87 String [] values = (String [])super.valueFrom(valueString); 88 89 Class [] classes = new Class [values.length]; 90 for (int i=0; i<values.length; i++) classes[i] = classFrom(values[i]); 91 return classes; 92 } 93 94 101 protected String valueErrorFor(Object value) { 102 return null; 103 } 104 } 105 | Popular Tags |