Class ELKIServiceRegistry


  • public class ELKIServiceRegistry
    extends java.lang.Object
    Registry of available implementations in ELKI.
    Since:
    0.7.0
    Author:
    Erich Schubert
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  ELKIServiceRegistry.Entry
      Entry in the service registry.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.ClassLoader CLASSLOADER
      Class loader
      private static java.util.Map<java.lang.Class<?>,​ELKIServiceRegistry.Entry> data
      Registry data.
      static java.lang.String FACTORY_POSTFIX
      Factory class postfix.
      private static java.lang.Class<?> FAILED_LOAD
      Value to abuse for failures.
      private static Logging LOG
      Class logger.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ELKIServiceRegistry()
      Do not use constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static boolean contains​(java.lang.Class<?> c)
      Test if a registry entry has already been created.
      static java.util.List<java.lang.Class<?>> findAllImplementations​(java.lang.Class<?> restrictionClass)
      Find all implementations of a particular interface.
      static java.util.List<java.lang.Class<?>> findAllImplementations​(java.lang.Class<?> restrictionClass, boolean everything)
      Find all implementations of a given class in the classpath.
      static <C> java.lang.Class<? extends C> findImplementation​(java.lang.Class<? super C> restrictionClass, java.lang.String value)
      Find an implementation of the given interface / super class, given a relative class name or alias name.
      protected static void register​(java.lang.Class<?> parent, java.lang.Class<?> clazz)
      Register a class in the registry.
      protected static void register​(java.lang.Class<?> parent, java.lang.String cname)
      Register a class with the registry.
      protected static void registerAlias​(java.lang.Class<?> parent, java.lang.String alias, java.lang.String cname)
      Register a class alias with the registry.
      private static <C> java.lang.Class<?> tryAlternateNames​(java.lang.Class<? super C> restrictionClass, java.lang.String value, ELKIServiceRegistry.Entry e)
      Try loading alternative names.
      private static java.lang.Class<?> tryLoadClass​(java.lang.String value)
      Attempt to load a class
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final Logging LOG
        Class logger.
      • CLASSLOADER

        private static final java.lang.ClassLoader CLASSLOADER
        Class loader
      • FACTORY_POSTFIX

        public static final java.lang.String FACTORY_POSTFIX
        Factory class postfix.
        See Also:
        Constant Field Values
      • FAILED_LOAD

        private static final java.lang.Class<?> FAILED_LOAD
        Value to abuse for failures.
    • Constructor Detail

      • ELKIServiceRegistry

        private ELKIServiceRegistry()
        Do not use constructor.
    • Method Detail

      • register

        protected static void register​(java.lang.Class<?> parent,
                                       java.lang.String cname)
        Register a class with the registry.
        Parameters:
        parent - Parent class
        cname - Class name
      • register

        protected static void register​(java.lang.Class<?> parent,
                                       java.lang.Class<?> clazz)
        Register a class in the registry.

        Careful: do not use this from your code before first making sure this has been fully initialized. Otherwise, other implementations will not be found. Therefore, avoid calling this from your own Java code!

        Parameters:
        parent - Class
        clazz - Implementation
      • registerAlias

        protected static void registerAlias​(java.lang.Class<?> parent,
                                            java.lang.String alias,
                                            java.lang.String cname)
        Register a class alias with the registry.
        Parameters:
        parent - Parent class
        alias - Alias name
        cname - Class name
      • tryLoadClass

        private static java.lang.Class<?> tryLoadClass​(java.lang.String value)
        Attempt to load a class
        Parameters:
        value - Class name to try.
        Returns:
        Class, or null.
      • contains

        protected static boolean contains​(java.lang.Class<?> c)
        Test if a registry entry has already been created.
        Parameters:
        c - Class
        Returns:
        true if a registry entry has been created.
      • findAllImplementations

        public static java.util.List<java.lang.Class<?>> findAllImplementations​(java.lang.Class<?> restrictionClass)
        Find all implementations of a particular interface.
        Parameters:
        restrictionClass - Class to scan for
        Returns:
        Found implementations
      • findAllImplementations

        public static java.util.List<java.lang.Class<?>> findAllImplementations​(java.lang.Class<?> restrictionClass,
                                                                                boolean everything)
        Find all implementations of a given class in the classpath.

        Note: returned classes may be abstract.

        Parameters:
        restrictionClass - Class restriction
        everything - include interfaces, abstract and private classes
        Returns:
        List of found classes.
      • findImplementation

        public static <C> java.lang.Class<? extends C> findImplementation​(java.lang.Class<? super C> restrictionClass,
                                                                          java.lang.String value)
        Find an implementation of the given interface / super class, given a relative class name or alias name.
        Parameters:
        restrictionClass - Restriction class
        value - Class name, relative class name, or nickname.
        Returns:
        Class found or null
      • tryAlternateNames

        private static <C> java.lang.Class<?> tryAlternateNames​(java.lang.Class<? super C> restrictionClass,
                                                                java.lang.String value,
                                                                ELKIServiceRegistry.Entry e)
        Try loading alternative names.
        Type Parameters:
        C - Generic type
        Parameters:
        restrictionClass - Context class, for prepending a package name.
        value - Class name requested
        e - Cache entry, may be null
        Returns:
        Class, or null