Class PackageObjectFactory

  • All Implemented Interfaces:
    ModuleFactory

    public class PackageObjectFactory
    extends java.lang.Object
    implements ModuleFactory
    A factory for creating objects from package names and names. Consider the below example for better understanding.
    • module name - name of java class that represents module;
    • module full name - fully qualifies name of java class that represents module;
    • check module short name - name of Check without 'Check' suffix;
    • check module name - name of java class that represents Check (with 'Check' suffix);
    • check module full name - fully qualifies name of java class that represents Check (with 'Check' suffix).
    • Constructor Summary

      Constructors 
      Constructor Description
      PackageObjectFactory​(java.lang.String packageName, java.lang.ClassLoader moduleClassLoader)
      Creates a new PackageObjectFactory instance.
      PackageObjectFactory​(java.util.Set<java.lang.String> packageNames, java.lang.ClassLoader moduleClassLoader)
      Creates a new PackageObjectFactory instance.
      PackageObjectFactory​(java.util.Set<java.lang.String> packageNames, java.lang.ClassLoader moduleClassLoader, PackageObjectFactory.ModuleLoadOption moduleLoadOption)
      Creates a new PackageObjectFactory instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object createModule​(java.lang.String name)
      Creates a new instance of a class from a given name, or that name concatenated with "Check".
      static java.lang.String getShortFromFullModuleNames​(java.lang.String fullName)
      Returns simple check name from full modules names map.
      • Methods inherited from class java.lang.Object

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

      • BASE_PACKAGE

        public static final java.lang.String BASE_PACKAGE
        Base package of checkstyle modules checks.
        See Also:
        Constant Field Values
      • UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE

        public static final java.lang.String UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE
        Exception message when it is unable to create a class instance.
        See Also:
        Constant Field Values
      • AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE

        public static final java.lang.String AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE
        Exception message when there is ambiguous module name in config file.
        See Also:
        Constant Field Values
      • CHECK_SUFFIX

        public static final java.lang.String CHECK_SUFFIX
        Suffix of checks.
        See Also:
        Constant Field Values
      • PACKAGE_SEPARATOR

        public static final java.lang.String PACKAGE_SEPARATOR
        Character separate package names in qualified name of java class.
        See Also:
        Constant Field Values
      • NULL_LOADER_MESSAGE

        public static final java.lang.String NULL_LOADER_MESSAGE
        Exception message when null class loader is given.
        See Also:
        Constant Field Values
      • NULL_PACKAGE_MESSAGE

        public static final java.lang.String NULL_PACKAGE_MESSAGE
        Exception message when null package name is given.
        See Also:
        Constant Field Values
      • STRING_SEPARATOR

        public static final java.lang.String STRING_SEPARATOR
        Separator to use in strings.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PackageObjectFactory

        public PackageObjectFactory​(java.util.Set<java.lang.String> packageNames,
                                    java.lang.ClassLoader moduleClassLoader)
        Creates a new PackageObjectFactory instance.
        Parameters:
        packageNames - the list of package names to use
        moduleClassLoader - class loader used to load Checkstyle core and custom modules
      • PackageObjectFactory

        public PackageObjectFactory​(java.util.Set<java.lang.String> packageNames,
                                    java.lang.ClassLoader moduleClassLoader,
                                    PackageObjectFactory.ModuleLoadOption moduleLoadOption)
        Creates a new PackageObjectFactory instance.
        Parameters:
        packageNames - the list of package names to use
        moduleClassLoader - class loader used to load Checkstyle core and custom modules
        moduleLoadOption - loading option
        Throws:
        java.lang.IllegalArgumentException - if moduleClassLoader is null or packageNames contains null
      • PackageObjectFactory

        public PackageObjectFactory​(java.lang.String packageName,
                                    java.lang.ClassLoader moduleClassLoader)
        Creates a new PackageObjectFactory instance.
        Parameters:
        packageName - The package name to use
        moduleClassLoader - class loader used to load Checkstyle core and custom modules
        Throws:
        java.lang.IllegalArgumentException - if moduleClassLoader is null or packageNames is null
    • Method Detail

      • createModule

        public java.lang.Object createModule​(java.lang.String name)
                                      throws CheckstyleException
        Creates a new instance of a class from a given name, or that name concatenated with "Check". If the name is a class name, creates an instance of the named class. Otherwise, creates an instance of a class name obtained by concatenating the given name to a package name from a given list of package names.
        Specified by:
        createModule in interface ModuleFactory
        Parameters:
        name - the name of a class.
        Returns:
        the Object created by loader.
        Throws:
        CheckstyleException - if an error occurs.
      • getShortFromFullModuleNames

        public static java.lang.String getShortFromFullModuleNames​(java.lang.String fullName)
        Returns simple check name from full modules names map.
        Parameters:
        fullName - name of the class for joining.
        Returns:
        simple check name.