org.apache.turbine.services.resources
Class TurbineResourceService

java.lang.Object
  |
  +--org.apache.turbine.services.BaseInitable
        |
        +--org.apache.turbine.services.BaseService
              |
              +--org.apache.turbine.services.TurbineBaseService
                    |
                    +--org.apache.turbine.services.resources.TurbineResourceService
All Implemented Interfaces:
Initable, ResourceService, Service

public class TurbineResourceService
extends TurbineBaseService
implements ResourceService

This implementation of the resourcesService relies on an external properties file for storing the configuration keys and values.

In order to be compatible with legacy applications, this implementation kept a static method for initializing the service, so it's still possible to write the following code:

TurbineResourceService.setPropertiesName("d:/conf/Turbine.properties"); Vector myVar = TurbineResources.getVector("myvar");

The new way to do things is to look at the org.apache.turbine.util.TurbineConfig class.

Version:
$Id$
Author:
Jonas Maurus, Jon S. Stevens, Frank Y. Kim, Raphaël Luta, Jason van Zyl

Field Summary
private  org.apache.velocity.runtime.configuration.Configuration configuration
          The container for the generic resources.
 
Fields inherited from class org.apache.turbine.services.BaseService
name, properties, serviceBroker
 
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
 
Fields inherited from interface org.apache.turbine.services.resources.ResourceService
SERVICE_NAME
 
Constructor Summary
TurbineResourceService()
           
 
Method Summary
 boolean getBoolean(java.lang.String name)
          The purpose of this method is to get the configuration resource with the given name as a boolean value.
 boolean getBoolean(java.lang.String name, boolean def)
          The purppose of this method is to get the configuration resource with the given name as a boolean value, or a default value.
 org.apache.velocity.runtime.configuration.Configuration getConfiguration()
          Wrapper around the configuration resources.
 org.apache.velocity.runtime.configuration.Configuration getConfiguration(java.lang.String prefix)
          The purpose of this method is to extract a subset of configuraton resources sharing a common name prefix.
 double getDouble(java.lang.String name)
          The purpose of this method is to get the configuration resource with the given name as a double.
 double getDouble(java.lang.String name, double def)
          The purpose of this method is to get the configuration resource with the given name as a double, or a default value.
 float getFloat(java.lang.String name)
          The purpose of this method is to get the configuration resource with the given name as a float.
 float getFloat(java.lang.String name, float def)
          The purpose of this method is to get the configuration resource with the given name as a float, or a default value.
 int getInt(java.lang.String name)
          The purpose of this method is to get the configuration resource with the given name as an integer.
 int getInt(java.lang.String name, int def)
          The purpose of this method is to get the configuration resource with the given name as an integer, or a default value.
 java.util.Iterator getKeys()
          Get the list of the keys contained in the configuration repository.
 java.util.Iterator getKeys(java.lang.String prefix)
          Get the list of the keys contained in the configuration repository that match the specified prefix.
 long getLong(java.lang.String name)
          The purpose of this method is to get the configuration resource with the given name as a long.
 long getLong(java.lang.String name, long def)
          The purpose of this method is to get the configuration resource with the given name as a long, or a default value.
 ResourceService getResources(java.lang.String prefix)
          The purpose of this method is to extract a subset of configuraton resources sharing a common name prefix.
 java.lang.String getString(java.lang.String name)
          The purpose of this method is to get the configuration resource with the given name as a string.
 java.lang.String getString(java.lang.String name, java.lang.String def)
          The purpose of this method is to get the configuration resource with the given name as a string, or a default value.
 java.lang.String[] getStringArray(java.lang.String name)
          The purpose of this method is to get the configuration resource with the given name as a string array.
 java.util.Vector getVector(java.lang.String name)
          The purpose of this method is to get the configuration resource with the given name as a vector.
 java.util.Vector getVector(java.lang.String name, java.util.Vector def)
          The purpose of this method is to get the configuration resource with the given name as a vector, or a default value.
private  void init(org.apache.velocity.runtime.configuration.Configuration configuration)
          Initializer method that sets up the configuration resources.
 void init(java.lang.Object data)
          Performs early initialization.
private  void init(java.util.Properties props)
          The purpose of this method is to init the configuration resource with a Properties object sent from a different system.
 void init(javax.servlet.ServletConfig config)
          This method is called when the Service is initialized
static void setProperties(java.util.Properties properties)
          Init the service with the given properties object.
static void setPropertiesFileName(java.lang.String propertiesFileName)
          Deprecated.  
 
Methods inherited from class org.apache.turbine.services.TurbineBaseService
init, init, shutdown
 
Methods inherited from class org.apache.turbine.services.BaseService
getName, getProperties, getServiceBroker, setName, setServiceBroker
 
Methods inherited from class org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBroker
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Service
getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, setInitableBroker, shutdown
 

Field Detail

configuration

private org.apache.velocity.runtime.configuration.Configuration configuration
The container for the generic resources.
Constructor Detail

TurbineResourceService

public TurbineResourceService()
Method Detail

init

public void init(java.lang.Object data)
          throws InitializationException
Performs early initialization. Overrides init() method in BaseService to detect objects used in Turbine's Service initialization and pass them to apropriate init() methods.
Specified by:
init in interface Initable
Overrides:
init in class TurbineBaseService
Parameters:
data - An Object to use for initialization activities.
Throws:
InitializationException, - if initialization of this class was not successful.

init

public void init(javax.servlet.ServletConfig config)
          throws InitializationException
This method is called when the Service is initialized
Overrides:
init in class TurbineBaseService
Parameters:
config - a ServletConfig object

setPropertiesFileName

public static void setPropertiesFileName(java.lang.String propertiesFileName)
                                  throws TurbineException
Deprecated.  

Init the service with the given properties filename
Parameters:
propertiesFileName - The file name.
Throws:
IOException, - if there was an I/O problem.

setProperties

public static void setProperties(java.util.Properties properties)
                          throws TurbineException
Init the service with the given properties object. Called from Cocoon to initialize Turbine.
Parameters:
properties - The java.util.Properties object sent from another process such as Cocoon. This Properties object contains all of the necessary properties found in the TurbineResources.properties file.
Throws:
TurbineException, - if there was an I/O problem.

getConfiguration

public org.apache.velocity.runtime.configuration.Configuration getConfiguration()
Wrapper around the configuration resources.
Specified by:
getConfiguration in interface Service
Overrides:
getConfiguration in class BaseService
Returns:
A Configuration.

init

private void init(org.apache.velocity.runtime.configuration.Configuration configuration)
Initializer method that sets up the configuration resources.
Parameters:
confs - A Configurations object.

init

private void init(java.util.Properties props)
The purpose of this method is to init the configuration resource with a Properties object sent from a different system. For example, a Properties sent over from Cocoon. The reason for this code is to provide a bridge between an org.apache.turbine.util.Configurations class and an org.apache.cocoon.framework.Configurations class.
Parameters:
props - A Properties object.

getBoolean

public boolean getBoolean(java.lang.String name)
The purpose of this method is to get the configuration resource with the given name as a boolean value.
Specified by:
getBoolean in interface ResourceService
Parameters:
name - The resource name.
Returns:
The value of the named resource as a boolean.

getBoolean

public boolean getBoolean(java.lang.String name,
                          boolean def)
The purppose of this method is to get the configuration resource with the given name as a boolean value, or a default value.
Specified by:
getBoolean in interface ResourceService
Parameters:
name - The resource name.
def - The default value of the resource.
Returns:
The value of the named resource as a boolean.

getDouble

public double getDouble(java.lang.String name)
The purpose of this method is to get the configuration resource with the given name as a double.
Specified by:
getDouble in interface ResourceService
Parameters:
name - The resoource name.
Returns:
The value of the named resource as double.

getDouble

public double getDouble(java.lang.String name,
                        double def)
The purpose of this method is to get the configuration resource with the given name as a double, or a default value.
Specified by:
getDouble in interface ResourceService
Parameters:
name - The resource name.
def - The default value of the resource.
Returns:
The value of the named resource as a double.

getFloat

public float getFloat(java.lang.String name)
The purpose of this method is to get the configuration resource with the given name as a float.
Specified by:
getFloat in interface ResourceService
Parameters:
name - The resource name.
Returns:
The value of the resource as a float.

getFloat

public float getFloat(java.lang.String name,
                      float def)
The purpose of this method is to get the configuration resource with the given name as a float, or a default value.
Specified by:
getFloat in interface ResourceService
Parameters:
name - The resource name.
def - The default value of the resource.
Returns:
The value of the resource as a float.

getInt

public int getInt(java.lang.String name)
The purpose of this method is to get the configuration resource with the given name as an integer.
Specified by:
getInt in interface ResourceService
Parameters:
name - The resource name.
Returns:
The value of the resource as an integer.

getInt

public int getInt(java.lang.String name,
                  int def)
The purpose of this method is to get the configuration resource with the given name as an integer, or a default value.
Specified by:
getInt in interface ResourceService
Parameters:
name - The resource name.
def - The default value of the resource.
Returns:
The value of the resource as an integer.

getKeys

public java.util.Iterator getKeys()
Get the list of the keys contained in the configuration repository.
Specified by:
getKeys in interface ResourceService
Returns:
An Enumeration with all the keys.

getKeys

public java.util.Iterator getKeys(java.lang.String prefix)
Get the list of the keys contained in the configuration repository that match the specified prefix.
Specified by:
getKeys in interface ResourceService
Parameters:
prefix - A String prefix to test against.
Returns:
An Enumeration of keys that match the prefix.

getLong

public long getLong(java.lang.String name)
The purpose of this method is to get the configuration resource with the given name as a long.
Specified by:
getLong in interface ResourceService
Parameters:
name - The resource name.
Returns:
The value of the resource as a long.

getLong

public long getLong(java.lang.String name,
                    long def)
The purpose of this method is to get the configuration resource with the given name as a long, or a default value.
Specified by:
getLong in interface ResourceService
Parameters:
name - The resource name.
def - The default value of the resource.
Returns:
The value of the resource as a long.

getString

public java.lang.String getString(java.lang.String name)
The purpose of this method is to get the configuration resource with the given name as a string.
Specified by:
getString in interface ResourceService
Parameters:
name - The resource name.
Returns:
The value of the resource as a string.

getString

public java.lang.String getString(java.lang.String name,
                                  java.lang.String def)
The purpose of this method is to get the configuration resource with the given name as a string, or a default value.
Specified by:
getString in interface ResourceService
Parameters:
name - The resource name.
def - The default value of the resource.
Returns:
The value of the resource as a string.

getStringArray

public java.lang.String[] getStringArray(java.lang.String name)
The purpose of this method is to get the configuration resource with the given name as a string array.
Specified by:
getStringArray in interface ResourceService
Parameters:
name - The resource name.
Returns:
The value of the resource as a string array.

getVector

public java.util.Vector getVector(java.lang.String name)
The purpose of this method is to get the configuration resource with the given name as a vector.
Specified by:
getVector in interface ResourceService
Parameters:
name - The resource name.
Returns:
The value of the resource as a vector.

getVector

public java.util.Vector getVector(java.lang.String name,
                                  java.util.Vector def)
The purpose of this method is to get the configuration resource with the given name as a vector, or a default value.
Specified by:
getVector in interface ResourceService
Parameters:
name - The resource name.
def - The default value of the resource.
Returns:
The value of the resource as a vector.

getResources

public ResourceService getResources(java.lang.String prefix)
The purpose of this method is to extract a subset of configuraton resources sharing a common name prefix. The prefix is stripped from the names of the resulting resources.
Specified by:
getResources in interface ResourceService
Parameters:
prefix - the common name prefix
Returns:
A ResourceService providing the subset of configuration.

getConfiguration

public org.apache.velocity.runtime.configuration.Configuration getConfiguration(java.lang.String prefix)
The purpose of this method is to extract a subset of configuraton resources sharing a common name prefix. The prefix is stripped from the names of the resulting resources.
Specified by:
getConfiguration in interface ResourceService
Parameters:
prefix - the common name prefix
Returns:
A Configuration providing the subset of configuration.


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.