01: package net.sourceforge.pmd.properties;
02:
03: import net.sourceforge.pmd.util.StringUtil;
04:
05: /**
06: * No, subclasses are not necessarily scalar per se, they're just easy to parse without error.
07: * If you can come up with a better name...
08: *
09: * @author Brian Remedios
10: * @version $Revision$
11: */
12: public abstract class AbstractScalarProperty extends
13: AbstractPMDProperty {
14:
15: /**
16: * Constructor for AbstractScalarProperty.
17: * @param theName String
18: * @param theDescription String
19: * @param theDefault Object
20: * @param theUIOrder float
21: */
22: public AbstractScalarProperty(String theName,
23: String theDescription, Object theDefault, float theUIOrder) {
24: super (theName, theDescription, theDefault, theUIOrder);
25: }
26:
27: /**
28: * Method createFrom.
29: * @param value String
30: * @return Object
31: */
32: protected abstract Object createFrom(String value);
33:
34: /**
35: * Method arrayFor.
36: * @param size int
37: * @return Object[]
38: */
39: protected abstract Object[] arrayFor(int size);
40:
41: /**
42: * Method valueFrom.
43: * @param valueString String
44: * @return Object[]
45: * @throws IllegalArgumentException
46: * @see net.sourceforge.pmd.PropertyDescriptor#valueFrom(String)
47: */
48: public Object valueFrom(String valueString)
49: throws IllegalArgumentException {
50:
51: if (maxValueCount() == 1)
52: return createFrom(valueString);
53:
54: String[] strValues = StringUtil.substringsOf(valueString,
55: multiValueDelimiter);
56:
57: Object[] values = arrayFor(strValues.length);
58: for (int i = 0; i < strValues.length; i++)
59: values[i] = createFrom(strValues[i]);
60: return values;
61: }
62: }
|