Interface ClassMapper
- All Known Implementing Classes:
DefaultClassMapper
public interface ClassMapper
Maps names or classes to classes.
- Author:
- harald
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ClassMappedListener listener) Adds a class mapped listener.static ClassMapperCreates a class mapper for a given mapped service.
The mapper maintains a map of implementation classes to other classes (usually interfaces).Class<?> Gets the default class.
Returned if there is no mapping.getMap()Gets a copy of the names map.Class<?> Maps a class or interface to another class or interface.Class<?> Maps a class or interface to another class or interface by its name.Class<?> mapLenient(Class<?> clazz) Maps a class or interface to another class or interface.
If there is no mapping forclazz, its superclasses are tried.Class<?> mapLenient(String name) Maps a name to a class.
Same asmapLenient(Class), but for a class name.voidRemoves all class mapped listeners.booleanremoveListener(ClassMappedListener listener) Removes a class mapped listener.voidsetDefaultClass(Class<?> defaultClass) Sets the default class.
If there is no matching class, the mapper returns this class.
-
Method Details
-
create
Creates a class mapper for a given mapped service.
The mapper maintains a map of implementation classes to other classes (usually interfaces).- Parameters:
name- the mapper's namemappedClass- class of the mapped service- Returns:
- the classmapper
- See Also:
-
map
Maps a class or interface to another class or interface.- Parameters:
clazz- the class to map- Returns:
- the mapped class, never null
- Throws:
ClassNotFoundException- if there is no mapping
-
map
Maps a class or interface to another class or interface by its name.- Parameters:
name- the name or basename of the class to map- Returns:
- the mapped class, never null
- Throws:
ClassNotFoundException- if there is no mapping
-
mapLenient
Maps a class or interface to another class or interface.
If there is no mapping forclazz, its superclasses are tried. If none of them is mapped, the interfaces ofclazzand its superclasses (including their super interfaces) are tried.- Parameters:
clazz- the class to map- Returns:
- the mapped class, never null
- Throws:
ClassNotFoundException- if there is no mapping
-
mapLenient
Maps a name to a class.
Same asmapLenient(Class), but for a class name.- Parameters:
name- the name to map- Returns:
- the mapped class, never null
- Throws:
ClassNotFoundException- if there is no mapping
-
getDefaultClass
Class<?> getDefaultClass()Gets the default class.
Returned if there is no mapping.- Returns:
- the class, null if no default
-
setDefaultClass
Sets the default class.
If there is no matching class, the mapper returns this class.- Parameters:
defaultClass- the default class
-
getMap
-
addListener
Adds a class mapped listener.- Parameters:
listener- invoked whenever a class is mapped the first time
-
removeListener
Removes a class mapped listener.- Parameters:
listener- the listener- Returns:
- true if removed, false if no such listener
-
removeAllListeners
void removeAllListeners()Removes all class mapped listeners.
-