Class FunctionService

java.lang.Object
ortus.boxlang.runtime.services.BaseService
ortus.boxlang.runtime.services.FunctionService
All Implemented Interfaces:
IService

public class FunctionService extends BaseService
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.
  • Constructor Details

    • FunctionService

      public FunctionService(BoxRuntime runtime)
      Constructor
      Parameters:
      runtime - The runtime instance
  • Method Details

    • onStartup

      public void onStartup()
      The startup event is fired when the runtime starts up
      Specified by:
      onStartup in interface IService
      Specified by:
      onStartup in class BaseService
    • onShutdown

      public void onShutdown(Boolean force)
      The shutdown event is fired when the runtime shuts down
      Specified by:
      onShutdown in interface IService
      Specified by:
      onShutdown in class BaseService
      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

      public String[] getGlobalFunctionNames()
      Returns the names of the global functions registered with the service
      Returns:
      A set of global function names
    • hasGlobalFunction

      public Boolean hasGlobalFunction(String name)
      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

      public Boolean hasGlobalFunction(Key name)
      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

      public BIFDescriptor getGlobalFunction(String name)
      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

      public BIFDescriptor getGlobalFunction(Key name)
      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

      public MemberDescriptor getMemberMethod(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 type
      Parameters:
      name - The name of the member method
      object - 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

      public MemberDescriptor getMemberMethod(Key name, BoxLangType type)
      Returns the member method with the given name and BoxLangType
      Parameters:
      name - The name of the member method
      type - The BoxLangType of the member method requested
      Returns:
      The member method with the given name and BoxLangType or null if none exists
    • registerGlobalFunction

      public void registerGlobalFunction(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 exception
      Parameters:
      descriptor - The descriptor for the global function
      name - The name of the global function
      force - Whether or not to force the registration, usually it means an overwrite
      Throws:
      BoxRuntimeException - If the global function already exists
    • registerGlobalFunction

      public void registerGlobalFunction(BIFDescriptor descriptor)
      Registers a global function with the service only using a descriptor. We take the name from the descriptor itself descriptor.name and we do not force the registration.
      Parameters:
      descriptor - The descriptor for the global function
      Throws:
      BoxRuntimeException - If the global function already exists
    • unregisterGlobalFunction

      public void unregisterGlobalFunction(Key name)
      Unregisters a global function with the service
      Parameters:
      name - The name of the global function
    • registerMemberMethod

      public void registerMemberMethod(Key memberKey, MemberDescriptor descriptor)
      Register a member method with the service using a member key and a MemberDescriptor
      Parameters:
      memberKey - The key for the member method: Ex: "append", "insert", "remove"
      descriptor - The descriptor for the member method: MemberDescriptor
    • loadGlobalFunctions

      public void loadGlobalFunctions() throws IOException
      This method loads all of the global functions into the service by scanning the ortus.boxlang.runtime.bifs.global package.
      Throws:
      IOException - If there is an error loading the global functions
    • processBIFRegistration

      public void processBIFRegistration(Class<?> BIFClass, BIF function, String module)
      This method process a raw BIF registration usually from a BIFClass and a function instance. This creates an internal BIFDescriptor and 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 registration
      function - The global function to process for registration
      module - 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