Class StandardTypeLocator
java.lang.Object
org.springframework.expression.spel.support.StandardTypeLocator
- All Implemented Interfaces:
TypeLocator
A simple implementation of
TypeLocator that uses the default
ClassLoader or a supplied
ClassLoader to locate types.
Supports well-known packages, registered as import prefixes. If a type cannot be found, this class will attempt to locate it using the registered import prefixes.
- Since:
- 3.0
- Author:
- Andy Clement, Juergen Hoeller, Sam Brannen
-
Constructor Summary
ConstructorsConstructorDescriptionCreate aStandardTypeLocatorfor the defaultClassLoader(typically, the thread contextClassLoader).StandardTypeLocator(@Nullable ClassLoader classLoader) Create aStandardTypeLocatorfor the givenClassLoader. -
Method Summary
Modifier and TypeMethodDescriptionClass<?> Find a (possibly unqualified) type reference, first using the type name as-is, and then trying any registered import prefixes if the type name cannot be found.Get the list of import prefixes registered with thisStandardTypeLocator.voidregisterImport(String prefix) Register a new import prefix that will be used when searching for unqualified types.voidremoveImport(String prefix) Remove the specified prefix from this locator's list of imports.
-
Constructor Details
-
StandardTypeLocator
public StandardTypeLocator()Create aStandardTypeLocatorfor the defaultClassLoader(typically, the thread contextClassLoader).Favor
StandardTypeLocator(ClassLoader)over this constructor in order to provide a specificClassLoaderthat is able to reliably locate user types.- See Also:
-
StandardTypeLocator
Create aStandardTypeLocatorfor the givenClassLoader.Favor this constructor over
StandardTypeLocator()in order to provide a specificClassLoaderthat is able to reliably locate user types.- Parameters:
classLoader- theClassLoaderto delegate to
-
-
Method Details
-
registerImport
Register a new import prefix that will be used when searching for unqualified types.Expected format is something like
"java.lang".- Parameters:
prefix- the import prefix to register
-
removeImport
Remove the specified prefix from this locator's list of imports.- Parameters:
prefix- the import prefix to remove
-
getImportPrefixes
-
findType
Find a (possibly unqualified) type reference, first using the type name as-is, and then trying any registered import prefixes if the type name cannot be found.- Specified by:
findTypein interfaceTypeLocator- Parameters:
typeName- the type to locate- Returns:
- the class object for the type
- Throws:
EvaluationException- if the type cannot be found
-