In the context of the new VelocityViewServlet (jakarta-velocity-tool)
we have defined interface ContextTool to be implemented by context
tools (optionally). Context tools that implement this interface can be
handled more efficiently by a tool manager.
I'd like to propose the addition of two new methods to ContextTool
that will further improve the handling of context tools.
public static void setLogger(ContextToolLogger logger);
public static boolean isStatic()
See description below for details. setLogger() allows a tool
manager to pass a logger instance to a class of context tools.
isStatic() allows a tool manager to optimize the handling of
a tool class if its methods and fields are all static.
Your feedback is welcome. If nobody disagrees I will go ahead and
implement.
Gabe
<ContextTool.java>
------------------------------------------------------------------------
package org.apache.velocity.tools.view.tools;
import org.apache.velocity.tools.view.context.ViewContext;
/**
* ContextTool defines a set of methods that allows a context tool
* manager to efficiently handle context tools.
*/
public interface ContextTool
{
/**
* Returns an instance of the context tool. Some tools may simply return
* themselves from this method others may instantiate new objects
* to hold the per-request state.
*/
public Object init(ViewContext context);
/**
* Allows a tool manager to pass a logger to the context tool.
* If a logger is set, it will be used for all instances of
* this class. If no logger is set, no logging will occur.
*
* @param logger A logger.
*/
public static void setLogger(ContextToolLogger logger);
/**
* Allows a tool manager to check if a tool is all static or
* not. If a tool is not all static, a new instance *must* be
* created for every template that is processed. If a tool is
* all static the tool manager *may* optimize the tool handling
* by working with a single instance for the entire runtime.
*
*/
public static boolean isStatic()
}
------------------------------------------------------------------------
<ContextToolLogger.java>
------------------------------------------------------------------------
package org.apache.velocity.tools.view.tools;
import org.apache.velocity.tools.view.context.ViewContext;
/**
* ContextToolLogger defines an interface for loggers that
* are passed to context tools.
*/
public interface ContextToolLogger
{
// Log levels
public static int INFO;
public static int WARN;
public static int ERROR;
/**
* Writes a message to the log with the given log level. It is
* up to the actual implementation of this interface to decide
* what to do with the log level. It may simply ignore it or it
* may map it to a log level of the underlying log system if it
* support the concept of log levels. The supported
* log levels are {@link #INFO}, {@link #WARN} and
* {@link #ERROR}.
*/
public void log(int level, String msg);
}
------------------------------------------------------------------------
--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>