You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Dishara Wijewardana <dd...@gmail.com> on 2012/06/10 08:45:26 UTC

Problem of Wrapping VelocityContext in JSR 223

Hi all,
Wrapping VelocityContext as the ScriptContext in JSR 223 seems not possible
as the intended behavior of each implementation is
quite different. Because VelocityContext is more like expected to behave as
a Map with having additional ability to have an inner context and etc.

So this VelocityContext is very much in to the behavior of
javax.script.Binding which is exactly a Map like behavior.
I think best way is to use it in that context. But still VelocityContext
has limited number of methods covers in a Map while Bindings interface
directly extends java.util.Map.

So what is the best way to accomplish this Bindings concept. But of course
we should not extend the VelocityContext behavior to go close with Bindings.
Shall we just wrap the VelocityBindings class with a Map object. And in the
VelocityScriptEngine, internally we can use(we have to) the velocity
context for evaluation methods.

What do you think ?

-- 
Thanks
/Dishara

Re: Problem of Wrapping VelocityContext in JSR 223

Posted by Dishara Wijewardana <dd...@gmail.com>.
On Mon, Jun 11, 2012 at 12:36 AM, Claude Brisson <cl...@renegat.net> wrote:

> A VelocityContext object is just a wrapper around a Map, the only point
> is just that it does not expose all methods of the wrapped Map.
>
> But we don't have to use VelocityContext directly: the only constraint
> is that we implement the org.apache.velocity.context.Context interface.
> So the easiest way is maybe to have VelocityBindings inherit Map and
> implement org.apache.velocity.context.Context directly.
>
+1, Will try and update you if problems occurs. Unless will commit the
proposed changes

>
>
>  Claude
>
> On Sun, 10 Jun 2012 12:15:26 +0530
> Dishara Wijewardana <dd...@gmail.com> wrote:
>
> > Hi all,
> > Wrapping VelocityContext as the ScriptContext in JSR 223 seems not
> > possible as the intended behavior of each implementation is
> > quite different. Because VelocityContext is more like expected to
> > behave as a Map with having additional ability to have an inner
> > context and etc.
> >
> > So this VelocityContext is very much in to the behavior of
> > javax.script.Binding which is exactly a Map like behavior.
> > I think best way is to use it in that context. But still
> > VelocityContext has limited number of methods covers in a Map while
> > Bindings interface directly extends java.util.Map.
> >
> > So what is the best way to accomplish this Bindings concept. But of
> > course we should not extend the VelocityContext behavior to go close
> > with Bindings. Shall we just wrap the VelocityBindings class with a
> > Map object. And in the VelocityScriptEngine, internally we can use(we
> > have to) the velocity context for evaluation methods.
> >
> > What do you think ?
> >
>
>


-- 
Thanks
/Dishara

Re: Problem of Wrapping VelocityContext in JSR 223

Posted by Claude Brisson <cl...@renegat.net>.
A VelocityContext object is just a wrapper around a Map, the only point
is just that it does not expose all methods of the wrapped Map.

But we don't have to use VelocityContext directly: the only constraint
is that we implement the org.apache.velocity.context.Context interface.
So the easiest way is maybe to have VelocityBindings inherit Map and
implement org.apache.velocity.context.Context directly.


  Claude

On Sun, 10 Jun 2012 12:15:26 +0530
Dishara Wijewardana <dd...@gmail.com> wrote:

> Hi all,
> Wrapping VelocityContext as the ScriptContext in JSR 223 seems not
> possible as the intended behavior of each implementation is
> quite different. Because VelocityContext is more like expected to
> behave as a Map with having additional ability to have an inner
> context and etc.
> 
> So this VelocityContext is very much in to the behavior of
> javax.script.Binding which is exactly a Map like behavior.
> I think best way is to use it in that context. But still
> VelocityContext has limited number of methods covers in a Map while
> Bindings interface directly extends java.util.Map.
> 
> So what is the best way to accomplish this Bindings concept. But of
> course we should not extend the VelocityContext behavior to go close
> with Bindings. Shall we just wrap the VelocityBindings class with a
> Map object. And in the VelocityScriptEngine, internally we can use(we
> have to) the velocity context for evaluation methods.
> 
> What do you think ?
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org