Class Bindings

java.lang.Object
org.rapidcontext.core.proc.Bindings

public class Bindings extends Object
A procedure bindings container. The procedure bindings contain virtually all data, information and parameters required by a procedure, and are used during serialization, unserialization, introspection and execution. Each binding has a name, a type and a value. The value object class depends on the binding type, but is frequently a string. The bindings can be linked together into a hierarchy, which is used when redefining binding values (such as when binding call argument values). The bindings can also be sealed, thereby protecting the particular bindings instance from further modifications (it can still be inherited, though).
Version:
1.0
  • Field Details

    • DATA

      public static final int DATA
      The static string data binding type. Any data value of this type must be a string.
      See Also:
    • PROCEDURE

      public static final int PROCEDURE
      The procedure name binding type. Any data value of this type must be a string containing the procedure name.
      See Also:
    • CONNECTION

      public static final int CONNECTION
      The connection pool name binding type. Any data value of this type must be a string containing the connection pool name.
      See Also:
    • ARGUMENT

      public static final int ARGUMENT
      The argument binding type. The data values of this type can be any object.
      See Also:
  • Constructor Details

    • Bindings

      public Bindings()
      Creates a new empty bindings container.
    • Bindings

      public Bindings(Bindings parent)
      Creates a new empty child bindings container.
      Parameters:
      parent - the parent bindings container
    • Bindings

      public Bindings(Bindings parent, Array arr)
      Creates a new bindings container with the specified data.
      Parameters:
      parent - the parent bindings container, or null
      arr - the data array to use, or null
  • Method Details

    • hasName

      public boolean hasName(String name)
      Checks if the specified binding name exists.
      Parameters:
      name - the binding name
      Returns:
      true if the name exists, or false otherwise
    • getNames

      public String[] getNames()
      Returns an array with all names defined in the hierarchy of bindings.
      Returns:
      an array with all binding names
    • getType

      public int getType(String name) throws ProcedureException
      Finds the type for a binding.
      Parameters:
      name - the binding name
      Returns:
      the binding data type
      Throws:
      ProcedureException - if the binding name wasn't found
    • getTypeName

      public String getTypeName(String name) throws ProcedureException
      Finds the type name identifier for a binding. Use the getType() method for most access. Only use this string value for debug printing or serialization.
      Parameters:
      name - the binding name
      Returns:
      the binding data type name
      Throws:
      ProcedureException - if the binding name wasn't found
    • getValue

      public Object getValue(String name) throws ProcedureException
      Finds the value for a binding.
      Parameters:
      name - the binding name
      Returns:
      the value binding
      Throws:
      ProcedureException - if the binding name wasn't found or if the value was null
    • getValue

      public Object getValue(String name, Object defaultValue) throws ProcedureException
      Finds the value for a binding.
      Parameters:
      name - the binding name
      defaultValue - the default value
      Returns:
      the value binding
      Throws:
      ProcedureException - if the binding name wasn't found
    • getDescription

      public String getDescription(String name) throws ProcedureException
      Returns the human-readable description for a binding.
      Parameters:
      name - the binding name
      Returns:
      the binding description, or an empty string if not set
      Throws:
      ProcedureException - if the binding name wasn't found
    • set

      public void set(String name, int type, Object value, String description) throws ProcedureException
      Sets the value for a binding. If the binding already exists locally it will be modified, otherwise it will be added. If the description is set to null, any parent binding description will be used instead.
      Parameters:
      name - the binding name
      type - the binding type
      value - the binding value, or null
      description - the binding description, or null
      Throws:
      ProcedureException - if this object was sealed
    • seal

      public void seal()
      Seals these bindings and prevents future modification. This method is used by built-in procedures once they have created their default (read-only) binding objects.
    • processTemplate

      public String processTemplate(String tpl, TextEncoding encoding)
      Replaces template variables with the corresponding argument value from the bindings. This method supports both raw (e.g. "@key") and encoded (e.g. ":key") template variables.
      Parameters:
      tpl - the template string to process
      encoding - the text encoding for values
      Returns:
      the processed template string