Nathan said:
> and find different way to satisfy both my
> desire for a flexible DateTool and Gabe's fears about thread-safety when
> DateTool is used as application scope. thinking....
ok, here's my suggestion (supporting arguments below it):
public class DateTool implements ViewContextTool
{
//this is used in all methods where a locale is
//not specified as a parameter
private Locale locale;
public DateTool()
{
locale = Locale.getDefault();
}
public void init(ViewContext ctx)
{
//search for a locale within the velocity context,
//request, session and servlet context
//in similar fashion to Daniel's MultiViewsTool
locale = the first one we find in the search pattern
}
... (all other methods go here of course)
}
Now, yes i know this is not completely threadsafe if used as application
scope. However, a template designer would have to go to all the trouble of
getting a ViewContext object in a template and passing it to the init
method. I'm gonna go out on a proverbial limb here and suggest that that
cannot possibly happen by accident!!! If Gabe really cannot trust template
designers not to do this maliciously or otherwise inappropriately on
purpose, then i suggest he use the following class as his date formatter.
public ThreadsafeDateTool extends DateTool
{
public ThreadsafeDateTool ()
{
super();
}
public void init(ViewContext ctx)
{
throws new UnsupportedOperationException("Bad designer! You can't do
that!");
}
}
Did i miss anything? Any reasonable objections?
Nathan Bubna
[EMAIL PROTECTED]
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>