Class DefaultClassMapper
- All Implemented Interfaces:
ClassMapper
A default implementation of a class mapper.
The map is either initialized from a map or a
The map is either initialized from a map or a
Properties-object which in turn
could be loaded from a properties file, an XML-file or constructed at runtime.- Author:
- harald
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultClassMapper(String name, Class<?> mappedClass) Creates a class mapper for a given mapped service class.
This is the most common usage of a class mapper.DefaultClassMapper(String name, ClassLoader classLoader, Map<String, String> nameMap, String[] packageNames) Constructs a class mapper.DefaultClassMapper(String name, ClassLoader classLoader, Properties nameProps, String[] packageNames) Constructs a class mapper.DefaultClassMapper(String name, String mappedServiceName) Creates a class mapper for a given mapped service name. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ClassMappedListener listener) Adds a class mapped listener.Class<?> Gets the default class.getMap()Gets a copy of the names map.Gets the mapping of service names.
The key is the name of the service to map, and the value is the name of the mapped object.String[]Gets the list of package names.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 forclazzits superclasses are tried.Class<?> mapLenient(String name) Maps a name to a class.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.Methods inherited from class AbstractClassMapper
getLogLevel, getName, map, setLogLevel, toString
-
Constructor Details
-
DefaultClassMapper
public DefaultClassMapper(String name, ClassLoader classLoader, Map<String, String> nameMap, String[] packageNames) Constructs a class mapper.- Parameters:
name- the mapper's nameclassLoader- the classloadernameMap- the mapping of classnamespackageNames- the package names, null or empty array if none
-
DefaultClassMapper
public DefaultClassMapper(String name, ClassLoader classLoader, Properties nameProps, String[] packageNames) Constructs a class mapper.- Parameters:
name- the mapper's nameclassLoader- the classloadernameProps- the properties holding the mapping.packageNames- the package names, null or empty array if none
-
DefaultClassMapper
-
DefaultClassMapper
-
-
Method Details
-
getNameMap
Description copied from class:AbstractClassMapperGets the mapping of service names.
The key is the name of the service to map, and the value is the name of the mapped object.- Specified by:
getNameMapin classAbstractClassMapper<String>- Returns:
- the names-map, never null.
-
getPackageNames
Description copied from class:AbstractClassMapperGets the list of package names.- Specified by:
getPackageNamesin classAbstractClassMapper<String>- Returns:
- the array of package names, null or empty array if none.
-
getDefaultClass
Description copied from interface:ClassMapperGets the default class.- Specified by:
getDefaultClassin interfaceClassMapper- Returns:
- the class, null if no default
-
setDefaultClass
Description copied from interface:ClassMapperSets the default class.
If there is no matching class, the mapper returns this class.- Specified by:
setDefaultClassin interfaceClassMapper- Parameters:
defaultClass- the default class
-
getMap
Description copied from interface:ClassMapperGets a copy of the names map.- Specified by:
getMapin interfaceClassMapper- Returns:
- the unmodifiable map of names
-
map
Description copied from interface:ClassMapperMaps a class or interface to another class or interface.- Specified by:
mapin interfaceClassMapper- Parameters:
clazz- the class to map- Returns:
- the mapped class, never null
- Throws:
ClassNotFoundException- if there is no mapping
-
map
Description copied from interface:ClassMapperMaps a class or interface to another class or interface by its name.- Specified by:
mapin interfaceClassMapper- 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
Description copied from interface:ClassMapperMaps a class or interface to another class or interface.
If there is no mapping forclazzits superclasses are tried. Ifclazzis an interface, all its super interfaces are tried.Notice: for classes their interfaces will be ignored.
- Specified by:
mapLenientin interfaceClassMapper- Parameters:
clazz- the class to map- Returns:
- the mapped class, never null
- Throws:
ClassNotFoundException- if there is no mapping
-
mapLenient
Description copied from interface:ClassMapperMaps a name to a class.- Specified by:
mapLenientin interfaceClassMapper- Parameters:
name- the name to map- Returns:
- the mapped class, never null
- Throws:
ClassNotFoundException- if there is no mapping
-
addListener
Description copied from interface:ClassMapperAdds a class mapped listener.- Specified by:
addListenerin interfaceClassMapper- Parameters:
listener- invoked whenever a class is mapped the first time
-
removeListener
Description copied from interface:ClassMapperRemoves a class mapped listener.- Specified by:
removeListenerin interfaceClassMapper- Parameters:
listener- the listener- Returns:
- true if removed, false if no such listener
-
removeAllListeners
public void removeAllListeners()Description copied from interface:ClassMapperRemoves all class mapped listeners.- Specified by:
removeAllListenersin interfaceClassMapper
-