org.apache.cocoon.spring.configurator.impl
Class SettingsBeanFactoryPostProcessor

java.lang.Object
  extended byorg.springframework.core.io.support.PropertiesLoaderSupport
      extended byorg.springframework.beans.factory.config.PropertyResourceConfigurer
          extended byorg.springframework.beans.factory.config.PropertyPlaceholderConfigurer
              extended byorg.apache.cocoon.spring.configurator.impl.AbstractSettingsBeanFactoryPostProcessor
                  extended byorg.apache.cocoon.spring.configurator.impl.SettingsBeanFactoryPostProcessor
All Implemented Interfaces:
BeanFactoryAware, BeanFactoryPostProcessor, BeanNameAware, FactoryBean, Ordered, PriorityOrdered, ResourceLoaderAware, ServletContextAware

public class SettingsBeanFactoryPostProcessor
extends AbstractSettingsBeanFactoryPostProcessor

This is a bean factory post processor which handles all the settings stuff for Cocoon. It reads in all properties files and replaces references to them in the spring configuration files. In addition this bean acts as a factory bean providing the settings object.

The settings object is created by reading several property files and merging of the values. If there is more than one definition for a property, the last one wins. The property files are read in the following order:

  1. If readFromClasspath is true: classpath*:/META-INF/cocoon/properties/*.properties Default values for the core and each block - the files are read in alphabetical order. Actually the files are read in two chunks, the first one containing all property files from jar files, and the second one containing all property files from WEB-INF/classes.
  2. If readFromClasspath is true: classpath*:/META-INF/cocoon/properties/[RUNNING_MODE]/*.properties Default values for the core and each block for a specific running mode - the files are read in alphabetical order. Actually the files are read in two chunks, the first one containing all property files from jar files, and the second one containing all property files from WEB-INF/classes.
  3. If readFromGlobalLocation is true: /WEB-INF/cocoon/properties/*.properties Default values for the core and each block - the files are read in alphabetical order. Actually the files are read in two chunks, the first one containing all property files from jar files, and the second one containing all property files from WEB-INF/classes.
  4. If readFromGlobalLocation is true: /WEB-INF/cocoon/properties/[RUNNING_MODE]/*.properties Default values for the core and each block for a specific running mode - the files are read in alphabetical order. Actually the files are read in two chunks, the first one containing all property files from jar files, and the second one containing all property files from WEB-INF/classes.
  5. Working directory from servlet context (if not already set)
  6. Optional property file which is stored under ".cocoon/settings.properties" in the user directory.
  7. Additional property file specified by the "org.apache.cocoon.settings" property. If the property defines a directory, all property files from this directory are read in alphabetical order and all files from a sub directory with the name of the current running mode are read in alphabetical order as well.
  8. Property provider (if configured in the bean factory)
  9. Add properties from configured directories AbstractSettingsBeanFactoryPostProcessor.directories.
  10. Add additional properties configured at AbstractSettingsBeanFactoryPostProcessor.additionalProperties
  11. System properties
This means that system properties (provided on startup of the web application) override all others etc.

Since:
1.0
Version:
$Id: SettingsBeanFactoryPostProcessor.java 591592 2007-11-03 11:09:21Z felixk $

Nested Class Summary
 
Nested classes inherited from class org.apache.cocoon.spring.configurator.impl.AbstractSettingsBeanFactoryPostProcessor
AbstractSettingsBeanFactoryPostProcessor.CocoonSettingsResolvingBeanDefinitionVisitor
 
Field Summary
protected  boolean readFromClasspath
          Should we read the properties from the classpath?
protected  boolean readFromGlobalLocation
          Should we read the properties from the global location?
protected  String runningMode
          The running mode for the web application.
 
Fields inherited from class org.apache.cocoon.spring.configurator.impl.AbstractSettingsBeanFactoryPostProcessor
additionalProperties, beanFactory, directories, logger, resourceLoader, servletContext, settings
 
Fields inherited from class org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, SYSTEM_PROPERTIES_MODE_FALLBACK, SYSTEM_PROPERTIES_MODE_NEVER, SYSTEM_PROPERTIES_MODE_OVERRIDE
 
Fields inherited from class org.springframework.core.io.support.PropertiesLoaderSupport
XML_FILE_EXTENSION
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
SettingsBeanFactoryPostProcessor()
           
 
Method Summary
protected  org.apache.cocoon.configuration.MutableSettings createSettings()
          Create a settings object.
protected  void dumpSystemProperties()
          Dump System Properties.
protected  void forceLoad()
          Handle the load-class settings.
protected  String getRunningMode()
          Get the running mode.
 void init()
          Initialize this processor.
protected  void preInit(org.apache.cocoon.configuration.MutableSettings s, Properties properties)
          This method can be used by subclasses to initialize the settings and/or the properties before createSettings() does it's work.
 void setReadFromClasspath(boolean readFromClasspath)
          Set if we read property configurations from the classpath.
 void setReadFromGlobalLocation(boolean readFromGlobalLocation)
          Set if we read property configurations from the global location.
 void setRunningMode(String mode)
          Set the running mode.
 
Methods inherited from class org.apache.cocoon.spring.configurator.impl.AbstractSettingsBeanFactoryPostProcessor
createMutableSettingsInstance, dumpSettings, getNameForPropertyProvider, getObject, getObjectType, getParentSettings, getResourceLoader, getSystemProperty, getSystemProperty, isSingleton, postInit, processProperties, resolvePlaceholder, setAdditionalProperties, setBeanFactory, setDirectories, setResourceLoader, setServletContext
 
Methods inherited from class org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
parseStringValue, resolvePlaceholder, resolveSystemProperty, setBeanName, setIgnoreUnresolvablePlaceholders, setPlaceholderPrefix, setPlaceholderSuffix, setSearchSystemEnvironment, setSystemPropertiesMode, setSystemPropertiesModeName
 
Methods inherited from class org.springframework.beans.factory.config.PropertyResourceConfigurer
convertProperties, convertPropertyValue, getOrder, postProcessBeanFactory, setOrder
 
Methods inherited from class org.springframework.core.io.support.PropertiesLoaderSupport
loadProperties, mergeProperties, setFileEncoding, setIgnoreResourceNotFound, setLocalOverride, setLocation, setLocations, setProperties, setPropertiesArray, setPropertiesPersister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

runningMode

protected String runningMode
The running mode for the web application.


readFromClasspath

protected boolean readFromClasspath
Should we read the properties from the classpath?

See Also:
Constants.CLASSPATH_PROPERTIES_LOCATION

readFromGlobalLocation

protected boolean readFromGlobalLocation
Should we read the properties from the global location?

See Also:
Constants.GLOBAL_PROPERTIES_LOCATION
Constructor Detail

SettingsBeanFactoryPostProcessor

public SettingsBeanFactoryPostProcessor()
Method Detail

setRunningMode

public void setRunningMode(String mode)
Set the running mode.

Parameters:
mode - The new running mode.

setReadFromClasspath

public void setReadFromClasspath(boolean readFromClasspath)
Set if we read property configurations from the classpath.

Parameters:
readFromClasspath -

setReadFromGlobalLocation

public void setReadFromGlobalLocation(boolean readFromGlobalLocation)
Set if we read property configurations from the global location.


init

public void init()
          throws Exception
Initialize this processor. Setup the settings object.

Overrides:
init in class AbstractSettingsBeanFactoryPostProcessor
Throws:
Exception

getRunningMode

protected String getRunningMode()
Description copied from class: AbstractSettingsBeanFactoryPostProcessor
Get the running mode. This method should be implemented by subclasses.

Specified by:
getRunningMode in class AbstractSettingsBeanFactoryPostProcessor
See Also:
AbstractSettingsBeanFactoryPostProcessor.getRunningMode()

preInit

protected void preInit(org.apache.cocoon.configuration.MutableSettings s,
                       Properties properties)
Description copied from class: AbstractSettingsBeanFactoryPostProcessor
This method can be used by subclasses to initialize the settings and/or the properties before AbstractSettingsBeanFactoryPostProcessor.createSettings() does it's work.

Overrides:
preInit in class AbstractSettingsBeanFactoryPostProcessor

createSettings

protected org.apache.cocoon.configuration.MutableSettings createSettings()
Description copied from class: AbstractSettingsBeanFactoryPostProcessor
Create a settings object. This method creates the settings by executing the following task:
  1. Create a new mutable settings object invoking AbstractSettingsBeanFactoryPostProcessor.createMutableSettingsInstance().
  2. Configure the properties and settings object by calling AbstractSettingsBeanFactoryPostProcessor.preInit(MutableSettings, Properties).
  3. Invoke a PropertyProvider if configured in the same application context (or its parent)
  4. Add properties from configured directories AbstractSettingsBeanFactoryPostProcessor.directories.
  5. Add additional properties configured at AbstractSettingsBeanFactoryPostProcessor.additionalProperties
  6. Apply system properties
  7. Configure the properties and settings object by calling AbstractSettingsBeanFactoryPostProcessor.postInit(MutableSettings, Properties).
  8. Replace references in properties
  9. Configure the settings object with the properties
  10. Make the settings object read-only.

Overrides:
createSettings in class AbstractSettingsBeanFactoryPostProcessor
Returns:
A new Settings object

dumpSystemProperties

protected void dumpSystemProperties()
Dump System Properties.


forceLoad

protected void forceLoad()
Handle the load-class settings. This overcomes limits in many classpath issues. One of the more notorious ones is a bug in WebSphere that does not load the URL handler for the classloader:// protocol. In order to overcome that bug, set org.apache.cocoon.classloader.load.classes.XY property to the com.ibm.servlet.classloader.Handler value.

If you need to load more than one class, then add several properties, all starting with org.apache.cocoon.classloader.load.classes. followed by a self defined identifier.



Copyright © 1999-2008 The Apache Software Foundation. All Rights Reserved.