Package org.springframework.expression.spel.support

# Class StandardTypeLocator

java.lang.Object
org.springframework.expression.spel.support.StandardTypeLocator

All Implemented Interfaces:
  `TypeLocator`

public class StandardTypeLocator extends Object implements 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

Constructors
Constructor
Description
`StandardTypeLocator()`
Create a `StandardTypeLocator` for the default `ClassLoader` (typically, the thread context `ClassLoader`).
`StandardTypeLocator(ClassLoader classLoader)`
Create a `StandardTypeLocator` for the given `ClassLoader`.

## Method Summary

Modifier and Type
Method
Description
`Class<?>`
`findType(String typeName)`
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.
`List<String>`
`getImportPrefixes()`
Get the list of import prefixes registered with this `StandardTypeLocator`.
`void`
`registerImport(String prefix)`
Register a new import prefix that will be used when searching for unqualified types.
`void`
`removeImport(String prefix)`
Remove the specified prefix from this locator's list of imports.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### StandardTypeLocator

public StandardTypeLocator()
Create a `StandardTypeLocator` for the default `ClassLoader` (typically, the thread context `ClassLoader`).

Favor `StandardTypeLocator(ClassLoader)` over this constructor in order to provide a specific `ClassLoader` that is able to reliably locate user types.

See Also:
  - `ClassUtils.getDefaultClassLoader()`

### StandardTypeLocator

public StandardTypeLocator(@Nullable ClassLoader classLoader)
Create a `StandardTypeLocator` for the given `ClassLoader`.

Favor this constructor over `StandardTypeLocator()` in order to provide a specific `ClassLoader` that is able to reliably locate user types.

Parameters:
  `classLoader` - the `ClassLoader` to delegate to

## Method Details

### registerImport

public void registerImport(String prefix)
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

public void removeImport(String prefix)
Remove the specified prefix from this locator's list of imports.

Parameters:
  `prefix` - the import prefix to remove

### getImportPrefixes

public List<String> getImportPrefixes()
Get the list of import prefixes registered with this `StandardTypeLocator`.

Returns:
  the list of registered import prefixes

### findType

public Class<?> findType(String typeName) throws EvaluationException
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:
  `findType` in interface `TypeLocator`
Parameters:
  `typeName` - the type to locate
Returns:
  the class object for the type
Throws:
  `EvaluationException` - if the type cannot be found