Package jodd.util

Class ClassLoaderStrategy.DefaultClassLoaderStrategy

java.lang.Object
jodd.util.ClassLoaderStrategy.DefaultClassLoaderStrategy
All Implemented Interfaces:
ClassLoaderStrategy
Enclosing interface:
ClassLoaderStrategy

public static class ClassLoaderStrategy.DefaultClassLoaderStrategy extends Object implements ClassLoaderStrategy
Default Jodd class loader strategy. Loads a class with a given name dynamically, more reliable then Class.forName.

Class will be loaded using class loaders in the following order:

  • provided class loader (if any)
  • Thread.currentThread().getContextClassLoader()}
  • caller classloader
  • Field Details

    • PRIMITIVE_TYPE_NAMES

      public static final String[] PRIMITIVE_TYPE_NAMES
      List of primitive type names.
    • PRIMITIVE_TYPES

      public static final Class[] PRIMITIVE_TYPES
      List of primitive types that matches names list.
    • PRIMITIVE_BYTECODE_NAME

      public static final char[] PRIMITIVE_BYTECODE_NAME
      List of primitive bytecode characters that matches names list.
    • loadArrayClassByComponentTypes

      protected boolean loadArrayClassByComponentTypes
  • Constructor Details

    • DefaultClassLoaderStrategy

      public DefaultClassLoaderStrategy()
  • Method Details

    • isLoadArrayClassByComponentTypes

      public boolean isLoadArrayClassByComponentTypes()
      Returns arrays class loading strategy.
    • setLoadArrayClassByComponentTypes

      public void setLoadArrayClassByComponentTypes(boolean loadArrayClassByComponentTypes)
      Defines arrays class loading strategy. If false (default), classes will be loaded by Class.forName. If true, classes will be loaded by reflection and component types.
    • prepareArrayClassnameForLoading

      public static String prepareArrayClassnameForLoading(String className)
      Prepares classname for loading, respecting the arrays. Returns null if class name is not an array.
    • getPrimitiveClassNameIndex

      private static int getPrimitiveClassNameIndex(String className)
      Detects if provided class name is a primitive type. Returns >= 0 number if so.
    • loadClass

      public Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException
      Loads class by name.
      Specified by:
      loadClass in interface ClassLoaderStrategy
      Throws:
      ClassNotFoundException
    • loadClass

      protected Class loadClass(String className, String arrayClassName, ClassLoader classLoader)
      Loads a class using provided class loader. If class is an array, it will be first loaded using the Class.forName! We must use this since for JDK >= 6 arrays will be not loaded using classloader, but only with forName method. However, array loading strategy can be changed.
    • loadArrayClassByComponentType

      protected Class loadArrayClassByComponentType(String className, ClassLoader classLoader) throws ClassNotFoundException
      Loads array class using component type.
      Throws:
      ClassNotFoundException