| java.lang.Object org.cougaar.lib.aggagent.script.PythXMLEncoder
PythXMLEncoder | public class PythXMLEncoder implements XMLEncoder(Code) | | An implementation of XMLEncoder that derives its functionality from
a script written in the JPython language. A PythXMLEncoder 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 PythXMLEncoder 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 XMLEncoder instance or a function designed to act as
the "encode" method of an XMLEncoder.
This class implements the XMLEncoder interface, and can be instantiated by
calling the constructor or a static factory method, encoderFromScript().
|
Constructor Summary | |
public | PythXMLEncoder(String script) Create a PythUnaryPredicate instance by using a script-generated
UnaryPredicate as a delegate. |
PythXMLEncoder | public PythXMLEncoder(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 |
encode | public void encode(Object o, Collection out)(Code) | | An implementation of the encode method of interface XMLEncoder. The
function is actually delegated to a script-generated implementation,
which is fabricated in the constructor.
Parameters: o - an object to be encoded Parameters: out - a Collection to which results of this operation are added |
encoderFromScript | public static XMLEncoder encoderFromScript(String script)(Code) | | Create an XMLEncoder from a JPython script. There are two acceptable
modes for the script. Either it must produce a JPython subclass of Java
interface XMLEncoder, or it must produce a JPython function that behaves
like the method XMLEncoder.encode (i.e., takes two arguments and treats
the second one like a PrintStream). Either way, the script is required
to define the magic function "instantiate()" to provide the function or
encoder instance to the Java context.
Parameters: script - the executable script that declares classes and variables an XMLEncoder instance derived from the JPython scripts |
|
|