Hi,

Am Mittwoch, den 30.04.2008, 21:07 +0600 schrieb janandith jayawardena:
> Hi ,
> 
> According to what i observed from scripting modules in Sling there is a
> Script Context used in the Script Engine's eval method.
> 
> Also according to what i understood from the JSR 223 spec a Script context
> provide a view of host application to the Script Engine.
> 
> ex: Define Global scope , Engine scope and other aspects of aplication such
> as readers & writers.

Right. The ScriptContext is used to inject variables in the globale
scope (intended to be shared among all ScriptContext instances) and the
engine scope (intended to only be visible to the ScriptEngine, whose
eval method will be called.

The ScriptContext is generally prepared by the caller of the
ScriptEngine.eval method to provide this information. Now in the case of
Sling, the SlingDefaultScript is actually the caller and fills the
ScriptContext for the ScriptEngine to evaluate.

> 
> If I'm right in my case Sling is the host Scripting Engine is the guest
> working with the host using Script Context. Is this correct ?

Yes.

> 
> Now Velocity has a VelocityContext according to
> VelocityTemplatesScriptEngine .

VelocityContext is AFAIK not a ScriptContext but a class of the Velocity
runtime used to inject environment and execution information into the
Velocity runtime. It is comparable to the ScriptContext but predates
JSR-223 and is therefore specific to Velocity.

> So I mailed the Scala mailing list to check whether there is a Context
> available for Scala but there is no response for it.
> So I assume there isn't one and I should be using the default
> javax.script.ScriptContext.

As an implementor of the ScriptEngine[Factory] you need not care about
the concrete ScriptContext, which is handed to you by Sling. You take
from it, what you need, e.g. the error output channel.

In particular you would take the scoped attributes from the
ScriptContext to inject them as predefined variables of the Script.
Whether and how this would be possible for Scala I cannot tell.

> 
> I am not clear about the way Sling looks like to a Script Engine when it
> works with it.
> 
> For example ,
> 
> What is in the Global scope of Sling when viewed by Script Engine.

Global scoped variables are not set by Sling right now. Sling only sets
Engine Scoped variables. These are used as global/predefined variables
in JavaScript. You might want to look at the RhinoJavaScriptEngine for a
hint how the variables are used.

> How can It use it.
> etc.
> 
> Does the Script Context behave like a mediator between Sling and Script
> Engine like the following  ?.
> 
> ex:   Sling <----------> Script Context <--------------> Script
> Engine<---------- Script.

Exactly.

Hope, this helps.

Regards
Felix


Reply via email to