You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by sato tadayosi <sa...@mogra.net> on 2005/01/04 07:22:04 UTC

how to inherit ServletToolboxManager?

Hello everyone,

I'm using VelocityView and am very happy it's much easier creating
dynamic HTML than JSP and custom tags.

Now I need to use some my own implementation of ServletToolboxRuleSet
(which is in "org.apache.velocity.tools.view.servlet" package),
so I tried to extend ServletToolboxManager to overrride "getRuleSet()"
method in it. But I couldn't because ServletToolboxManager is singleton
and its only constructor is private.

ServletToolboxManager source (VelocityTools 1.1) is like this:
===
public class ServletToolboxManger extends XMLToolboxManager {
  ...
  private ServletToolboxManager(ServletContext servletContext) {
    ...
  }
  ...
  public static synchronized ServletToolboxManager getInstance(
    ServletContext servlet,
    String toolboxFile) {
    ...
  }
  ...
  protected RuleSet getRuleSet() { ... }
}
===

and I made subclass like this (it's bad solution. it fails to compile...):
===
public class MyServletToolboxManger extends ServletToolboxManager {
  public static synchronized ServletToolboxManger getInstance(
    ServletContext servlet,
    String toolboxFile) {
    ...
  }
  protected RuleSet getRuleSet() { /* return my own RuleSet */ }
}
===


If any good idea to extend ServletToolboxManager, please could you
tell me?

Thank you.

Sato

(*
 *  SATO TADAYOSI <sa...@mogra.net>
 *)

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


Re: how to inherit ServletToolboxManager?

Posted by sato tadayosi <sa...@mogra.net>.
Hi Nathan,

Thank you. I'm looking forward to your work.

Sato

> i actually have some stuff like this in the works.  if we're lucky and
> i get some paid-time to work on VelocityTools in the next few weeks,
> you might see some fairly radical changes begin to arrive.  i've been
> long, slowly working on some heavy changes (probably worthy of a 2.x
> branch), and with a product launch imminent, i may be able to take
> some work time to further that effort. :)
> 
> nathan

(*
  *  SATO TADAYOSI <sa...@mogra.net>
  *)

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


Re: how to inherit ServletToolboxManager?

Posted by Nathan Bubna <nb...@gmail.com>.
On Wed, 5 Jan 2005 21:33:45 +0900, Shinobu Kawai
<sh...@gmail.com> wrote:
> Hi Sato,
> 
> > I'm using VelocityView and am very happy it's much easier creating
> > dynamic HTML than JSP and custom tags.
> 
> Agreed.  :)
> 
> > Now I need to use some my own implementation of ServletToolboxRuleSet
> > (which is in "org.apache.velocity.tools.view.servlet" package),
> > so I tried to extend ServletToolboxManager to overrride "getRuleSet()"
> > method in it. But I couldn't because ServletToolboxManager is singleton
> > and its only constructor is private.
> 
...
> > If any good idea to extend ServletToolboxManager, please could you
> > tell me?
> 
> Hacking VelocityViewServlet#initToolbox()?  Actually, I think it might
> be nice if you could configure the RuleSet via init-param.
...

i actually have some stuff like this in the works.  if we're lucky and
i get some paid-time to work on VelocityTools in the next few weeks,
you might see some fairly radical changes begin to arrive.  i've been
long, slowly working on some heavy changes (probably worthy of a 2.x
branch), and with a product launch imminent, i may be able to take
some work time to further that effort. :)

nathan

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


Re: how to inherit ServletToolboxManager?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Sato,

> Thank you for your advice!

No sweat.  :)

> So far, I chose a solution to just copy the ServletToolboxManager source
> and customize it to make my own ServletToolboxManager extention. But I think
> it's not good solution... Now I'm looking for a better way.
> 
> > Hacking VelocityViewServlet#initToolbox()?  Actually, I think it might
> > be nice if you could configure the RuleSet via init-param.
> 
> Yes, I hacked initToolbox(). And I don't think it might be solution
> to configure the RuleSet via init-param. (I'm not good skilled, so
> this might be wrong)
> 
> The real story is: my aim is to hack the mechanism of instance
> creation of ViewTools and attach some additional function (such as
> dependency injection) at the instance creation time. So I found
> that I need to prepare replacements for all classes of
> VelocityViewServlet, ServletToolboxManager, ServletToolboxRuleSet
> and ServletToolInfo in my library.
> 
> I would really appreciate if you would give me another comment.
> Thank you very much.

I was wondering if you can use the o.a.v.t.view.tools.Configurable
interface.  Don't know how to use it (yet), but it /might/ be of help.
    http://svn.apache.org/viewcvs.cgi/jakarta/velocity-tools/trunk/src/java/org/apache/velocity/tools/view/tools/Configurable.java?rev=72058&view=auto

Best regards,
-- Shinobu

--
Shinobu "Kawai" Yoshida <sh...@gmail.com>

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


Re: how to inherit ServletToolboxManager?

Posted by sato tadayosi <sa...@mogra.net>.
Hi Kawai san,

Thank you for your advice!

 >>Now I need to use some my own implementation of ServletToolboxRuleSet
 >>(which is in "org.apache.velocity.tools.view.servlet" package),
 >>so I tried to extend ServletToolboxManager to overrride "getRuleSet()"
 >>method in it. But I couldn't because ServletToolboxManager is singleton
 >>and its only constructor is private.
 >
 >
 > It is so easy to change the constructor protected.  ;)

Yes, actually I can by modifying the original ServletToolboxManager
source code because source is open, and then I can successfully subclass it.
But now I intend to let the original code unmodified, because I want
to let my library be used as an extension of Velocity View.
Primary reasons are:
  - I don't want to release my version of Velocity View
  - to reuse the original impl. as much as possible in order to
      easily follow the upgrades.

So far, I chose a solution to just copy the ServletToolboxManager source
and customize it to make my own ServletToolboxManager extention. But I think
it's not good solution... Now I'm looking for a better way.

> Hacking VelocityViewServlet#initToolbox()?  Actually, I think it might
> be nice if you could configure the RuleSet via init-param.

Yes, I hacked initToolbox(). And I don't think it might be solution
to configure the RuleSet via init-param. (I'm not good skilled, so
this might be wrong)

The real story is: my aim is to hack the mechanism of instance
creation of ViewTools and attach some additional function (such as
dependency injection) at the instance creation time. So I found
that I need to prepare replacements for all classes of
VelocityViewServlet, ServletToolboxManager, ServletToolboxRuleSet
and ServletToolInfo in my library.

I would really appreciate if you would give me another comment.
Thank you very much.

Sato


(*
  *  SATO TADAYOSI <sa...@mogra.net>
  *)

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


Re: how to inherit ServletToolboxManager?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Sato,

> I'm using VelocityView and am very happy it's much easier creating
> dynamic HTML than JSP and custom tags.

Agreed.  :)

> Now I need to use some my own implementation of ServletToolboxRuleSet
> (which is in "org.apache.velocity.tools.view.servlet" package),
> so I tried to extend ServletToolboxManager to overrride "getRuleSet()"
> method in it. But I couldn't because ServletToolboxManager is singleton
> and its only constructor is private.

It is so easy to change the constructor protected.  ;)

> ServletToolboxManager source (VelocityTools 1.1) is like this:
> ===

## snip

> and I made subclass like this (it's bad solution. it fails to compile...):
> ===
> public class MyServletToolboxManger extends ServletToolboxManager {
>  public static synchronized ServletToolboxManger getInstance(
>    ServletContext servlet,
>    String toolboxFile) {
>    ...
>  }
>  protected RuleSet getRuleSet() { /* return my own RuleSet */ }
> }
> ===
> 
> If any good idea to extend ServletToolboxManager, please could you
> tell me?

Hacking VelocityViewServlet#initToolbox()?  Actually, I think it might
be nice if you could configure the RuleSet via init-param.

Best regards,
-- Shinobu

--
Shinobu "Kawai" Yoshida <sh...@gmail.com>

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