|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.core.Constants
public class Constants
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 asNumber
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. |
String |
getClassName()
Return the name of the analyzed class. |
protected Map |
getFieldCache()
Exposes the field cache to subclasses: a Map from String field name to object value. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Constants(Class clazz)
clazz
- the class to analyzeMethod Detail |
---|
public final String getClassName()
public final int getSize()
protected final Map getFieldCache()
public Number asNumber(String code) throws ConstantException
code
- name of the field
ConstantException
- if the field name wasn't found
or if the type wasn't compatible with NumberasObject(java.lang.String)
public String asString(String code) throws ConstantException
code
- name of the field
ConstantException
- if the field name wasn't foundasObject(java.lang.String)
public Object asObject(String code) throws ConstantException
ConstantException
- if there's no such fieldpublic Set getValues(String namePrefix)
namePrefix
- prefix of the constant names to search
public Set getValuesForProperty(String propertyName)
propertyName
- the name of the bean property
propertyToConstantNamePrefix(java.lang.String)
public String toCode(Object value, String namePrefix) throws ConstantException
value
- constant value to look upnamePrefix
- prefix of the constant names to search
ConstantException
- if the value wasn't foundpublic String toCodeForProperty(Object value, String propertyName) throws ConstantException
value
- constant value to look uppropertyName
- the name of the bean property
ConstantException
- if the value wasn't foundpropertyToConstantNamePrefix(java.lang.String)
public String propertyToConstantNamePrefix(String propertyName)
Example: "imageSize" -> "IMAGE_SIZE"
Example: "imagesize" -> "IMAGESIZE".
Example: "ImageSize" -> "_IMAGE_SIZE".
Example: "IMAGESIZE" -> "_I_M_A_G_E_S_I_Z_E"
propertyName
- the name of the bean property
getValuesForProperty(java.lang.String)
,
toCodeForProperty(java.lang.Object, java.lang.String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |