Package adams.core

Class ClassLister

  • All Implemented Interfaces:
    Serializable

    public class ClassLister
    extends nz.ac.waikato.cms.locator.ClassLister
    Determines the classnames of superclasses that are to be displayed in the GUI for instance.

    IMPORTANT NOTE: Due to reentrant threads, the getSingleton() method is not allowed to be called from static {...} blocks in classes that are managed by the ClassLister class (and therefore the ClassLocator class). Since the ClassLocator class loads classes into the JVM, the static {...} block of these classes gets executed and the ClassLister gets initialized once again. In this case, the previous singleton will most likely get overwritten.

    Calling the main method of this class allows listing of classes for all or a specific superclass. Examples:
     - List all:
       adams.core.ClassLister -allow-empty
     - List all actors:
       adams.core.ClassLister -super adams.flow.core.Actor
     - List only transformers:
       adams.core.ClassLister -super adams.flow.core.Actor -match ".*\.transformer\..*"
     - List only actors from the adams-compress module:
       adams.core.ClassLister -super adams.flow.core.Actor -filter-by-module adams-compress"
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    main(String[]), Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String BLACKLIST
      the name of the props file.
      static String CLASSLISTER_CLASSES
      for statically listed classes (superclass -> comma-separated classnames).
      static String CLASSLISTER_PACKAGES
      for statically listed packages (superclass -> comma-separated packages).
      static String CLASSPATH_BLACKLIST
      the name of the classpath blacklist props file.
      static String FILENAME
      the name of the props file.
      protected static ClassLister m_Singleton
      the singleton.
      protected boolean m_Static
      whether static or dynamic discovery is used.
      • Fields inherited from class nz.ac.waikato.cms.locator.ClassLister

        m_AllCached, m_Blacklist, m_CacheClasses, m_CacheNames, m_ClassTraversal, m_ListClasses, m_ListNames, m_Logger, m_ManagedClasses, m_ManagedClassnames, m_OnlyDefaultConstructor, m_OnlySerializable, m_Packages
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ClassLister()
      Initializes the classlister.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Class[] filterByModule​(Class[] classes, String module)
      Filters the classes using the ADAMS module name, returning only ones that are from this module.
      List<String> getAllClassnames​(boolean managed)
      For returning a list of all classes.
      List<String> getAllClassnames​(boolean managed, Class[] filters)
      For returning a list of all classes.
      Class[] getClasses​(Class superclass, Class restriction)
      Returns all the classes of the specified superclass (abstract class or interface), but restricts it further to the specified class.
      Class[] getClasses​(Class superclass, Class[] restriction)
      Returns all the classes of the specified superclass (abstract class or interface), but restricts it further to the specified classes.
      static ClassLister getSingleton()
      Returns the singleton instance of the class lister.
      boolean isStatic()
      Returns whether static or dynamic discivery is being used.
      static void main​(String[] args)
      Outputs a list of available conversions.
      protected boolean matches​(Class cls, Class[] filters)
      Matches the class against the filters (interfaces, superclasses).
      protected boolean matches​(String cls, Class[] filters)
      Matches the class against the filters (interfaces, superclasses).
      • Methods inherited from class nz.ac.waikato.cms.locator.ClassLister

        addHierarchy, addHierarchy, extractPackage, getClasses, getClasses, getClassLocator, getClassnames, getClassTraversal, getLogger, getManagedClasses, getManagedClassnames, getPackages, getPackages, getPackages, getSingleton, getSuperclasses, getSuperclasses, getSuperclasses, initialize, isLoggingEnabled, isManaged, isManaged, isOnlyDefaultConstructor, isOnlySerializable, load, load, setBlacklist, setOnlyDefaultConstructor, setOnlySerializable, setPackages, toPackages, toProperties, toString, updateCaches, updateCaches, updateClasses, updateClasses, updateClassnames, updateClassnames
    • Field Detail

      • CLASSPATH_BLACKLIST

        public static final String CLASSPATH_BLACKLIST
        the name of the classpath blacklist props file.
        See Also:
        Constant Field Values
      • CLASSLISTER_CLASSES

        public static final String CLASSLISTER_CLASSES
        for statically listed classes (superclass -> comma-separated classnames).
        See Also:
        Constant Field Values
      • CLASSLISTER_PACKAGES

        public static final String CLASSLISTER_PACKAGES
        for statically listed packages (superclass -> comma-separated packages).
        See Also:
        Constant Field Values
      • m_Singleton

        protected static ClassLister m_Singleton
        the singleton.
      • m_Static

        protected boolean m_Static
        whether static or dynamic discovery is used.
    • Constructor Detail

      • ClassLister

        protected ClassLister()
        Initializes the classlister.
    • Method Detail

      • isStatic

        public boolean isStatic()
        Returns whether static or dynamic discivery is being used.
        Returns:
        true if static
      • getClasses

        public Class[] getClasses​(Class superclass,
                                  Class restriction)
        Returns all the classes of the specified superclass (abstract class or interface), but restricts it further to the specified class.
        Parameters:
        superclass - abstract class or interface to get classes for
        restriction - the interface that the classes must implement
        Returns:
        the class subset
      • getClasses

        public Class[] getClasses​(Class superclass,
                                  Class[] restriction)
        Returns all the classes of the specified superclass (abstract class or interface), but restricts it further to the specified classes.
        Parameters:
        superclass - abstract class or interface to get classes for
        restriction - the interfaces that the classes must implement
        Returns:
        the class subset
      • getAllClassnames

        public List<String> getAllClassnames​(boolean managed)
        For returning a list of all classes.
        Parameters:
        managed - whether to restrict to managed classes
        Returns:
        the list of class names
      • matches

        protected boolean matches​(String cls,
                                  Class[] filters)
        Matches the class against the filters (interfaces, superclasses).
        Parameters:
        cls - the class to match
        filters - the interfaces/superclasses to match, null if no filtering
        Returns:
        true if a match
      • matches

        protected boolean matches​(Class cls,
                                  Class[] filters)
        Matches the class against the filters (interfaces, superclasses).
        Parameters:
        cls - the class to match
        filters - the interfaces/superclasses to match, null if no filtering
        Returns:
        true if a match
      • getAllClassnames

        public List<String> getAllClassnames​(boolean managed,
                                             Class[] filters)
        For returning a list of all classes.
        Parameters:
        managed - whether to restrict to managed classes
        filters - for filtering the classes (interfaces/superclasses to match again), null to ignore
        Returns:
        the list of class names
      • filterByModule

        public Class[] filterByModule​(Class[] classes,
                                      String module)
        Filters the classes using the ADAMS module name, returning only ones that are from this module.
        Parameters:
        classes - the classes to filter
        module - the name of the ADAMS module
        Returns:
        the filtered classes
      • getSingleton

        public static ClassLister getSingleton()
        Returns the singleton instance of the class lister.
        Returns:
        the singleton
      • main

        public static void main​(String[] args)
                         throws Exception
        Outputs a list of available conversions.
        Parameters:
        args - the commandline options: [-env classname] [-super classname] [-match regexp]
        Throws:
        Exception - if invalid environment class or invalid regular expression