You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Chris Brown <br...@reflexe.fr> on 2003/07/04 18:15:22 UTC

Accessing custom resource loaders without static methods/singleton

Hello (again),

I've seen that you can configure resource loaders using the following
approach:

resource.loader=ldr1,ldr2
ldr1.loader.description=My Loader
ldr1.resource.loader.class=com....

...using the setProperty methods.  This obviously performs Class.forName()
(or similar) to create an instance.

I'd like to pass an existing instance instead, or at least retrieve the
instance of my loader to perform extra initialisation.  Our resource loader
will need to access a particular object instance, and as we've got several
instances of VelocityEngine, it'd be preferable not to turn to singletons or
static methods, so I'd like to access the loader and pass it some extra
object references (passing objects into the loader so that can access the
correct business objects from where the templates can be loaded).

Is there anyway to either:

1./ supply instances of ResourceLoaders (instead of class names)

- and/or -

2./ recover instances of ResourceLoader instantiated by the VelocityEngine ?

Thanks,
Chris Brown



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


FreeMarker, Velocity, Jonathon, me :)

Posted by Dave Newton <da...@solaraccess.com>.
Hey Nathan--

Well, I'm back from vacation like three weeks later and he's still an
ass. Throw some Velocity work at me; I'll implement whatever needs to be
implemented to shut up anybody that likes FreeMarker more than Velocity.

I don't have a job now (economic downturn, don'tcha know) so I might as
well contribute and piss off Jon some more at the same time. 

So seriously, I want to contribute, but anonymously, so tell me where to
look and what to do and I'm on it.

Dave



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


Re: Accessing custom resource loaders without static methods/singleton

Posted by Nathan Bubna <na...@esha.com>.
Chris Brown
...
> I've seen that you can configure resource loaders using the following
> approach:
>
> resource.loader=ldr1,ldr2
> ldr1.loader.description=My Loader
> ldr1.resource.loader.class=com....
>
> ...using the setProperty methods.  This obviously performs Class.forName()
> (or similar) to create an instance.
>
> I'd like to pass an existing instance instead, or at least retrieve the
> instance of my loader to perform extra initialisation.  Our resource loader
> will need to access a particular object instance, and as we've got several
> instances of VelocityEngine, it'd be preferable not to turn to singletons or
> static methods, so I'd like to access the loader and pass it some extra
> object references (passing objects into the loader so that can access the
> correct business objects from where the templates can be loaded).

you ought to look at the source of the VelocityViewServlet and the
WebappLoader in the velocity-tools project.

http://cvs.apache.org/viewcvs/jakarta-velocity-tools/src/java/org/apache/veloc
ity/tools/view/servlet/

there we make use of Velocity's application attributes to make the
ServletContext available to the WebappLoader.

i don't know offhand if you're suggested approaches are feasible, but this
works quite well for us.

Nathan Bubna
nathan@esha.com


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