Module jamal.engine

Class ScriptMacro

  • All Implemented Interfaces:
    Evaluable, Identified, ScriptMacro

    public class ScriptMacro
    extends java.lang.Object
    implements ScriptMacro
    Stores the information about a user defined macro and can also evaluate it using actual parameter string values.
    • Constructor Summary

      Constructors 
      Constructor Description
      ScriptMacro​(Processor processor, java.lang.String id, java.lang.String scriptType, java.lang.String content, java.lang.String... parameters)
      Creates a new user defined macro.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String evaluate​(java.lang.String... actualValues)
      Evaluate the content of the user defined macro using the actual values for the parameter values.
      int expectedNumberOfArguments()  
      java.lang.String getId()
      Get the name / identifier of the user defined macro.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ScriptMacro

        public ScriptMacro​(Processor processor,
                           java.lang.String id,
                           java.lang.String scriptType,
                           java.lang.String content,
                           java.lang.String... parameters)
        Creates a new user defined macro.
        Parameters:
        processor - is the context of the evaluation. Through this object a macro can access the evaluation environment.
        id - the identifier of the macro. This is the string that stands after the define keyword when the user defined macro is defined. This is a unique identified in the context where the macro is reachable and usable.
        scriptType - the type of the script. The scripting engine with this name is used to execute the content. The value jamal means that content has to be interpreted by Jamal itself.
        content - the text of the macro that stands after the = character and before the macro closing character.
        parameters - the names of the parameters. These do not actually need to be real identifiers, alphanumeric or something like that. The only requirement is that there is no comma in these names. It is recommended though to use usual identifiers.
    • Method Detail

      • getId

        public java.lang.String getId()
        Get the name / identifier of the user defined macro.
        Specified by:
        getId in interface Identified
        Returns:
        the id.
      • evaluate

        public java.lang.String evaluate​(java.lang.String... actualValues)
                                  throws BadSyntax
        Evaluate the content of the user defined macro using the actual values for the parameter values.
        Specified by:
        evaluate in interface Evaluable
        Parameters:
        actualValues - the actual string values for the parameters
        Returns:
        the string that is the result of the evaluation
        Throws:
        BadSyntaxAt - if the user defined macro is a script and the script evaluation throws exception. This exception is thrown if the number of the actual values is not the same as the number of the parameters.
        BadSyntax