| java.lang.Object org.cougaar.lib.aggagent.script.PythIncrementFormat
PythIncrementFormat | public class PythIncrementFormat implements IncrementFormat(Code) | | An implementation of IncrementFormat that derives its functionality from
a script written in the JPython language. A PythIncrementFormat 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 PythIncrementFormat 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 an IncrementFormat instance or a function designed to
act as the "encode" method of an IncrementFormat.
This class implements the IncrementFormat interface, and can be
instantiated by calling the constructor or a static factory method,
formatFromScript().
|
Constructor Summary | |
public | PythIncrementFormat(String script) Create a PythIncrementFormat instance by using a script-generated
IncrementFormat as a delegate. |
PythIncrementFormat | public PythIncrementFormat(String script)(Code) | | Create a PythIncrementFormat instance by using a script-generated
IncrementFormat as a delegate.
Parameters: script - the JPython script that defines the embodied functionality |
encode | public void encode(UpdateDelta out, SubscriptionAccess sacc)(Code) | | An implementation of the encode method of interface IncrementFormat. The
function is actually delegated to a script-generated implementation,
which is fabricated in the constructor.
Parameters: out - an UpdateDelta to be returned to the client Parameters: sacc - the subscription data to be encoded |
formatFromScript | public static IncrementFormat formatFromScript(String script)(Code) | | Create an IncrementFormat from a JPython script. There are two
acceptable modes for the script. It must produce either a JPython
subclass of Java interface IncrementFormat or a JPython function that
behaves like the method IncrementFormat.encode (i.e., takes two
arguments and treats them as an UpdateDelta and a SubscriptionAccess).
Either way, the script is required to define the magic function
"instantiate()" to provide the function or formatter instance to the Java
context.
Parameters: script - the executable script that declares classes and variables an IncrementFormat instance derived from the JPython scripts |
|
|