Class BoxResolver

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

public class BoxResolver extends BaseResolver
This resolver is in charge of resolving and returning BoxLang classes. It will follow the rules of checking runtime mappings and the current template directory for the class requesting resolution.

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 );
 
  • Constructor Details

    • BoxResolver

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

    • getValidExtensions

      public Set<String> getValidExtensions()
      Get all the valid extensions we can process. This list does NOT include the dot.
    • resolve

      public Optional<ClassLocation> resolve(IBoxContext context, String name, boolean loadClass)
      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.
      Parameters:
      context - The current context of execution
      name - The name of the class to resolve
      loadClass - When false, the class location is returned with informatino about where the class was found, but the class is not loaded and will be null.
      Returns:
      An optional class object representing the class if found
    • 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 name 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 name of the class to resolve
      imports - The list of imports to use
      Returns:
      An optional class object representing the class if found
    • resolve

      public Optional<ClassLocation> resolve(IBoxContext context, String name, List<ImportDefinition> imports, boolean loadClass, 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.
      Parameters:
      context - The current context of execution
      name - The name of the class to resolve
      imports - The list of imports to use
      loadClass - When false, the class location is returned with informatino about where the class was found, but the class is not loaded and will be null.
      Returns:
      An optional class object representing the class if found
    • findFromModules

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

      public Optional<ClassLocation> findFromModules(IBoxContext context, String fullyQualifiedName, List<ImportDefinition> imports, boolean loadClass)
      This tries to load a BoxLang class from registered modules using the fullyQualifiedName@moduleName provided. If the class is not found, it will return an empty Optional.

      If there is no module name, then we return an empty Optional, because it will delegate to the findFromLocal(ortus.boxlang.runtime.context.IBoxContext, java.lang.String, java.util.List<ortus.boxlang.runtime.loader.ImportDefinition>) method, which will look for the class in the current template directory, or using module mappings.

      Parameters:
      context - The current context of execution
      fullyQualifiedName - The fully qualified path of the class to load
      imports - The list of imports to use
      loadClass - When false, the class location is returned with informatino about where the class was found, but the class is not loaded and will be null.
      Returns:
      The loaded class or null if not found
    • 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 in the module root
      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
    • findFromLocal

      public Optional<ClassLocation> findFromLocal(IBoxContext context, String fullyQualifiedName, List<ImportDefinition> imports)
      Load a class from the configured directory byte code
      Parameters:
      context - The current context of execution
      fullyQualifiedName - The fully qualified path of the class to load
      imports - The list of imports to use
      Returns:
      The loaded class or null if not found
    • findFromLocal

      public Optional<ClassLocation> findFromLocal(IBoxContext context, String fullyQualifiedName, List<ImportDefinition> imports, boolean loadClass, IStruct properties)
      Load a class from the configured directory byte code
      Parameters:
      context - The current context of execution
      fullyQualifiedName - The fully qualified path of the class to load
      imports - The list of imports to use
      loadClass - When false, the class location is returned with informatino about where the class was found, but the class is not loaded and will be null.
      Returns:
      The loaded class or null if not found
    • importHasMulti

      public boolean importHasMulti(IBoxContext context, ImportDefinition thisImport, String className)
      Checks if the import has the given class name as a multi-import
      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