sleep.interfaces
Interface FilterEnvironment


public interface FilterEnvironment

Filtered environments are similar to normal keyword environments except they also allow a parameter specified by the user. The identifier and parameter are both sent to the bridge when a block of code is bound to a particular filtered environment keyword.

In general the syntax for binding a filtered environment is:

keyword identifier "parameter" { code; }

One thing worth noting is that when the "parameter" string gets passed to the class implementing this interface, the "parameter" will be unevaluated. So if the "parameter" was an expression i.e. (2 + 2), the value passed back to the interface would be the string "(2 + 2)". To evaluate the parameter use the following code:

ScriptEnvironment environment = script.getScriptEnvironment();
 Scalar value = environment.evaluateExpression(parameter);

Script filtered environment bridge keywords should be registered with the script parser before any scripts are loaded. This can be accomplished as follows:

ParserConfig.addKeyword("keyword");

To install a new filtered environment into the script environment:

 ScriptInstance script;              // assume
 FilterEnvironment    myEnvironmentBridge; // assume
 
 Hashtable environment = script.getScriptEnvironment().getEnvironment();
 environment.put("keyword", myEnvironmentBridge);
 

Filter environments are really just an extension of the normal environment bridges. In particular filter environments can be used to implement event listener mechanisms or as an expansion fornormal environment bridges that might require a parameter.

See Also:
Environment, ParserConfig.addKeyword(String)

Method Summary
 void bindFilteredFunction(ScriptInstance si, java.lang.String keyword, java.lang.String identifier, java.lang.String parameter, Block functionBody)
          binds a function (functionName) of a certain type (typeKeyword) to the defined functionBody.
 

Method Detail

bindFilteredFunction

void bindFilteredFunction(ScriptInstance si,
                          java.lang.String keyword,
                          java.lang.String identifier,
                          java.lang.String parameter,
                          Block functionBody)
binds a function (functionName) of a certain type (typeKeyword) to the defined functionBody.

Parameters:
keyword - the keyword for the function.
identifier - the identifier attached to this keyword
parameter - the parameter specified with this declaration. The parameter keyword is passed in unparsed to allow you, the bridge writer, choice in the matter of what to do with the parameter. Depending on the purpose of the bridge some maywant to evaluate the parameter when the block of code is first bound. Others may want to evaluate the parameter each time the bridge carries out its actions.
functionBody - the compiled body of the function (i.e. code to add 2 numbers)