cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r391810 - in /cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core: CoreUtil.java container/spring/BeanFactoryUtil.java
Date Wed, 05 Apr 2006 21:04:03 GMT
Author: danielf
Date: Wed Apr  5 14:04:02 2006
New Revision: 391810

URL: http://svn.apache.org/viewcvs?rev=391810&view=rev
Log:
Continued refactor CoreUtil, so that its different products: Settings, (Avalon) Context, BeanFactory,
Logger and Cocoon can be created independently. This is needed for setting up blocks and in
general for making the setup less monolithic.

Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java?rev=391810&r1=391809&r2=391810&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/CoreUtil.java Wed Apr
 5 14:04:02 2006
@@ -188,9 +188,46 @@
         // create settings
         this.settings = this.createSettings();
 
+        // Create bootstrap logger
+        this.log = BeanFactoryUtil.createBootstrapLogger(this.environmentContext, settings.getBootstrapLogLevel());
+
+        if (this.log.isDebugEnabled())
+            this.log.debug("Context URL: " + contextUrl);
+
+        // initialize some directories
+        CoreUtil.initSettingsFiles(this.settings, this.log);
+
+        // update configuration
+        final URL u = this.getConfigFile(this.settings.getConfiguration());
+        this.settings.setConfiguration(u.toExternalForm());
+
+        // dump system properties
+        this.dumpSystemProperties();
+
+        // settings can't be changed anymore
+        this.settings.makeReadOnly();
+
+        // Init logger
+        this.log = BeanFactoryUtil.createRootLogger(this.environmentContext,
+                                                    this.settings);
+
+        this.createClassloader();
+        // add the Avalon context attributes that are contained in the settings
+        CoreUtil.addSettingsContext(this.appContext, this.settings, this.classloader);
+
+        // test the setup of the spring based container
+        this.container = this.setupSpringContainer();
+    }
+
+    /**
+     * Init work, upload and cache directory
+     * @param settings 
+     * @param log 
+     */
+    public static void initSettingsFiles(MutableSettings settings, Logger log) {
         // first init the work-directory for the logger.
         // this is required if we are running inside a war file!
-        final String workDirParam = this.settings.getWorkDirectory();
+        final String workDirParam = settings.getWorkDirectory();
         File workDir;
         if (workDirParam != null) {
             // No context path : consider work-directory as absolute
@@ -199,44 +236,39 @@
             workDir = new File("cocoon-files");
         }
         workDir.mkdirs();
-        this.settings.setWorkDirectory(workDir.getAbsolutePath());
-
-        // Init logger
-        this.log = BeanFactoryUtil.createRootLogger(this.environmentContext,
-                                                    this.settings);
+        settings.setWorkDirectory(workDir.getAbsolutePath());
 
         // Output some debug info
-        if (this.log.isDebugEnabled()) {
-            this.log.debug("Context URL: " + contextUrl);
+        if (log.isDebugEnabled()) {
             if (workDirParam != null) {
-                this.log.debug("Using work-directory " + workDir);
+                log.debug("Using work-directory " + workDir);
             } else {
-                this.log.debug("Using default work-directory " + workDir);
+                log.debug("Using default work-directory " + workDir);
             }
         }
 
-        final String uploadDirParam = this.settings.getUploadDirectory();
+        final String uploadDirParam = settings.getUploadDirectory();
         File uploadDir;
         if (uploadDirParam != null) {
             uploadDir = new File(uploadDirParam);
-            if (this.log.isDebugEnabled()) {
-                this.log.debug("Using upload-directory " + uploadDir);
+            if (log.isDebugEnabled()) {
+                log.debug("Using upload-directory " + uploadDir);
             }
         } else {
             uploadDir = new File(workDir, "upload-dir" + File.separator);
-            if (this.log.isDebugEnabled()) {
-                this.log.debug("Using default upload-directory " + uploadDir);
+            if (log.isDebugEnabled()) {
+                log.debug("Using default upload-directory " + uploadDir);
             }
         }
         uploadDir.mkdirs();
-        this.settings.setUploadDirectory(uploadDir.getAbsolutePath());
+        settings.setUploadDirectory(uploadDir.getAbsolutePath());
 
-        String cacheDirParam = this.settings.getCacheDirectory();
+        String cacheDirParam = settings.getCacheDirectory();
         File cacheDir;
         if (cacheDirParam != null) {
             cacheDir = new File(cacheDirParam);
-            if (this.log.isDebugEnabled()) {
-                this.log.debug("Using cache-directory " + cacheDir);
+            if (log.isDebugEnabled()) {
+                log.debug("Using cache-directory " + cacheDir);
             }
         } else {
             cacheDir = new File(workDir, "cache-dir" + File.separator);
@@ -244,29 +276,12 @@
             if (parent != null) {
                 parent.mkdirs();
             }
-            if (this.log.isDebugEnabled()) {
-                this.log.debug("cache-directory was not set - defaulting to " + cacheDir);
+            if (log.isDebugEnabled()) {
+                log.debug("cache-directory was not set - defaulting to " + cacheDir);
             }
         }
         cacheDir.mkdirs();
-        this.settings.setCacheDirectory(cacheDir.getAbsolutePath());
-
-        // update configuration
-        final URL u = this.getConfigFile(this.settings.getConfiguration());
-        this.settings.setConfiguration(u.toExternalForm());
-
-        // dump system properties
-        this.dumpSystemProperties();
-
-        // settings can't be changed anymore
-        this.settings.makeReadOnly();
-
-        this.createClassloader();
-        // add the Avalon context attributes that are contained in the settings
-        CoreUtil.addSettingsContext(this.appContext, this.settings, this.classloader);
-
-        // test the setup of the spring based container
-        this.container = this.setupSpringContainer();
+        settings.setCacheDirectory(cacheDir.getAbsolutePath());
     }
 
     public static DefaultContext createContext(Settings settings, Context environmentContext,

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java?rev=391810&r1=391809&r2=391810&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/BeanFactoryUtil.java
Wed Apr  5 14:04:02 2006
@@ -150,13 +150,16 @@
             throw new CoreInitializationException("Cannot setup log4j logging system.", ce);
         }
     }
-
-    protected static Logger initLogger(ServletContext servletContext,
-                                       Settings       settings)
-    throws Exception {
+    
+    /**
+     * Create a bootstrap logger that uses the servlet context
+     * @param servletContext
+     * @param logLevelString
+     * @return the logger
+     */
+    public static Logger createBootstrapLogger(ServletContext servletContext, String logLevelString)
{
         // create a bootstrap logger
         int logLevel;
-        final String logLevelString = settings.getBootstrapLogLevel();
         if ( "DEBUG".equalsIgnoreCase(logLevelString) ) {
             logLevel = ServletLogger.LEVEL_DEBUG;
         } else if ( "WARN".equalsIgnoreCase(logLevelString) ) {
@@ -166,7 +169,15 @@
         } else {
             logLevel = ServletLogger.LEVEL_INFO;
         }
-        final Logger bootstrapLogger = new ServletLogger(servletContext, "Cocoon", logLevel);
+        return new ServletLogger(servletContext, "Cocoon", logLevel);
+    }
+
+    protected static Logger initLogger(ServletContext servletContext,
+                                       Settings       settings)
+    throws Exception {
+        // create a bootstrap logger
+        final String logLevelString = settings.getBootstrapLogLevel();
+        final Logger bootstrapLogger = BeanFactoryUtil.createBootstrapLogger(servletContext,
logLevelString);
 
 
         // create an own context for the logger manager



Mime
View raw message