Package ortus.boxlang.runtime.services
Class FunctionService
java.lang.Object
ortus.boxlang.runtime.services.BaseService
ortus.boxlang.runtime.services.FunctionService
- All Implemented Interfaces:
IService
The
FunctionService is in charge of managing the runtime's built-in functions.
It will also be used by the module services to register functions.-
Field Summary
Fields inherited from class ortus.boxlang.runtime.services.BaseService
name, runtime, timerUtil -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetGlobalFunction(String name) Returns the global function with the given namegetGlobalFunction(Key name) Returns the global function with the given namelongReturns the number of global functions registered with the serviceString[]Returns the names of the global functions registered with the servicegetMemberMethod(IBoxContext context, Key name, Object object) Returns the member method with the given name and type by verifying if the passed object can be cast to that typegetMemberMethod(Key name, BoxLangType type) Returns the member method with the given name and BoxLangTypelongThe count of registered namespaceshasGlobalFunction(String name) Returns whether or not the service has a global function with the given namehasGlobalFunction(Key name) Returns whether or not the service has a global function with the given namevoidThis method loads all of the global functions into the service by scanning theortus.boxlang.runtime.bifs.globalpackage.voidonShutdown(Boolean force) The shutdown event is fired when the runtime shuts downvoidThe startup event is fired when the runtime starts upvoidprocessBIFRegistration(Class<?> BIFClass, BIF function, String module) This method process a raw BIF registration usually from aBIFClassand afunctioninstance.voidregisterGlobalFunction(BIFDescriptor descriptor) Registers a global function with the service only using a descriptor.voidregisterGlobalFunction(BIFDescriptor descriptor, Key name, Boolean force) Registers a global function with the service using a descriptor, a name, and if we want to override if it exists, else it will throw an exceptionvoidregisterMemberMethod(Key memberKey, MemberDescriptor descriptor) Register a member method with the service using a member key and aMemberDescriptorvoidunregisterGlobalFunction(Key name) Unregisters a global function with the serviceMethods inherited from class ortus.boxlang.runtime.services.BaseService
announce, announce, announce, announce, getName, getRuntime, getTimerUtil
-
Constructor Details
-
FunctionService
Constructor- Parameters:
runtime- The runtime instance
-
-
Method Details
-
onStartup
public void onStartup()The startup event is fired when the runtime starts up- Specified by:
onStartupin interfaceIService- Specified by:
onStartupin classBaseService
-
onShutdown
The shutdown event is fired when the runtime shuts down- Specified by:
onShutdownin interfaceIService- Specified by:
onShutdownin classBaseService- Parameters:
force- Whether the shutdown is forced
-
getGlobalFunctionCount
public long getGlobalFunctionCount()Returns the number of global functions registered with the service- Returns:
- The number of global functions registered with the service
-
getGlobalFunctionNames
Returns the names of the global functions registered with the service- Returns:
- A set of global function names
-
hasGlobalFunction
Returns whether or not the service has a global function with the given name- Parameters:
name- The name of the global function- Returns:
- Whether or not the service has a global function with the given name
-
hasGlobalFunction
Returns whether or not the service has a global function with the given name- Parameters:
name- The key name of the global function- Returns:
- Whether or not the service has a global function with the given name
-
getGlobalFunction
Returns the global function with the given name- Parameters:
name- The name of the global function- Returns:
- The global function with the given name or null if none exists
-
getGlobalFunction
Returns the global function with the given name- Parameters:
name- The name of the global function- Returns:
- The global function with the given name or null if none exists
-
getMemberMethod
Returns the member method with the given name and type by verifying if the passed object can be cast to that type- Parameters:
name- The name of the member methodobject- An object to cast to the type of the member method- Returns:
- The member method with the given name and type or null if none exists
-
getMemberMethod
Returns the member method with the given name and BoxLangType- Parameters:
name- The name of the member methodtype- The BoxLangType of the member method requested- Returns:
- The member method with the given name and BoxLangType or null if none exists
-
registerGlobalFunction
Registers a global function with the service using a descriptor, a name, and if we want to override if it exists, else it will throw an exception- Parameters:
descriptor- The descriptor for the global functionname- The name of the global functionforce- Whether or not to force the registration, usually it means an overwrite- Throws:
BoxRuntimeException- If the global function already exists
-
registerGlobalFunction
Registers a global function with the service only using a descriptor. We take the name from the descriptor itselfdescriptor.nameand we do not force the registration.- Parameters:
descriptor- The descriptor for the global function- Throws:
BoxRuntimeException- If the global function already exists
-
unregisterGlobalFunction
Unregisters a global function with the service- Parameters:
name- The name of the global function
-
registerMemberMethod
Register a member method with the service using a member key and aMemberDescriptor- Parameters:
memberKey- The key for the member method: Ex: "append", "insert", "remove"descriptor- The descriptor for the member method:MemberDescriptor
-
loadGlobalFunctions
This method loads all of the global functions into the service by scanning theortus.boxlang.runtime.bifs.globalpackage.- Throws:
IOException- If there is an error loading the global functions
-
processBIFRegistration
This method process a raw BIF registration usually from aBIFClassand afunctioninstance. This creates an internalBIFDescriptorand registers it with the service. This is main way to register Java based BIFs with the runtime.- Parameters:
BIFClass- The BIF class to process for registrationfunction- The global function to process for registrationmodule- The module the global function belongs to when registering- Throws:
BoxRuntimeException- If no BIF class or function was provided
-
getNamespaceCount
public long getNamespaceCount()The count of registered namespaces- Returns:
- The count of registered namespaces
-