org.apache.cocoon.core
Class CoreUtil

java.lang.Object
  extended byorg.apache.cocoon.core.CoreUtil
Direct Known Subclasses:
OSGICoreUtil

public class CoreUtil
extends Object

This is an utility class to create a new Cocoon instance. TODO - Remove dependencies to LogKit and Log4J

Since:
2.2
Version:
$Id: CoreUtil.java 321157 2005-10-14 17:21:29Z cziegeler $

Nested Class Summary
protected static class CoreUtil.LoggerWrapper
           
 
Field Summary
protected  DefaultContext appContext
          "legacy" support: create an avalon context.
protected  ClassLoader classloader
           
protected  Cocoon cocoon
          The Cocoon instance (the root processor).
protected static Map CONTEXT_PARAMETERS
          Parameter map for the context protocol
protected  BootstrapEnvironment env
          The callback to the real environment.
protected  boolean isPerRequestLoggerManager
          Is this a per request logger manager
protected  Logger log
          The root logger.
protected  LoggerManager loggerManager
          The logger manager.
protected  ServiceManager parentManager
          The parent service manager.
protected  MutableSettings settings
          The settings.
 
Constructor Summary
CoreUtil(BootstrapEnvironment environment)
          Setup a new instance.
 
Method Summary
 void cleanUpRequest(Object handle)
          Cleanup everything initialized during the request processing in initializeRequest(Environment).
protected  void createClassloader()
          Create the classloader that inlcudes all the [block]/BLOCK-INF/classes directories.
 Cocoon createCocoon()
          Creates the Cocoon object and handles exception handling.
protected  Core createCore()
          Create a new core instance.
protected  MutableSettings createSettings()
          Get the settings for Cocoon.
protected  SourceResolver createSourceResolver(Logger logger)
          Create a simple source resolver.
 void destroy()
          Dispose Cocoon when environment is destroyed
protected  void disposeCocoon()
          Destroy Cocoon
protected  void forceLoad()
          Handle the load-class parameter.
protected  void forceProperty()
          Handle the "force-property" parameter.
 Cocoon getCocoon(String pathInfo, String reloadParam)
          Gets the current cocoon object.
protected  Logger getCocoonLogger()
           
 Core getCore()
           
protected  String getExtraClassPath()
          Retreives the "extra-classpath" attribute, that needs to be added to the class path.
protected  ServiceManager getParentServiceManager(Core core)
          Instatiates the parent service manager, as specified in the parent-service-manager init parameter.
 Settings getSettings()
          Return the settings object.
protected  void init()
           
 Object initializeRequest(Environment env)
          Initialize the current request.
protected  void initLogger()
           
protected  void overrideLogLevel(Configuration root, String value)
           
protected  void readProperties(String directoryName, MutableSettings s, SourceResolver resolver)
          Read all property files from the given directory and apply them to the settings.
protected  void updateEnvironment()
          Method to update the environment before Cocoon instances are created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTEXT_PARAMETERS

protected static final Map CONTEXT_PARAMETERS
Parameter map for the context protocol


env

protected final BootstrapEnvironment env
The callback to the real environment.


appContext

protected final DefaultContext appContext
"legacy" support: create an avalon context.


settings

protected MutableSettings settings
The settings.


parentManager

protected ServiceManager parentManager
The parent service manager.


log

protected Logger log
The root logger.


loggerManager

protected LoggerManager loggerManager
The logger manager.


cocoon

protected Cocoon cocoon
The Cocoon instance (the root processor).


isPerRequestLoggerManager

protected boolean isPerRequestLoggerManager
Is this a per request logger manager


classloader

protected ClassLoader classloader
Constructor Detail

CoreUtil

public CoreUtil(BootstrapEnvironment environment)
         throws Exception
Setup a new instance.

Parameters:
environment - The hook back to the environment.
Throws:
Exception
Method Detail

init

protected void init()
             throws Exception
Throws:
Exception

getCore

public Core getCore()

createCore

protected Core createCore()
Create a new core instance. This method can be overwritten in sub classes.

Returns:
A new core object.

getSettings

public Settings getSettings()
Return the settings object.


getParentServiceManager

protected ServiceManager getParentServiceManager(Core core)
Instatiates the parent service manager, as specified in the parent-service-manager init parameter. If none is specified, the method returns null.

Returns:
the parent service manager, or null.

createSettings

protected MutableSettings createSettings()
Get the settings for Cocoon. This method reads several property files and merges the result. If there is more than one definition for a property, the last one wins. The property files are read in the following order: 1) context://WEB-INF/properties/*.properties Default values for the core and each block - the order in which the files are read is not guaranteed. 2) context://WEB-INF/properties/[RUNNING_MODE]/*.properties Default values for the running mode - the order in which the files are read is not guaranteed. 3) Property providers (ToBeDocumented) 4) The environment (CLI, Servlet etc.) adds own properties (e.g. from web.xml) 5) Additional property file specified by the "org.apache.cocoon.settings" system property or if the property is not found, the file ".cocoon/settings.properties" is tried to be read from the user directory. 6) System properties

Returns:
A new Settings object

readProperties

protected void readProperties(String directoryName,
                              MutableSettings s,
                              SourceResolver resolver)
Read all property files from the given directory and apply them to the settings.


initializeRequest

public Object initializeRequest(Environment env)
Initialize the current request. This method can be used to initialize anything required for processing the request. For example, if the logger manager is a PerRequestLoggerManager than this manager is invoked to initialize the logging context for the request. This method returns a handle that should be used to clean up everything when the request is finished by calling cleanUpRequest(Object).


cleanUpRequest

public void cleanUpRequest(Object handle)
Cleanup everything initialized during the request processing in initializeRequest(Environment).


createSourceResolver

protected SourceResolver createSourceResolver(Logger logger)
Create a simple source resolver.


initLogger

protected void initLogger()

overrideLogLevel

protected void overrideLogLevel(Configuration root,
                                String value)

createCocoon

public Cocoon createCocoon()
                    throws Exception
Creates the Cocoon object and handles exception handling.

Throws:
Exception

createClassloader

protected void createClassloader()
                          throws Exception
Create the classloader that inlcudes all the [block]/BLOCK-INF/classes directories.

Throws:
Exception

getCocoon

public Cocoon getCocoon(String pathInfo,
                        String reloadParam)
                 throws Exception
Gets the current cocoon object. Reload cocoon if configuration changed or we are reloading. Ensure that the correct classloader is set.

Throws:
Exception

disposeCocoon

protected final void disposeCocoon()
Destroy Cocoon


getCocoonLogger

protected Logger getCocoonLogger()

forceLoad

protected void forceLoad()
Handle the load-class parameter. 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 load-class parameter to the com.ibm.servlet.classloader.Handler value.

If you need to load more than one class, then separate each entry with whitespace, a comma, or a semi-colon. Cocoon will strip any whitespace from the entry.


forceProperty

protected void forceProperty()
Handle the "force-property" parameter. If you need to force more than one property to load, then separate each entry with whitespace, a comma, or a semi-colon. Cocoon will strip any whitespace from the entry.


updateEnvironment

protected void updateEnvironment()
                          throws Exception
Method to update the environment before Cocoon instances are created. This is also useful if you wish to customize any of the 'protected' variables from this class before a Cocoon instance is built in a derivative of this class (eg. Cocoon Context).

Throws:
Exception

destroy

public void destroy()
Dispose Cocoon when environment is destroyed


getExtraClassPath

protected String getExtraClassPath()
Retreives the "extra-classpath" attribute, that needs to be added to the class path.



Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.