Class DefaultClassMapper

java.lang.Object
org.tentackle.reflect.AbstractClassMapper<String>
org.tentackle.reflect.DefaultClassMapper
All Implemented Interfaces:
ClassMapper

public class DefaultClassMapper extends AbstractClassMapper<String> implements ClassMapper
A default implementation of a class mapper.
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 Details

    • DefaultClassMapper

      public DefaultClassMapper(String name, ClassLoader classLoader, Map<String,String> nameMap, String[] packageNames)
      Constructs a class mapper.
      Parameters:
      name - the mapper's name
      classLoader - the classloader
      nameMap - the mapping of classnames
      packageNames - 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 name
      classLoader - the classloader
      nameProps - the properties holding the mapping.
      packageNames - the package names, null or empty array if none
    • DefaultClassMapper

      public DefaultClassMapper(String name, String mappedServiceName)
      Creates a class mapper for a given mapped service name.
      Parameters:
      name - the mapper's name
      mappedServiceName - the mapped name
    • DefaultClassMapper

      public DefaultClassMapper(String name, Class<?> mappedClass)
      Creates a class mapper for a given mapped service class.
      This is the most common usage of a class mapper.
      Parameters:
      name - the mapper's name
      mappedClass - the mapped service class
  • Method Details

    • getNameMap

      public Map<String,String> getNameMap()
      Description copied from class: AbstractClassMapper
      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.
      Specified by:
      getNameMap in class AbstractClassMapper<String>
      Returns:
      the names-map, never null.
    • getPackageNames

      public String[] getPackageNames()
      Description copied from class: AbstractClassMapper
      Gets the list of package names.
      Specified by:
      getPackageNames in class AbstractClassMapper<String>
      Returns:
      the array of package names, null or empty array if none.
    • getDefaultClass

      public Class<?> getDefaultClass()
      Description copied from interface: ClassMapper
      Gets the default class.
      Specified by:
      getDefaultClass in interface ClassMapper
      Returns:
      the class, null if no default
    • setDefaultClass

      public void setDefaultClass(Class<?> defaultClass)
      Description copied from interface: ClassMapper
      Sets the default class.
      If there is no matching class, the mapper returns this class.
      Specified by:
      setDefaultClass in interface ClassMapper
      Parameters:
      defaultClass - the default class
    • getMap

      public Map<String,String> getMap()
      Description copied from interface: ClassMapper
      Gets a copy of the names map.
      Specified by:
      getMap in interface ClassMapper
      Returns:
      the unmodifiable map of names
    • map

      public Class<?> map(Class<?> clazz) throws ClassNotFoundException
      Description copied from interface: ClassMapper
      Maps a class or interface to another class or interface.
      Specified by:
      map in interface ClassMapper
      Parameters:
      clazz - the class to map
      Returns:
      the mapped class, never null
      Throws:
      ClassNotFoundException - if there is no mapping
    • map

      public Class<?> map(String name) throws ClassNotFoundException
      Description copied from interface: ClassMapper
      Maps a class or interface to another class or interface by its name.
      Specified by:
      map in interface ClassMapper
      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

      public Class<?> mapLenient(Class<?> clazz) throws ClassNotFoundException
      Description copied from interface: ClassMapper
      Maps a class or interface to another class or interface.
      If there is no mapping for clazz its superclasses are tried. If clazz is an interface, all its super interfaces are tried.

      Notice: for classes their interfaces will be ignored.

      Specified by:
      mapLenient in interface ClassMapper
      Parameters:
      clazz - the class to map
      Returns:
      the mapped class, never null
      Throws:
      ClassNotFoundException - if there is no mapping
    • mapLenient

      public Class<?> mapLenient(String name) throws ClassNotFoundException
      Description copied from interface: ClassMapper
      Maps a name to a class.
      Specified by:
      mapLenient in interface ClassMapper
      Parameters:
      name - the name to map
      Returns:
      the mapped class, never null
      Throws:
      ClassNotFoundException - if there is no mapping
    • addListener

      public void addListener(ClassMappedListener listener)
      Description copied from interface: ClassMapper
      Adds a class mapped listener.
      Specified by:
      addListener in interface ClassMapper
      Parameters:
      listener - invoked whenever a class is mapped the first time
    • removeListener

      public boolean removeListener(ClassMappedListener listener)
      Description copied from interface: ClassMapper
      Removes a class mapped listener.
      Specified by:
      removeListener in interface ClassMapper
      Parameters:
      listener - the listener
      Returns:
      true if removed, false if no such listener
    • removeAllListeners

      public void removeAllListeners()
      Description copied from interface: ClassMapper
      Removes all class mapped listeners.
      Specified by:
      removeAllListeners in interface ClassMapper