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: TurbineResourceService.java,v 1.11 2002/08/15 08:16:24 henning Exp $
Author:
Jonas Maurus, Jon S. Stevens, Frank Y. Kim, Raphaël Luta, Jason van Zyl

Fields inherited from class org.apache.turbine.services.BaseService
configuration, 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.commons.configuration.Configuration getConfiguration()
          Wrapper around the configuration resources.
 org.apache.commons.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.
 void init()
          Load all configured components and initialize them.
 void init(java.lang.Object data)
          Performs early initialization.
 void init(javax.servlet.ServletConfig config)
          This method is called when the Service is initialized
protected  java.lang.String interpolate(java.lang.String base)
           
static void setProperties(java.util.Properties properties)
          Init the service with the given properties object.
static void setPropertiesFileName(java.lang.String propertiesFileName)
          Deprecated.  
 void setProperty(java.lang.String key, java.lang.String value)
          Set a property in with a key=value pair.
 
Methods inherited from class org.apache.turbine.services.TurbineBaseService
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, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Service
getName, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, setInitableBroker, shutdown
 

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()
          throws InitializationException
Load all configured components and initialize them. This is a zero parameter variant which queries the Turbine Servlet for its config.
Specified by:
init in interface Initable
Overrides:
init in class TurbineBaseService
Throws:
InitializationException - Something went wrong in the init stage

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
Throws:
InitializationException - Something went wrong when starting up.

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.

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)
Set a property in with a key=value pair.
Specified by:
setProperty in interface ResourceService
Parameters:
String - key
String - value

interpolate

protected java.lang.String interpolate(java.lang.String base)

getConfiguration

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

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 int.

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.commons.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 © 2000-2002 Apache Software Foundation. All Rights Reserved.