velosurf.web
Class VelosurfTool

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<java.lang.String,java.lang.Object>
          extended by velosurf.context.DBReference
              extended by velosurf.web.VelosurfTool
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.lang.Object>

public class VelosurfTool
extends DBReference

This class is a tool meant to be referenced in toolbox.xml

It can be used in any scope you want (application/session/request), depending on the behaviour you need for the refinement and ordering mechanisms (which will follow the same scope). The initialization itself is very fast once all static initialization has been done, so there is no performance bottleneck when using request scope.

Since version 1.0rc1, you can have several instances of VelosurfTool, each with a distinct configuration file. This can be useful to have one instance per schema, or one instance per database if dealing with several databases.

For this to work, you have to use the 1.3 version of velocity-tools (not yet released at the time I'm writing this, so you need to grab it from the Velocity subversion repository) and give each instance the pathname of its configuration file via the 'config' parameter in the toolbox.xml file, like this :


  <!-- first instance -->
  <tool>
    <key>db1</key>
    <scope>request</scope>
    <class>velosurf.tools.VelosurfTool</scope>
    <parameter name="config" value="WEB-INF/db1.xml" />
  </tool>

  <!-- second instance -->
  <tool>
    <key>db2</key>
    <scope>request</scope>
    <class>velosurf.tools.VelosurfTool</scope>
    <parameter name="config" value="WEB-INF/db2.xml" />
   </tool>

Author:
Claude Brisson
See Also:
Serialized Form

Field Summary
private  java.lang.String configFile
          path to the config file.
private static java.util.Map<java.lang.String,Database> dbMap
          database connections.
private static java.lang.String DEFAULT_CONFIG_FILE
          default database config file.
private static boolean fetchLocalizer
          do we need to try to fetch the localizer object?
private static java.lang.String OLD_DEFAULT_CONFIG_FILE
          old default database config file.
private static java.lang.String TOOLBOX_CONFIG_FILE_KEY
          key used in the toolbox (toolbox.xml) to set the name of the config file.
private static java.lang.String TOOLBOX_CONFIG_FILE_KEY2
          alternate key for the toolbox
private static java.lang.String WEBAPP_CONFIG_FILE_KEY
          key used in the deployment descriptor (web.xml) to set the name of the config file.
private static java.lang.String WEBAPP_CONFIG_FILE_KEY2
          alternate webapp key
 
Constructor Summary
VelosurfTool()
          build a new VelosurfTool.
 
Method Summary
 void configure(java.util.Map<java.lang.String,java.lang.String> map)
          configure.
(package private) static java.lang.String findConfigFile(javax.servlet.ServletContext ctx)
          Tries to find the configuration file.
private static Database getConnection(java.lang.String configFile)
          return the existing Database for the specified config file, or null if it isn't already open.
private static Database getConnection(java.lang.String configFile, javax.servlet.ServletContext servletContext)
          return the existing Database for the specified config file and servlet context, or null if an error occurs.
private static Database getDefaultConnection()
          return the existing Database for the default config file, or null if it does not already exist.
private static Database getDefaultConnection(javax.servlet.ServletContext servletContext)
          return the existing Database for the default config file and servlet context, or null if an error occurs.
static DBReference getDefaultInstance()
          return a db reference the existing Database for the default config file, or null if it does not already exist.
static DBReference getDefaultInstance(javax.servlet.ServletContext servletContext)
          return a db reference on the existing Database for the default config file or null if an error occurs.
static DBReference getDefaultInstance(javax.servlet.ServletContext servletContext, UserContext userContext)
          return a db reference on the existing Database for the default config file and servlet context, or null if an error occurs.
static DBReference getDefaultInstance(UserContext userContext)
          return a db reference the existing Database for the default config file, or null if it does not already exist.
static DBReference getInstance(java.lang.String configFile)
          return a db reference on the existing Database for the specified config file, or null if it isn't already open.
static DBReference getInstance(java.lang.String configFile, javax.servlet.ServletContext servletContext)
          return a db reference on the existing Database for the specified config file and servlet context, or null if an error occurs.
static DBReference getInstance(java.lang.String configFile, javax.servlet.ServletContext servletContext, UserContext userContext)
          return a db reference on the existing Database for the specified config file and servlet context, or null if an error occurs.
static DBReference getInstance(java.lang.String configFile, UserContext userContext)
          return a db reference on the existing Database for the specified config file, or null if it isn't already open.
 void init(java.lang.Object viewContext)
          Initialize this instance using the given ViewContext.
private  void initialize(javax.servlet.ServletContext ctx)
          initialization from a servlet context
 
Methods inherited from class velosurf.context.DBReference
deobfuscate, get, getSchema, init, obfuscate, put
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

WEBAPP_CONFIG_FILE_KEY

private static final java.lang.String WEBAPP_CONFIG_FILE_KEY
key used in the deployment descriptor (web.xml) to set the name of the config file.

See Also:
Constant Field Values

WEBAPP_CONFIG_FILE_KEY2

private static final java.lang.String WEBAPP_CONFIG_FILE_KEY2
alternate webapp key

See Also:
Constant Field Values

TOOLBOX_CONFIG_FILE_KEY

private static final java.lang.String TOOLBOX_CONFIG_FILE_KEY
key used in the toolbox (toolbox.xml) to set the name of the config file.

See Also:
Constant Field Values

TOOLBOX_CONFIG_FILE_KEY2

private static final java.lang.String TOOLBOX_CONFIG_FILE_KEY2
alternate key for the toolbox

See Also:
Constant Field Values

DEFAULT_CONFIG_FILE

private static final java.lang.String DEFAULT_CONFIG_FILE
default database config file.

See Also:
Constant Field Values

OLD_DEFAULT_CONFIG_FILE

private static final java.lang.String OLD_DEFAULT_CONFIG_FILE
old default database config file.

See Also:
Constant Field Values

configFile

private java.lang.String configFile
path to the config file.


dbMap

private static java.util.Map<java.lang.String,Database> dbMap
database connections.


fetchLocalizer

private static boolean fetchLocalizer
do we need to try to fetch the localizer object? True initially, false after one unsuccessful try.

Constructor Detail

VelosurfTool

public VelosurfTool()
build a new VelosurfTool.

Method Detail

init

public void init(java.lang.Object viewContext)
          throws java.lang.Exception
Initialize this instance using the given ViewContext.

Parameters:
viewContext - initialization data
Throws:
java.lang.Exception

findConfigFile

static java.lang.String findConfigFile(javax.servlet.ServletContext ctx)
Tries to find the configuration file.

Parameters:
ctx - servelt context
Returns:
found config file or null

initialize

private void initialize(javax.servlet.ServletContext ctx)
initialization from a servlet context


configure

public void configure(java.util.Map<java.lang.String,java.lang.String> map)
configure.

Parameters:
map - parameters

getConnection

private static Database getConnection(java.lang.String configFile)
return the existing Database for the specified config file, or null if it isn't already open.

Parameters:
configFile -
Returns:
a Database

getInstance

public static DBReference getInstance(java.lang.String configFile,
                                      UserContext userContext)
return a db reference on the existing Database for the specified config file, or null if it isn't already open.

Parameters:
configFile -
Returns:
a DBReference

getInstance

public static DBReference getInstance(java.lang.String configFile)
return a db reference on the existing Database for the specified config file, or null if it isn't already open.

Parameters:
configFile -
Returns:
a DBReference

getConnection

private static Database getConnection(java.lang.String configFile,
                                      javax.servlet.ServletContext servletContext)
return the existing Database for the specified config file and servlet context, or null if an error occurs.

Parameters:
configFile -
Returns:
a Database

getInstance

public static DBReference getInstance(java.lang.String configFile,
                                      javax.servlet.ServletContext servletContext,
                                      UserContext userContext)
return a db reference on the existing Database for the specified config file and servlet context, or null if an error occurs.

Parameters:
configFile -
Returns:
a DBReference

getInstance

public static DBReference getInstance(java.lang.String configFile,
                                      javax.servlet.ServletContext servletContext)
return a db reference on the existing Database for the specified config file and servlet context, or null if an error occurs.

Parameters:
configFile -
Returns:
a DBReference

getDefaultConnection

private static Database getDefaultConnection()
return the existing Database for the default config file, or null if it does not already exist.

Returns:
a Database

getDefaultInstance

public static DBReference getDefaultInstance(UserContext userContext)
return a db reference the existing Database for the default config file, or null if it does not already exist.

Returns:
a DBReference

getDefaultInstance

public static DBReference getDefaultInstance()
return a db reference the existing Database for the default config file, or null if it does not already exist.

Returns:
a DBReference

getDefaultConnection

private static Database getDefaultConnection(javax.servlet.ServletContext servletContext)
return the existing Database for the default config file and servlet context, or null if an error occurs.

Returns:
a Database

getDefaultInstance

public static DBReference getDefaultInstance(javax.servlet.ServletContext servletContext,
                                             UserContext userContext)
return a db reference on the existing Database for the default config file and servlet context, or null if an error occurs.

Returns:
a Database

getDefaultInstance

public static DBReference getDefaultInstance(javax.servlet.ServletContext servletContext)
return a db reference on the existing Database for the default config file or null if an error occurs.

Returns:
a Database


~ooOoo~