| java.lang.Object org.cougaar.lib.aggagent.script.PythUnaryPredicate
PythUnaryPredicate | public class PythUnaryPredicate implements UnaryPredicate(Code) | | An implementation of UnaryPredicate that derives its functionality from
a script written in the JPython language. A PythUnaryPredicate is
configured in two stages: one is to declare a function or class, and the
other is to pass the function or an instance of the class to the
controlling Java context.
The necessity of using a two-stage initialization procedure for both types
of PythUnaryPredicate implementations is due to JPython's resolute refusal
to allow an expression to declare a new function or class (or, indeed, any
multiline construct). One possibility is to use a "magic" function through
which the Java and JPython contexts can communicate. For the sake of
uniformity, this option is used here. The magic function is "instantiate",
which the script should define in the global context as a no-arg function
that returns either a UnaryPredicate instance or a function designed to act
as the "execute" method of a UnaryPredicate.
This class implements the UnaryPredicate interface, and can be instantiated
by calling the constructor or a static factory method,
predicateFromScript().
|
Constructor Summary | |
public | PythUnaryPredicate(String script) Create a PythUnaryPredicate instance by using a script-generated
UnaryPredicate as a delegate. |
PythUnaryPredicate | public PythUnaryPredicate(String script)(Code) | | Create a PythUnaryPredicate instance by using a script-generated
UnaryPredicate as a delegate.
Parameters: script - the JPython script that defines the embodied functionality |
execute | public boolean execute(Object o)(Code) | | An implementation of the execute method of interface UnaryPredicate. The
function is actually delegated to a script-generated implementation,
which is fabricated in the constructor.
Parameters: o - an object to be tested true if and only if the object matches the predicate |
predicateFromScript | public static UnaryPredicate predicateFromScript(String script)(Code) | | Create a UnaryPredicate from a JPython script. There are two acceptable
modes for the script. Either it must produce a JPython subclass of Java
interface UnaryPredicate, or it must produce a JPython function that
behaves like the method UnaryPredicate.execute (i.e., takes one argument
and returns a JPython-style boolean result (which is really a number
where zero denotes "false" and any other value denotes "true")). Either
way, the script is required to define the magic function "instantiate()"
to provide the function or predicate instance to the Java context.
Parameters: script - the executable script that declares classes and variables a UnaryPredicate instance derived from the JPython scripts |
|
|