| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This class can be used to parse other classes containing constant definitions in public static final members. The asXXXX() methods of this class allow these constant values to be accessed via their string names.
Consider class Foo containing public final static int CONSTANT1 = 66; An instance of this class wrapping Foo.class will return the constant value of 66 from its asInt() method given the argument "CONSTANT1".
This class is ideal for use in PropertyEditors, enabling them to recognize the same names as the constants themselves, and freeing them from maintaining their own mapping.
| Constructor Summary | |
Constants(Class clazz)Create a new Constants converter class wrapping the given class. | |
| Method Summary | |
Number | asNumber(String code)Return a constant value cast to a Number. |
Object | asObject(String code)Parse the given string (upper or lower case accepted) and return the appropriate value if it's the name of a constant field in the class we're analysing. |
String | asString(String code)Return a constant value as a String. |
int | getSize()Return the number of constants exposed. |
Set | getValues(String namePrefix)Return all values of the given group of constants. |
Set | getValuesForProperty(String propertyName)Return all values of the group of constants for the given bean property name. |
String | propertyToConstantNamePrefix(String propertyName)Convert the given bean property name to a constant name prefix. |
String | toCode(Object value, String namePrefix)Look up the given value within the given group of constants. |
String | toCodeForProperty(Object value, String propertyName)Look up the given value within the group of constants for the given bean property name. |
| Constructor Detail |
public Constants(Class clazz)
| Method Detail |
public Number asNumber(String code)
throws ConstantException
public Object asObject(String code)
throws ConstantException
public String asString(String code)
throws ConstantException
public int getSize()
public Set getValues(String namePrefix)
public Set getValuesForProperty(String propertyName)
public String propertyToConstantNamePrefix(String propertyName)
Example: "imageSize" -> "IMAGE_SIZE".
public String toCode(Object value, String namePrefix)
throws ConstantException
public String toCodeForProperty(Object value, String propertyName)
throws ConstantException
| Association Links |
to Class java.lang.Class
| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||