| java.lang.Object sisc.util.Util sisc.interpreter.Context
Context | abstract public class Context extends Util (Code) | | Context is a utility class which facilitates Java to Scheme
calls in SISC.
Typically, this involves obtaining an Interpreter for a given
initialized
sisc.interpreter.AppContext , using the Interpreter for one or more
evaluations, then exiting the context, as follows:
AppContext ctx = ...
Interpreter r=Context.enter(ctx);
r.eval(someProcedure, new Value[] { ... some arguments ... });
Context.exit();
Preferrably, one should use the SchemeCaller supported visitor pattern
to allow Context to handle the management of the Interpreter Context,
as follows:
Object returnValue=Context.execute(ctx, mySchemeCaller);
The provided SchemeCaller instance's execute method is invoked with
an Interpreter which is automatically obtained and then returned when
the call completes. The return value of the SchemeCaller's execute
method is returned from the Context method.
See Also: SchemeCaller See Also: AppContext See Also: Interpreter |
Method Summary | |
public static AppContext | currentAppContext() Returns the AppContext of any current interpreter in an
internal call, or the default AppContext if no current
interpreter is present. | public static Interpreter | currentInterpreter() Fetches the current Interpreter, if this is an internal call (that is,
a call from Java to Scheme in the contex of a Scheme->Java call). | public static Interpreter | currentInterpreter(AppContext ctx) Fetches the nearest enclosing Interpreter that operates on a
given AppContext, if this is an internal call (that is, a call
from Java to Scheme in the contex of a Scheme->Java call). | public static Interpreter | enter() Returns an Interpreter that shares the AppContext and
DynamicEnvironment with the current Interpreter. | public static Interpreter | enter(AppContext ctx) Returns an Interpreter bound to the given AppContext with same
DynamicEnvironment as the nearest enclosing Interpreter in the
same thread that is bound to the same AppContext. | public static Interpreter | enter(DynamicEnvironment dynenv) Returns an Interpreter bound to the given DynamicEnvironment. | public static Interpreter | enter(String appName) | public static Object | execute(SchemeCaller caller) Calls caller with an Interpreter that shares the AppContext and
DynamicEnvironment with the current Interpreter. | public static Object | execute(AppContext ctx, SchemeCaller caller) Calls caller with an Interpreter bound to the given AppContext
with same DynamicEnvironment as the nearest enclosing
Interpreter in the same thread that is bound to the same
AppContext. | public static Object | execute(DynamicEnvironment dynenv, SchemeCaller caller) Obtains an Interpreter bound to the given DynamicEnvironment
and invokes caller.execute(Interpreter) with that Interper.
Once execute returns, the Interpreter is freed, and the return
value of caller.execute() is returned from this method.
NB: It is critical that the Interpreter reference provided
during the call is used only in the thread which calls this
method. | public static Object | execute(String appName, SchemeCaller caller) | public static void | exit() Exits the current context, releasing the current Interpreter. | public static synchronized AppContext | getDefaultAppContext() Returns the currently set default AppContext, or creates
a new AppContext with default values if non was already set,
and attempts to initialize it with the default heap. | public static AppContext | lookup(String appName) | public static ThreadContext | lookupThreadContext() | public static void | register(String appName, AppContext ctx) | public static synchronized void | setDefaultAppContext(AppContext ctx) Sets the default AppContext, which is used sparingly whenever
a call originates from uncontrolled Java source that involves
the Scheme environment. | public static void | unregister(String appName) |
currentAppContext | public static AppContext currentAppContext()(Code) | | Returns the AppContext of any current interpreter in an
internal call, or the default AppContext if no current
interpreter is present.
|
currentInterpreter | public static Interpreter currentInterpreter()(Code) | | Fetches the current Interpreter, if this is an internal call (that is,
a call from Java to Scheme in the contex of a Scheme->Java call).
the current Interpreter, or null if this is not aninternal call. |
currentInterpreter | public static Interpreter currentInterpreter(AppContext ctx)(Code) | | Fetches the nearest enclosing Interpreter that operates on a
given AppContext, if this is an internal call (that is, a call
from Java to Scheme in the contex of a Scheme->Java call).
Parameters: ctx - the AppContext the nearest enclosing Interpreter operating on thegiven ctx, or null if no such Interpreter exists. |
enter | public static Interpreter enter()(Code) | | Returns an Interpreter that shares the AppContext and
DynamicEnvironment with the current Interpreter. If there is no
current Interpreter present, an Interpreter bound to the
default AppContext is returned instead.
This method provides the usual mechanism for obtaining an
Interpreter for calling from Java to Scheme.
See Also: Interpreter |
enter | public static Interpreter enter(AppContext ctx)(Code) | | Returns an Interpreter bound to the given AppContext with same
DynamicEnvironment as the nearest enclosing Interpreter in the
same thread that is bound to the same AppContext. If no such
Interpreter exists then a new DynamicEnvironment is created,
bound to the AppContext.
Parameters: ctx - The AppContext The newly created Interpreter |
enter | public static Interpreter enter(DynamicEnvironment dynenv)(Code) | | Returns an Interpreter bound to the given DynamicEnvironment.
Parameters: dynenv - The DynamicEnvironment The newly created Interpreter |
execute | public static Object execute(SchemeCaller caller) throws SchemeException(Code) | | Calls caller with an Interpreter that shares the AppContext and
DynamicEnvironment with the current Interpreter. If there is no
current Interpreter present, an Interpreter bound to the
default AppContext is created instead.
This method provides the usual mechanism for managed calls from
Java to Scheme.
Parameters: caller - The SchemeCaller to invoke the result of invoking the SchemeCaller |
execute | public static Object execute(AppContext ctx, SchemeCaller caller) throws SchemeException(Code) | | Calls caller with an Interpreter bound to the given AppContext
with same DynamicEnvironment as the nearest enclosing
Interpreter in the same thread that is bound to the same
AppContext. If no such Interpreter exists then a new
DynamicEnvironment is returned, bound to the AppContext.
Parameters: ctx - The AppContext Parameters: caller - The SchemeCaller to invoke. the result of invoking the SchemeCaller |
execute | public static Object execute(DynamicEnvironment dynenv, SchemeCaller caller) throws SchemeException(Code) | | Obtains an Interpreter bound to the given DynamicEnvironment
and invokes caller.execute(Interpreter) with that Interper.
Once execute returns, the Interpreter is freed, and the return
value of caller.execute() is returned from this method.
NB: It is critical that the Interpreter reference provided
during the call is used only in the thread which calls this
method. New threads should obtain a different Interpreter via
this or enter() calls.
Parameters: dynenv - The DynamicEnvironment. Parameters: caller - The SchemeCaller to invoke. the result of invoking the SchemeCaller |
exit | public static void exit()(Code) | | Exits the current context, releasing the current Interpreter.
|
getDefaultAppContext | public static synchronized AppContext getDefaultAppContext()(Code) | | Returns the currently set default AppContext, or creates
a new AppContext with default values if non was already set,
and attempts to initialize it with the default heap.
|
lookupThreadContext | public static ThreadContext lookupThreadContext()(Code) | | thread context lookup **********
|
setDefaultAppContext | public static synchronized void setDefaultAppContext(AppContext ctx)(Code) | | Sets the default AppContext, which is used sparingly whenever
a call originates from uncontrolled Java source that involves
the Scheme environment. For example, Java serialization initiated
by a web application server.
Parameters: ctx - the AppContext to make the default. |
unregister | public static void unregister(String appName)(Code) | | |
Methods inherited from sisc.util.Util | final public static AnnotatedExpr annotated(Value o)(Code)(Java Doc) public static Expression annotatedAppEval(Class clazz, String fn)(Code)(Java Doc) public static Pair append(Pair p1, Pair p2)(Code)(Java Doc) final public static void argCheck(Pair argl, int arity) throws Exception(Code)(Java Doc) public static Symbol[] argsToSymbols(Pair p)(Code)(Java Doc) public static Value assq(Value v, Pair p)(Code)(Java Doc) final public static SchemeBinaryInputPort bininport(Value o)(Code)(Java Doc) final public static InputStream bininstream(Value o)(Code)(Java Doc) final public static SchemeBinaryOutputPort binoutport(Value o)(Code)(Java Doc) final public static OutputStream binoutstream(Value o)(Code)(Java Doc) final public static Box box(Value o)(Code)(Java Doc) final public static char character(Value c)(Code)(Java Doc) final public static SchemeCharacterInputPort charinport(Value o)(Code)(Java Doc) final public static Reader charinreader(Value o)(Code)(Java Doc) final public static SchemeCharacterOutputPort charoutport(Value o)(Code)(Java Doc) final public static Writer charoutwriter(Value o)(Code)(Java Doc) public static Charset charsetFromString(String charsetName)(Code)(Java Doc) final public static SchemeCharacter chr(Value o)(Code)(Java Doc) final public static CallFrame cont(Value o)(Code)(Java Doc) public static ClassLoader currentClassLoader()(Code)(Java Doc) final public static SymbolicEnvironment env(Value o)(Code)(Java Doc) public static void error(Interpreter r, Value where, String errormessage, Pair moreData) throws ContinuationException(Code)(Java Doc) public static void error(Interpreter r, Value where, String errormessage, Exception e) throws ContinuationException(Code)(Java Doc) public static void error(Interpreter r, Value where, String errormessage) throws ContinuationException(Code)(Java Doc) public static void error(Interpreter r, String errormessage, Pair moreData) throws ContinuationException(Code)(Java Doc) public static void error(Interpreter r, String errormessage) throws ContinuationException(Code)(Java Doc) public static void error(Interpreter r, Value errormessage) throws ContinuationException(Code)(Java Doc) public static void error(Interpreter r, Pair error) throws ContinuationException(Code)(Java Doc) final public static Expression expr(Value o)(Code)(Java Doc) public static Charset getDefaultCharacterSet()(Code)(Java Doc) final public static ImmutablePair immutablePair(Value o)(Code)(Java Doc) final public static ImmutableVector immutableVector(Value o)(Code)(Java Doc) final public static InputPort inport(Value o)(Code)(Java Doc) protected static String javaExceptionToString(Exception e)(Code)(Java Doc) public static Value javaWrap(Object o)(Code)(Java Doc) public static String justify(String v, int p, char c)(Code)(Java Doc) public static int length(Pair p)(Code)(Java Doc) public static String liMessage(Symbol bundleName, String messageName)(Code)(Java Doc) public static String liMessage(Symbol bundle, String messageName, String arg1)(Code)(Java Doc) public static String liMessage(Symbol bundle, String messageName, String arg1, String arg2)(Code)(Java Doc) public static String liMessage(Symbol bundle, String messageName, String arg1, String arg2, String arg3)(Code)(Java Doc) public static String liMessage(Symbol bundle, String messageName, String arg1, String arg2, String arg3, String arg4)(Code)(Java Doc) public static String liMessage(Symbol bundle, String messageName, String arg1, int arg2, int arg3)(Code)(Java Doc) public static String liMessage(Symbol bundle, String messageName, Object[] args)(Code)(Java Doc) final public static Pair list(Value o1)(Code)(Java Doc) final public static Pair list(Value o1, Value o2)(Code)(Java Doc) final public static Pair list(Value o1, Value o2, Value o3)(Code)(Java Doc) final public static Pair list(Value o1, Value o2, Value o3, Value o4)(Code)(Java Doc) final public static Pair list(Value o1, Value o2, Value o3, Value o4, Value o5)(Code)(Java Doc) public static URL makeURL(String url)(Code)(Java Doc) public static Pair mapcar(Pair list)(Code)(Java Doc) public static Value memq(Value v, Pair p)(Code)(Java Doc) final public static NativeLibrary nlib(Value o)(Code)(Java Doc) final public static Quantity num(Value o)(Code)(Java Doc) final public static OutputPort outport(Value o)(Code)(Java Doc) final public static Pair pair(Value o)(Code)(Java Doc) public static Vector pairToExpVect(Pair p)(Code)(Java Doc) public static Expression[] pairToExpressions(Pair p)(Code)(Java Doc) public static Value[] pairToValues(Pair p)(Code)(Java Doc) final public static Procedure proc(Value o)(Code)(Java Doc) public static Value read(String expr) throws IOException(Code)(Java Doc) public static void registerBundle(Symbol bundleName) throws MissingResourceException(Code)(Java Doc) public static Pair reverse(Pair p)(Code)(Java Doc) public static Pair reverseInPlace(Pair s)(Code)(Java Doc) public static String simpleErrorToString(Pair p)(Code)(Java Doc) public static Pair sourceAnnotations(String file, int line, int column, Pair anns)(Code)(Java Doc) final public static SchemeString str(Value o)(Code)(Java Doc) final public static String string(Value o)(Code)(Java Doc) final public static Symbol sym(String s)(Code)(Java Doc) final public static Symbol symbol(Value o)(Code)(Java Doc) final public static String symval(Value o)(Code)(Java Doc) final public static Pair truePair(Value o)(Code)(Java Doc) final public static SchemeBoolean truth(boolean b)(Code)(Java Doc) final public static boolean truth(Value v)(Code)(Java Doc) public static void typeError(String type, Value o)(Code)(Java Doc) public static void typeError(Symbol bundleName, String type, Value o)(Code)(Java Doc) public static void updateName(Value v, Symbol s)(Code)(Java Doc) public static URL url(Value v)(Code)(Java Doc) public static URL url(String s) throws MalformedURLException(Code)(Java Doc) public static URL url(Value current, Value v)(Code)(Java Doc) final public static Pair valArrayToList(Value[] r, int offset, int len)(Code)(Java Doc) final public static Pair valArrayToList(Value[] r)(Code)(Java Doc) final public static SchemeVector valArrayToVec(Value[] r)(Code)(Java Doc) final public static SchemeVector vec(Value o)(Code)(Java Doc) public static String warn(String messageClass)(Code)(Java Doc) public static String warn(String messageClass, String sourceFile, int lineNumber, int columnNumber)(Code)(Java Doc) public static String warn(String messageClass, String arg)(Code)(Java Doc)
|
|
|