Class JavaResolver

java.lang.Object
ortus.boxlang.runtime.loader.resolvers.BaseResolver
ortus.boxlang.runtime.loader.resolvers.JavaResolver
All Implemented Interfaces:
IClassResolver

public class JavaResolver extends BaseResolver
This resolver deals with Java classes only. It has two import caches as well to deal with JDK classes and non-JDK classes.

In order to access it you must go via the @{link ClassLocator} class, as the ClassLocator controls all the resolvers in the runtime.

Example:

 ClassLocator.getJavaResolver();
 or
 ClassLocator.getResolver( ClassLocator.JAVA_PREFIX );
 
  • Field Details

    • instance

      protected static JavaResolver instance
      Singleton instance
  • Constructor Details

    • JavaResolver

      public JavaResolver(ClassLocator classLocator)
      Constructor
      Parameters:
      classLocator - The class locator to use
  • Method Details

    • resolve

      public Optional<ClassLocation> resolve(IBoxContext context, String name)
      Each resolver has a way to resolve the class it represents. This method will be called by the ClassLocator class to resolve the class if the prefix matches.
      Specified by:
      resolve in interface IClassResolver
      Overrides:
      resolve in class BaseResolver
      Parameters:
      context - The current context of execution
      name - The name of the class to resolve
      Returns:
      An optional class object representing the class if found
    • resolve

      public Optional<ClassLocation> resolve(IBoxContext context, String name, List<ImportDefinition> imports, IStruct properties)
      Each resolver has a way to resolve the class it represents. This method will be called by the ClassLocator class to resolve the class if the prefix matches with imports.
      Specified by:
      resolve in interface IClassResolver
      Overrides:
      resolve in class BaseResolver
      Parameters:
      context - The current context of execution
      name - The fully qualified name OR imported alias of the class to resolve
      imports - The list of imports to use
      properties - The properties to use
      Returns:
      An optional class object representing the class if found
    • resolve

      public Optional<ClassLocation> resolve(IBoxContext context, String name, List<ImportDefinition> imports)
      Each resolver has a way to resolve the class it represents. This method will be called by the ClassLocator class to resolve the class if the prefix matches with imports.
      Parameters:
      context - The current context of execution
      name - The fully qualified name OR imported alias of the class to resolve
      imports - The list of imports to use
      Returns:
      An optional class object representing the class if found
    • findFromModules

      public Optional<ClassLocation> findFromModules(String fullyQualifiedName, List<ImportDefinition> imports, IBoxContext context)
      Load a class from the registered runtime module class loaders
      Parameters:
      fullyQualifiedName - The fully qualified path of the class to load
      imports - The list of imports to use
      context - The current context of execution
      Returns:
      The loaded class or null if not found
    • findFromAllModules

      public Optional<ClassLocation> findFromAllModules(String fullyQualifiedName, List<ImportDefinition> imports, IBoxContext context)
      Find a class from all the registered runtime modules by asking them individually
      Parameters:
      fullyQualifiedName - The fully qualified path of the class to load
      imports - The list of imports to use
      context - The current context of execution
      Returns:
      The ClassLocation record wrapped in an optional if found, empty otherwise
    • findFromModule

      public Optional<ClassLocation> findFromModule(String fullyQualifiedName, Key moduleName, List<ImportDefinition> imports, IBoxContext context)
      Find a class from a specific module explicitly.
      Parameters:
      fullyQualifiedName - The fully qualified path of the class to load
      moduleName - The name of the module to look in
      imports - The list of imports to use
      context - The current context of execution
      Returns:
      The ClassLocation record wrapped in an optional if found, empty otherwise
      Throws:
      BoxRuntimeException - If the module is not found
    • findFromSystem

      public Optional<ClassLocation> findFromSystem(String fullyQualifiedName, List<ImportDefinition> imports, IBoxContext context)
      Load a class from the system using our lookup mechanism
      Parameters:
      fullyQualifiedName - The fully qualified path of the class to load
      imports - The list of imports to use
      context - The current context of execution
      Returns:
      The ClassLocation record wrapped in an optional if found, empty otherwise
    • importHas

      protected boolean importHas(IBoxContext context, ImportDefinition thisImport, String className)
      Checks if the import has the given class name as : - an alias - as a class - as a multi-import (java.util.*) definition
      Overrides:
      importHas in class BaseResolver
      Parameters:
      context - The current context of execution
      thisImport - The import to check
      className - The class name to check
      Returns:
      True if the import has the class name, false otherwise
    • importHasMulti

      protected boolean importHasMulti(IBoxContext context, ImportDefinition thisImport, String className)
      Checks if the import has the given class name as a multi-import. However, we can't interrogate the JDK due to limitations in the JDK itself. So we do a simple check to see if the class name can be loaded from the system class loader. This is not a perfect check, but it will do for now. If the class is not a JDK class, we delegate to the super class.
      Overrides:
      importHasMulti in class BaseResolver
      Parameters:
      context - The current context of execution
      thisImport - The import to check
      className - The class name to check
      Returns:
      True if the import has the class name, false otherwise
    • clearJdkImportCache

      public void clearJdkImportCache()
      Clear the JDK import cache
    • getJdkImportCache

      public Set<String> getJdkImportCache()
      Get the JDK import cache
      Returns:
      The JDK import cache
    • getJdkImportCacheSize

      public Integer getJdkImportCacheSize()
      Get the size of the JDK import cache
      Returns:
      The size of the JDK import cache