velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Douglass" <r.dougl...@onlinehome.de>
Subject RE: clearing and setting Velocity properties
Date Sat, 30 Aug 2003 10:15:49 GMT
Here's how I've initially solved the problem. I reinstantiated
RuntimeInstance in RuntimeSingleton every time a parameterized init method
is called. This works, but smells bad to me. First of all, a new object has
to be created and initialized each time(wasteful). Second of all, and most
worrysome to me, is it makes my code dependent on a modified Velocity. When
Velocity 1.4 or Velocity 2 comes along, I'm going to have to modify it too.
I'm still hoping someone has a better suggestion.

-RD

  public static void init(Properties p) throws Exception
    {
	ri = new RuntimeInstance();
      ri.init(p);
    }
  public static void init(String configurationFile)
        throws Exception
    {
	ri = new RuntimeInstance();
      ri.init( configurationFile );
    }

-----Original Message-----
From: Robert Douglass [mailto:r.douglass@onlinehome.de]
Sent: Saturday, August 30, 2003 9:32 AM
To: Velocity list
Subject: clearing and setting Velocity properties


Hello,
	I'm integrating Velocity into an existing app, and need help with the way
the Velocity object is initialized. I understand that it is a singleton, and
that calling init() repeatedly will have no effect. However, I was surprised
that the following code also doesn't work as one might think:

	org.apache.velocity.app.Velocity.Velocity.init();
		Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, "foo");
		Object o1 = Velocity.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH);
		Velocity.clearProperty(Velocity.FILE_RESOURCE_LOADER_PATH);
		Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, "bar");
		Object o2 = Velocity.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH);


o1 and o2 both end up being "." ... which is apparently the default value
from calling Velocity.init(). So, do I understand that there is no way to
set the properties after the first call to .init(...)? In my application, I
would like to set Velocity.FILE_RESOURCE_LOADER_PATH every time before I
call .merge. Is this possible, as Velocity is, or do I need to customize it?
If I need to customize it, has anybody made this change already, and what is
the best method to do so? My first thought would be to destroy Velocity
object and create it new each time. Thanks for your thoughts,

Robert Douglass


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


Mime
View raw message