Class JavaResolver
java.lang.Object
ortus.boxlang.runtime.loader.resolvers.BaseResolver
ortus.boxlang.runtime.loader.resolvers.JavaResolver
- All Implemented Interfaces:
IClassResolver
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 Summary
FieldsFields inherited from class ortus.boxlang.runtime.loader.resolvers.BaseResolver
classLocator, importCache, name, prefix, runtime -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClear the JDK import cachefindFromAllModules(String fullyQualifiedName, List<ImportDefinition> imports, IBoxContext context) Find a class from all the registered runtime modules by asking them individuallyfindFromModule(String fullyQualifiedName, Key moduleName, List<ImportDefinition> imports, IBoxContext context) Find a class from a specific module explicitly.findFromModules(String fullyQualifiedName, List<ImportDefinition> imports, IBoxContext context) Load a class from the registered runtime module class loadersfindFromSystem(String fullyQualifiedName, List<ImportDefinition> imports, IBoxContext context) Load a class from the system using our lookup mechanismGet the JDK import cacheGet the size of the JDK import cacheprotected booleanimportHas(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.*) definitionprotected booleanimportHasMulti(IBoxContext context, ImportDefinition thisImport, String className) Checks if the import has the given class name as a multi-import.resolve(IBoxContext context, String name) Each resolver has a way to resolve the class it represents.resolve(IBoxContext context, String name, List<ImportDefinition> imports) Each resolver has a way to resolve the class it represents.resolve(IBoxContext context, String name, List<ImportDefinition> imports, IStruct properties) Each resolver has a way to resolve the class it represents.Methods inherited from class ortus.boxlang.runtime.loader.resolvers.BaseResolver
clearImportCache, expandFromImport, getClassLocator, getConfiguration, getImportCache, getImportCacheSize, getLogger, getName, getPrefix, getRuntime, getSystemClassLoader, importApplies
-
Field Details
-
instance
Singleton instance
-
-
Constructor Details
-
JavaResolver
Constructor- Parameters:
classLocator- The class locator to use
-
-
Method Details
-
resolve
Each resolver has a way to resolve the class it represents. This method will be called by theClassLocatorclass to resolve the class if the prefix matches.- Specified by:
resolvein interfaceIClassResolver- Overrides:
resolvein classBaseResolver- Parameters:
context- The current context of executionname- 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 theClassLocatorclass to resolve the class if the prefix matches with imports.- Specified by:
resolvein interfaceIClassResolver- Overrides:
resolvein classBaseResolver- Parameters:
context- The current context of executionname- The fully qualified name OR imported alias of the class to resolveimports- The list of imports to useproperties- 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 theClassLocatorclass to resolve the class if the prefix matches with imports.- Parameters:
context- The current context of executionname- The fully qualified name OR imported alias of the class to resolveimports- 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 loadimports- The list of imports to usecontext- 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 loadimports- The list of imports to usecontext- 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 loadmoduleName- The name of the module to look inimports- The list of imports to usecontext- 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 loadimports- The list of imports to usecontext- The current context of execution- Returns:
- The
ClassLocationrecord wrapped in an optional if found, empty otherwise
-
importHas
Checks if the import has the given class name as : - an alias - as a class - as a multi-import (java.util.*) definition- Overrides:
importHasin classBaseResolver- Parameters:
context- The current context of executionthisImport- The import to checkclassName- 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:
importHasMultiin classBaseResolver- Parameters:
context- The current context of executionthisImport- The import to checkclassName- 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
Get the JDK import cache- Returns:
- The JDK import cache
-
getJdkImportCacheSize
Get the size of the JDK import cache- Returns:
- The size of the JDK import cache
-