Interface ClassMapper

All Known Implementing Classes:
DefaultClassMapper

public interface ClassMapper
Maps names or classes to classes.
Author:
harald
  • Method Details

    • create

      static ClassMapper create(String name, Class<?> mappedClass)
      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 name
      mappedClass - class of the mapped service
      Returns:
      the classmapper
      See Also:
    • map

      Class<?> map(Class<?> clazz) throws ClassNotFoundException
      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

      Class<?> map(String name) throws ClassNotFoundException
      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

      Class<?> mapLenient(Class<?> clazz) throws ClassNotFoundException
      Maps a class or interface to another class or interface.
      If there is no mapping for clazz, its superclasses are tried. If none of them is mapped, the interfaces of clazz and 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

      Class<?> mapLenient(String name) throws ClassNotFoundException
      Maps a name to a class.
      Same as mapLenient(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

      void setDefaultClass(Class<?> defaultClass)
      Sets the default class.
      If there is no matching class, the mapper returns this class.
      Parameters:
      defaultClass - the default class
    • getMap

      Map<String,String> getMap()
      Gets a copy of the names map.
      Returns:
      the unmodifiable map of names to mapped names
    • addListener

      void addListener(ClassMappedListener listener)
      Adds a class mapped listener.
      Parameters:
      listener - invoked whenever a class is mapped the first time
    • removeListener

      boolean removeListener(ClassMappedListener listener)
      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.