org.apache.turbine.services
Class TurbineServices

java.lang.Object
  |
  +--org.apache.turbine.services.BaseInitableBroker
        |
        +--org.apache.turbine.services.BaseServiceBroker
              |
              +--org.apache.turbine.services.TurbineServices
All Implemented Interfaces:
InitableBroker, ServiceBroker

public class TurbineServices
extends BaseServiceBroker

This is a singleton utility class that acts as a Services broker.

Version:
$Id: TurbineServices.java,v 1.9 2002/07/27 12:36:12 henning Exp $
Author:
Greg Ritter, Brett McLaughlin, Kevin Burton, Rafal Krzewski, Jon S. Stevens, Henning P. Schmiedehausen

Field Summary
static java.lang.String CLASSNAME_SUFFIX
          A Service property determining its implementing class name .
static java.lang.String COMPONENT_CLASS_DEFAULT
          Default component service implementation
static java.lang.String COMPONENT_CLASS_KEY
          Servlet initialization parameter name for defining the component loader service implementation to load Stratum based components.
protected static ServiceBroker instance
          The single instance of this class.
static java.lang.String LOGGING_CLASS_DEFAULT
          Default bootstrap logger implementation
static java.lang.String LOGGING_CLASS_KEY
          Servlet initialization parameter name for defining the logging service implementation to use.
static java.lang.String PROPERTIES_PATH_DEFAULT
          Default value of TurbineResources.properties file path (/WEB-INF/conf/TurbineResources.properties).
static java.lang.String PROPERTIES_PATH_KEY
          Servlet initialization parameter name for the path to TurbineResources.properties file used by TurbineResourceService (properties).
static java.lang.String RESOURCES_CLASS_DEFAULT
          Default resources service implementation to use when none explicitly specified ( org.apache.turbine.services.resources.TurbineResourceService)
static java.lang.String RESOURCES_CLASS_KEY
          Servlet initialization parameter name for defining the resources service implementation to use (resources).
static java.lang.String SERVICE_PREFIX
          A prefix for Service properties in TurbineResource.properties.
 
Fields inherited from class org.apache.turbine.services.BaseServiceBroker
mapping, services
 
Fields inherited from class org.apache.turbine.services.BaseInitableBroker
initables, stack
 
Constructor Summary
protected TurbineServices()
          This constructor is protected to force clients to use getInstance() to access this class.
 
Method Summary
 void error(java.lang.Throwable t)
          Output an error message.
 org.apache.commons.configuration.Configuration getConfiguration(java.lang.String name)
          Returns the Configuration for the specified service.
static ServiceBroker getInstance()
          The method through which this class is accessed.
 java.util.Properties getProperties(java.lang.String name)
          Returns the properites of a specific service.
 ResourceService getResources(java.lang.String name)
          Returns the configuration resources of a specific service.
protected  void initMapping()
          Creates a mapping between Service names and class names.
 void initMapping(org.apache.commons.configuration.Configuration mapping)
          Creates mapping of Service names to class names.
 void initPrimaryServices(javax.servlet.ServletConfig config)
          Initialize the primary services (Logging and Resources).
 void notice(java.lang.String msg)
          Output a diagnostic notice.
 
Methods inherited from class org.apache.turbine.services.BaseServiceBroker
getService, getServiceInstance, initService, initServices, initServices, isRegistered, shutdownService, shutdownServices
 
Methods inherited from class org.apache.turbine.services.BaseInitableBroker
getInitable, getInitableInstance, initClass, shutdownClass
 
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.InitableBroker
getInitable, initClass, shutdownClass
 

Field Detail

RESOURCES_CLASS_KEY

public static final java.lang.String RESOURCES_CLASS_KEY
Servlet initialization parameter name for defining the resources service implementation to use (resources).

RESOURCES_CLASS_DEFAULT

public static final java.lang.String RESOURCES_CLASS_DEFAULT
Default resources service implementation to use when none explicitly specified ( org.apache.turbine.services.resources.TurbineResourceService)

LOGGING_CLASS_KEY

public static final java.lang.String LOGGING_CLASS_KEY
Servlet initialization parameter name for defining the logging service implementation to use.

LOGGING_CLASS_DEFAULT

public static final java.lang.String LOGGING_CLASS_DEFAULT
Default bootstrap logger implementation

COMPONENT_CLASS_KEY

public static final java.lang.String COMPONENT_CLASS_KEY
Servlet initialization parameter name for defining the component loader service implementation to load Stratum based components.

COMPONENT_CLASS_DEFAULT

public static final java.lang.String COMPONENT_CLASS_DEFAULT
Default component service implementation

PROPERTIES_PATH_KEY

public static final java.lang.String PROPERTIES_PATH_KEY
Servlet initialization parameter name for the path to TurbineResources.properties file used by TurbineResourceService (properties).

PROPERTIES_PATH_DEFAULT

public static final java.lang.String PROPERTIES_PATH_DEFAULT
Default value of TurbineResources.properties file path (/WEB-INF/conf/TurbineResources.properties).

SERVICE_PREFIX

public static final java.lang.String SERVICE_PREFIX
A prefix for Service properties in TurbineResource.properties.

CLASSNAME_SUFFIX

public static final java.lang.String CLASSNAME_SUFFIX
A Service property determining its implementing class name .

instance

protected static ServiceBroker instance
The single instance of this class.
Constructor Detail

TurbineServices

protected TurbineServices()
This constructor is protected to force clients to use getInstance() to access this class.
Method Detail

getInstance

public static ServiceBroker getInstance()
The method through which this class is accessed.
Returns:
The single instance of this class.

initPrimaryServices

public void initPrimaryServices(javax.servlet.ServletConfig config)
                         throws InstantiationException,
                                InitializationException
Initialize the primary services (Logging and Resources).

initMapping

public void initMapping(org.apache.commons.configuration.Configuration mapping)
Creates mapping of Service names to class names. BaseServiceBroker knows no mappings.

initMapping

protected void initMapping()
Creates a mapping between Service names and class names. The mapping is built according to settings present in TurbineResources.properties. The entries should have the following form:
 services.MyService.classname=com.mycompany.MyServiceImpl
 services.MyOtherService.classname=com.mycompany.MyOtherServiceImpl
 

Generic ServiceBroker provides no Services.

getProperties

public java.util.Properties getProperties(java.lang.String name)
Returns the properites of a specific service. Properties are retrieved from TurbineResources.properties provided that you have the following entries:
services.MyService.greeting=Hello\, I'm Jan B.
services.MyService.defaultAction=beep
Service "MyService" will get a set of two properites: "greeting" = "Hello, I'm Jan B." and "defaultAction" = "beep".

Note that this way you will receive a 'collapsed' version of your resources - multiple entries with the same key will have only one value stored. Use the getConfiguration(java.lang.String) or getResources(java.lang.String) method to take advantage of the capabilities of the TurbineResources class.

Overrides:
getProperties in class BaseServiceBroker
Parameters:
name - The name of the service.
Returns:
Properties of requested Service.

getConfiguration

public org.apache.commons.configuration.Configuration getConfiguration(java.lang.String name)
Returns the Configuration for the specified service.
Overrides:
getConfiguration in class BaseServiceBroker
Parameters:
name - The name of the service.

getResources

public ResourceService getResources(java.lang.String name)
Returns the configuration resources of a specific service. This method extracts the configuration options of a service from global Turbine configuration. The interface ResourceService offers significant advantages over plain java.util.Properties - you can request for exaple you can retrieve ints booleans, and vectors of Strings.

Note that the proces extracting the configuration might be time consuming, it might be a good idea to store the reference returned by this method in an instance variable of the service.

Parameters:
name - The name of the Service.
Returns:
The configuration resources of the Service.

notice

public void notice(java.lang.String msg)
Output a diagnostic notice. This method is used by the service framework classes for producing tracing mesages that might be useful for debugging.

Standard Turbine logging facilities are used.

Overrides:
notice in class BaseInitableBroker
Parameters:
msg - the message to print.

error

public void error(java.lang.Throwable t)
Output an error message. This method is used by the service framework classes for displaying stacktraces of any exceptions that might be caught during processing.

Standard Turbine logging facilities are used.

Overrides:
error in class BaseInitableBroker
Parameters:
msg - the message to print.


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.