java.lang.Object | |
↳ | org.springframework.core.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.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new Constants converter class wrapping the given class.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return a constant value cast to a Number.
| |||||||||||
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 that we're analysing.
| |||||||||||
Return a constant value as a String.
| |||||||||||
Return the name of the analyzed class.
| |||||||||||
Return all names of the given group of constants.
| |||||||||||
Return all names of the group of constants for the
given bean property name.
| |||||||||||
Return all names of the given group of constants.
| |||||||||||
Return the number of constants exposed.
| |||||||||||
Return all values of the given group of constants.
| |||||||||||
Return all values of the group of constants for the
given bean property name.
| |||||||||||
Return all values of the given group of constants.
| |||||||||||
Convert the given bean property name to a constant name prefix.
| |||||||||||
Look up the given value within the given group of constants.
| |||||||||||
Look up the given value within the group of constants for
the given bean property name.
| |||||||||||
Look up the given value within the given group of constants.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Exposes the field cache to subclasses:
a Map from String field name to object value.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Create a new Constants converter class wrapping the given class.
All public static final variables will be exposed, whatever their type.
clazz | the class to analyze |
---|
IllegalArgumentException | if the supplied clazz is null
|
---|
Return a constant value cast to a Number.
code | the name of the field (never null ) |
---|
ConstantException | if the field name wasn't found or if the type wasn't compatible with Number |
---|
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 that we're analysing.
code | the name of the field (never null ) |
---|
ConstantException | if there's no such field |
---|
Return a constant value as a String.
code | the name of the field (never null ) |
---|
toString()
).ConstantException | if the field name wasn't found |
---|
Return all names of the given group of constants.
Note that this method assumes that constants are named
in accordance with the standard Java convention for constant
values (i.e. all uppercase). The supplied namePrefix
will be uppercased (in a locale-insensitive fashion) prior to
the main logic of this method kicking in.
namePrefix | prefix of the constant names to search (may be null ) |
---|
Return all names of the group of constants for the given bean property name.
propertyName | the name of the bean property |
---|
Return all names of the given group of constants.
Note that this method assumes that constants are named
in accordance with the standard Java convention for constant
values (i.e. all uppercase). The supplied nameSuffix
will be uppercased (in a locale-insensitive fashion) prior to
the main logic of this method kicking in.
nameSuffix | suffix of the constant names to search (may be null ) |
---|
Return all values of the given group of constants.
Note that this method assumes that constants are named
in accordance with the standard Java convention for constant
values (i.e. all uppercase). The supplied namePrefix
will be uppercased (in a locale-insensitive fashion) prior to
the main logic of this method kicking in.
namePrefix | prefix of the constant names to search (may be null ) |
---|
Return all values of the group of constants for the given bean property name.
propertyName | the name of the bean property |
---|
Return all values of the given group of constants.
Note that this method assumes that constants are named
in accordance with the standard Java convention for constant
values (i.e. all uppercase). The supplied nameSuffix
will be uppercased (in a locale-insensitive fashion) prior to
the main logic of this method kicking in.
nameSuffix | suffix of the constant names to search (may be null ) |
---|
Convert the given bean property name to a constant name prefix.
Uses a common naming idiom: turning all lower case characters to upper case, and prepending upper case characters with an underscore.
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 |
---|
Look up the given value within the given group of constants.
Will return the first match.
value | constant value to look up |
---|---|
namePrefix | prefix of the constant names to search (may be null ) |
ConstantException | if the value wasn't found |
---|
Look up the given value within the group of constants for the given bean property name. Will return the first match.
value | constant value to look up |
---|---|
propertyName | the name of the bean property |
ConstantException | if the value wasn't found |
---|
Look up the given value within the given group of constants.
Will return the first match.
value | constant value to look up |
---|---|
nameSuffix | suffix of the constant names to search (may be null ) |
ConstantException | if the value wasn't found |
---|
Exposes the field cache to subclasses: a Map from String field name to object value.