Class BSHMethod


  • public class BSHMethod
    extends java.lang.Object
    This is a utility class that makes it a bit easier to work with beanshell scripts. Check out the execute methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      BSHMethod​(java.lang.String bshData, boolean source)
      Creates a BSHMethod.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static BSHMethod createBshMethod​(org.jdom2.Element e)
      Creates a BSHMethod from a JDom Element.
      java.lang.Object execute​(java.util.Map arguments, java.lang.String resultName)
      Sets the given arguments to the Interpreter, evaluates the script and returns the object stored on the variable named resultName.
      java.util.Map execute​(java.util.Map arguments, java.util.Collection returnNames)
      Sets the given arguments to the Interpreter, evaluates the script and returns a map that has the Strings of the returnNames collection as keys and the objects stored in the variables thus named as values.
      protected bsh.Interpreter initInterpreter​(java.util.Map arguments)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • BSHMethod

        public BSHMethod​(java.lang.String bshData,
                         boolean source)
        Creates a BSHMethod.
        Parameters:
        bshData - - May either be the file to source or the script itself to evaluate.
        source - - If true indicates that the bshData passed is a file to source. Otherwise the string itself is evaluated.
    • Method Detail

      • createBshMethod

        public static BSHMethod createBshMethod​(org.jdom2.Element e)
                                         throws java.io.IOException
        Creates a BSHMethod from a JDom Element. The element is not requiered to have a specific name. If the given element defines an attribute named 'file' the file specified as its value will be sourced by the created BSHMethod. If the 'file' attribute is specified, a 'cache' attribute may be specified as well which can take the values true|false and indicates wether to load the script to memory or to read from the file for every script evaluation. If the 'file' attibute is not specified then the text contained by the element is set to be evaluated by the new BSHMethod.
          Example 1 : 
                  <prepare>
                          import org.jpos.iso.*;
                        import org.jpos.transaction.*;
        
                                msg = context.get("txnRequest");
                                BaseChannel.getChannel("loop-channel").send(msg);
                                result=TransactionConstants.PREPARED | TransactionConstants.READONLY;
                        </prepare>
        
          Example 2 :
                  <routing file='cfg\files\routing1.bsh' cache='false'/>
          
        Throws:
        java.io.IOException
      • execute

        public java.lang.Object execute​(java.util.Map arguments,
                                        java.lang.String resultName)
                                 throws bsh.EvalError,
                                        java.io.IOException
        Sets the given arguments to the Interpreter, evaluates the script and returns the object stored on the variable named resultName.
        Parameters:
        arguments - Parameters to set to the Interpreter. For every Map.Entry (key, value), interpreter.set(key, value) is called. All keys must be Strings.
        Throws:
        bsh.EvalError
        java.io.IOException
      • execute

        public java.util.Map execute​(java.util.Map arguments,
                                     java.util.Collection returnNames)
                              throws bsh.EvalError,
                                     java.io.IOException
        Sets the given arguments to the Interpreter, evaluates the script and returns a map that has the Strings of the returnNames collection as keys and the objects stored in the variables thus named as values.
        Parameters:
        arguments - Parameters to set to the Interpreter. For every Map.Entry (key, value), interpreter.set(key, value) is called. All keys must be Strings.
        returnNames - Collection of Strings. The names of the variables wich`s contents are to be returned.
        Throws:
        bsh.EvalError
        java.io.IOException
      • initInterpreter

        protected bsh.Interpreter initInterpreter​(java.util.Map arguments)
                                           throws bsh.EvalError,
                                                  java.io.IOException
        Throws:
        bsh.EvalError
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object