public class ConstantLookup extends org.apache.commons.lang.text.StrLookup
A specialized lookup implementation that allows access to constant fields of classes.
Sometimes it is necessary in a configuration file to refer to a constant
defined in a class. This can be done with this lookup implementation.
Variable names passed in must be of the form
will split the passed in string at the last dot, separating the fully
qualified class name and the name of the constant (i.e. static final)
member field. Then the class is loaded and the field's value is obtained
Once retrieved values are cached for fast access. This class is thread-safe. It can be used as a standard (i.e. global) lookup object and serve multiple clients concurrently.
|Constructor and Description|
|Modifier and Type||Method and Description|
Clears the shared cache with the so far resolved constants.
Loads the class with the specified name.
Tries to resolve the specified variable.
Determines the value of the specified constant member field of a class.
mapLookup, noneLookup, systemPropertiesLookup
resolveField()method and pass in the name of the class and the field.
var- the name of the variable to be resolved
public static void clear()
protected Object resolveField(String className, String fieldName) throws Exception
fetchClass()to obtain the
java.lang.Classobject for the target class. Then it will use reflection to obtain the field's value. For this to work the field must be accessable.
className- the name of the class
fieldName- the name of the member field of that class to read
Exception- if an error occurs
protected Class<?> fetchClass(String className) throws ClassNotFoundException
getClass()method of Commons Lang's
className- the name of the class to be loaded
ClassNotFoundException- if the class cannot be loaded
Copyright © 2001–2013 The Apache Software Foundation. All rights reserved.