You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Jaap van der Molen <ja...@vandermolen.net> on 2004/04/19 11:27:52 UTC

VelocityToolbox - ToolboxContext

Hi,

I have the following problem with the ToolboxContext: the class extends
VelocityContext, yet doesn't implement any of the methods in the class
hierarchy.
The collection of ToolInfo objects is stored in a private Map on the
ToolboxContext,
meaning the super-class methods like getKeys(), etc. do not return a
correct result.

Similar for ChainedContext. If I create a ChainedContext using an existing
VelocityContext, the getKeys() method returns 0 (zero), while the
VelocityContext
does contain elements.

Is there a specific reason for this? Or should I go for a bug report?

Background: I am trying to get the tools available in the vm's of an
existing web
application (Roller - http://www.rollerweblogger.org). I have to work with an
existing VelocityContext object that I can't simply replace by a
ChainedContext.

-- 
Jaap





-- 
Jaap


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


Re: ToolboxManager.getToolboxContext(Object) not helping - continued

Posted by Claude Brisson <cl...@renegat.net>.
> yeah, "context" is a pretty generic term.  easy to get confused.

it depends upon the context
...hum...

CloD

----- Original Message ----- 
From: "Nathan Bubna" <na...@esha.com>
To: "Velocity Developers List" <ve...@jakarta.apache.org>
Sent: Friday, April 23, 2004 6:49 AM
Subject: Re: ToolboxManager.getToolboxContext(Object) not helping - continued


> Paulo Silveira said:
> > I took a better look at the code, and there is no way to create a new
> > method since the Object initdata is sent to the ToolInfos for tool
> > instatiations.
> 
> yeah, i thought so.  i was just wondering if you might have seen something i
> didn't.
> 
> > So now I am implementing ViewContext. I dindt see that ViewContext does
> > not extends Context. The name got me confused.
> 
> yeah, "context" is a pretty generic term.  easy to get confused.
> 
> > Now I can do what I need! Something that really could come in handy is a
> > ServletToolboxManaget.getInstance(InputStream).
> ...
> 
> something along those lines might be easier.  i'm always happy to look over
> enhancement patches. :)
> 
> Nathan Bubna
> nathan@esha.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 

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


Re: ToolboxManager.getToolboxContext(Object) not helping - continued

Posted by Paulo Silveira <pa...@paulo.com.br>.
Nathan Bubna wrote:
>>Now I can do what I need! Something that really could come in handy is a
>>ServletToolboxManaget.getInstance(InputStream).
> 
> ...
> 
> something along those lines might be easier.  i'm always happy to look over
> enhancement patches. :)

Reading the code better, there is no way to do it, since the private 
constructor needs a ServletContext, and the manager really needs this 
context.

> 
> Nathan Bubna
> nathan@esha.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 
> 
> 


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


Re: ToolboxManager.getToolboxContext(Object) not helping - continued

Posted by Nathan Bubna <na...@esha.com>.
Paulo Silveira said:
> I took a better look at the code, and there is no way to create a new
> method since the Object initdata is sent to the ToolInfos for tool
> instatiations.

yeah, i thought so.  i was just wondering if you might have seen something i
didn't.

> So now I am implementing ViewContext. I dindt see that ViewContext does
> not extends Context. The name got me confused.

yeah, "context" is a pretty generic term.  easy to get confused.

> Now I can do what I need! Something that really could come in handy is a
> ServletToolboxManaget.getInstance(InputStream).
...

something along those lines might be easier.  i'm always happy to look over
enhancement patches. :)

Nathan Bubna
nathan@esha.com


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


Re: ToolboxManager.getToolboxContext(Object) not helping - continued

Posted by Paulo Silveira <pa...@paulo.com.br>.
Hello

I took a better look at the code, and there is no way to create a new 
method since the Object initdata is sent to the ToolInfos for tool 
instatiations.

So now I am implementing ViewContext. I dindt see that ViewContext does 
not extends Context. The name got me confused.

Now I can do what I need! Something that really could come in handy is a 
ServletToolboxManaget.getInstance(InputStream).

thanks for your help.

Paulo





Paulo Silveira wrote:

> Helo Nathan!
> 
>> hmm.  most of the standard tools we provide expect to receive a 
>> ViewContext
>> during initialization.  if we added the method you suggest, i'm not 
>> sure how
>> it would work.  can you provide a patch for this?  it would make it 
>> easier to
>> assess.
> 
> I will send a patch later night.
> 
>>
>> also, why don't you want to use the ViewContext interface?  i'm curious.
> 
> Imagine the following situation: I will not use a ChainContext because I 
> dont wanna extend it. Then I have a MyViewContext, which will first see 
> inside a Map of toolboxes, and then look in the local Map for the values.
> 
> The sequence would be:
> - Create MyViewContext
> - Get a toolbox from the ServletToolboxManager, passing this as 
> argument, suposing we will call it from the MyviewContext
> - use a MyViewContext.setToolbox(Map) or 
> MyViewContext.setToolbox(ToolboxContext)
> - and then our get will do the job, taking a look first at the toolbox.
> 
> It simply seems too much. It could be done as this:
> - Create a toolbox through a new method 
> ServletToolboxManager.getToolboxContext(ServletRequest, ServletContext,...)
> - Create a MyContext with a toolbox as one of the parameters, and there 
> will be no need to implement ViewContext.
> 
> what do you think?
> 
>> Nathan Bubna
>> nathan@esha.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 
> 
> 


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


Re: ToolboxManager.getToolboxContext(Object) not helping

Posted by Paulo Silveira <pa...@paulo.com.br>.
Helo Nathan!
> hmm.  most of the standard tools we provide expect to receive a ViewContext
> during initialization.  if we added the method you suggest, i'm not sure how
> it would work.  can you provide a patch for this?  it would make it easier to
> assess.
I will send a patch later night.

> 
> also, why don't you want to use the ViewContext interface?  i'm curious.
Imagine the following situation: I will not use a ChainContext because I 
dont wanna extend it. Then I have a MyViewContext, which will first see 
inside a Map of toolboxes, and then look in the local Map for the values.

The sequence would be:
- Create MyViewContext
- Get a toolbox from the ServletToolboxManager, passing this as 
argument, suposing we will call it from the MyviewContext
- use a MyViewContext.setToolbox(Map) or 
MyViewContext.setToolbox(ToolboxContext)
- and then our get will do the job, taking a look first at the toolbox.

It simply seems too much. It could be done as this:
- Create a toolbox through a new method 
ServletToolboxManager.getToolboxContext(ServletRequest, ServletContext,...)
- Create a MyContext with a toolbox as one of the parameters, and there 
will be no need to implement ViewContext.

what do you think?

> Nathan Bubna
> nathan@esha.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 
> 
> 


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


Re: ToolboxManager.getToolboxContext(Object) not helping

Posted by Nathan Bubna <na...@esha.com>.
Paulo Silveira said:
> I am having truble trying to use the utility classes for the toolbox use.
>
> I dont wanna use VelocityViewServlet, neither Chained/ViewContext, but
> ServletToolboxManager has a cast in getToolboxContext(Object param),
> casting param to ViewContext.
>
> I do sugest an extra method, getToolboxContext(ServletContext,
> ServletRequest,...), giving the users an option.

hmm.  most of the standard tools we provide expect to receive a ViewContext
during initialization.  if we added the method you suggest, i'm not sure how
it would work.  can you provide a patch for this?  it would make it easier to
assess.

also, why don't you want to use the ViewContext interface?  i'm curious.

> And there are _many_ other places where this kind of restrictions apply.
> Extra methods (not overriden ones) could help.

i'd be happy to consider any enhancement requests.  and if you can provide
patches for them, that would particularly help.

> Thanks for the great job. By the way, what is the meaning for a
> getVelocityContext() in ViewContext?

i didn't put it there, but my understanding is that it is to allow alternate
implementations of ViewContext which provide access to a VelocityContext but
are not an instance of VelocityContext themselves (as ChainedContext is).

Nathan Bubna
nathan@esha.com


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


ToolboxManager.getToolboxContext(Object) not helping

Posted by Paulo Silveira <pa...@paulo.com.br>.
Hi!

I am having truble trying to use the utility classes for the toolbox use.

I dont wanna use VelocityViewServlet, neither Chained/ViewContext, but 
ServletToolboxManager has a cast in getToolboxContext(Object param), 
casting param to ViewContext.

I do sugest an extra method, getToolboxContext(ServletContext, 
ServletRequest,...), giving the users an option.

And there are _many_ other places where this kind of restrictions apply. 
Extra methods (not overriden ones) could help.

Thanks for the great job. By the way, what is the meaning for a 
getVelocityContext() in ViewContext?

Paulo


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


Re: VelocityToolbox - ToolboxContext

Posted by Nathan Bubna <na...@esha.com>.
Jaap van der Molen said:
> I have the following problem with the ToolboxContext: the class extends
> VelocityContext, yet doesn't implement any of the methods in the class
> hierarchy.

not quite true, but close enough.

> The collection of ToolInfo objects is stored in a private Map on the
> ToolboxContext,
> meaning the super-class methods like getKeys(), etc. do not return a
> correct result.

no.  the ToolInfo instances are stored in the ToolboxManager as either a group
of Maps (ServletToolboxManager) or single Map (default in XMLToolboxManager).
the ToolboxManager creates a ToolboxContext from a separate Map of actual tool
instances.

> Similar for ChainedContext.  If I create a ChainedContext using an existing
> VelocityContext, the getKeys() method returns 0 (zero), while the
> VelocityContext does contain elements.

the ChainedContext ctor feeds the Context you gave it to super(null, ctx)
(i.e. VelocityContext(Map, Context) ).  VelocityContext.getKeys() will not
check the specified context for keys.  it only checks the Map.  i don't know
why that is.

> Is there a specific reason for this? Or should I go for a bug report?
>
> Background: I am trying to get the tools available in the vm's of an
> existing web
> application (Roller - http://www.rollerweblogger.org). I have to work with
an
> existing VelocityContext object that I can't simply replace by a
> ChainedContext.

hmm.  well, i'd be happy to help you figure out a way to do this.  frankly,
i've never quite understood the purpose of ToolboxContext or it's design.  it
always seemed like a pointless exercise, but since it hasn't actually caused a
problem yet, i haven't bothered to mess with it.

i've also had hesitations about the current, lone ChainedContext constructor
(and a few other parts of its implementation).  i've been meaning to take a
look at improving these things at some point.  so, while i won't have much
free development time in the next 2-3 weeks, i'd be happy to at least start
discussing ways we could improve this and hopefully make it work for you.

Nathan Bubna
nathan@esha.com


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