cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r149243 - in cocoon/trunk/src/blocks/hsqldb: WEB-INF/xconf/cocoon-hsqldb.xconf java/org/apache/cocoon/components/hsqldb/ServerImpl.java
Date Mon, 31 Jan 2005 11:52:12 GMT
Author: reinhard
Date: Mon Jan 31 03:52:09 2005
New Revision: 149243

URL: http://svn.apache.org/viewcvs?view=rev&rev=149243
Log:
make path to HSQLDB and name of it parameterizable

Modified:
    cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf
    cocoon/trunk/src/blocks/hsqldb/java/org/apache/cocoon/components/hsqldb/ServerImpl.java

Modified: cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf?view=diff&r1=149242&r2=149243
==============================================================================
--- cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf (original)
+++ cocoon/trunk/src/blocks/hsqldb/WEB-INF/xconf/cocoon-hsqldb.xconf Mon Jan 31 03:52:09 2005
@@ -32,6 +32,8 @@
       |  port   : number      port where the server is listening
       |  silent : true/false  display all queries
       |  trace  : true/false  display JDBC trace messages
+      |  name   : string      name of the HSQL-DB
+      |  path   : string      path to the database - context-protocol is resolved
       +-->
   <hsqldb-server class="org.apache.cocoon.components.hsqldb.ServerImpl"
                  logger="core.hsqldb-server"
@@ -40,6 +42,8 @@
      <parameter name="silent" value="true"/>
      <parameter name="trace" value="false"/>
      <parameter name="thread-pool-name" value="daemon"/>
+     <parameter name="name" value="cocoondb"/>
+     <parameter name="path" value="context://WEB-INF/db"/>
   </hsqldb-server>
 
 </components>

Modified: cocoon/trunk/src/blocks/hsqldb/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/hsqldb/java/org/apache/cocoon/components/hsqldb/ServerImpl.java?view=diff&r1=149242&r2=149243
==============================================================================
--- cocoon/trunk/src/blocks/hsqldb/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
(original)
+++ cocoon/trunk/src/blocks/hsqldb/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
Mon Jan 31 03:52:09 2005
@@ -55,6 +55,16 @@
                Serviceable,
                Startable {
 
+    private static final String DEFAULT_TRACE = "false";
+    private static final String DEFAULT_SILENT = "true";
+    private static final String DEFAULT_PORT = "9002";
+    private static final String CONTEXT_PROTOCOL = "context:/"; 
+    private static final String DEFAULT_DB_NAME = "cocoondb";
+    private static final String DEFAULT_DB_PATH = "context://WEB-INF/db";
+    
+    /** Cocoon context **/
+    private org.apache.cocoon.environment.Context cocoonContext;
+    
     /** Port which HSQLDB server will listen to */
     private String port;
 
@@ -69,7 +79,7 @@
 
     /** The {@link ServiceManager} instance */
     private ServiceManager m_serviceManager;
-
+    
     /**
      * Initialize the ServerImpl.
      * A few options can be used :
@@ -83,35 +93,34 @@
         this.getLogger().debug("Parameterize ServerImpl");
 
         arguments[0] = "-port";
-        arguments[1] = this.port = params.getParameter("port", "9002");
+        arguments[1] = this.port = params.getParameter("port", DEFAULT_PORT);
         arguments[2] = "-silent";
-        arguments[3] = params.getParameter("silent", "true");
+        arguments[3] = params.getParameter("silent", DEFAULT_SILENT);
         arguments[4] = "-trace";
-        arguments[5] = params.getParameter("trace", "false");
+        arguments[5] = params.getParameter("trace", DEFAULT_TRACE);
         arguments[6] = "-no_system_exit";
-        arguments[7] = "true";
+        arguments[7] = DEFAULT_SILENT;
         if (this.getLogger().isDebugEnabled()) {
             this.getLogger().debug("Configure ServerImpl with port: " + arguments[1]
                     + ", silent: " + arguments[3]
                     + ", trace: " +arguments[5]);
         }
         m_daemonThreadPoolName = params.getParameter( "thread-pool-name", m_daemonThreadPoolName
);
-    }
 
-    /** Contextualize this class */
-    public void contextualize(Context context) throws ContextException {
-        org.apache.cocoon.environment.Context ctx =
-                (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
+        String dbPath = params.getParameter("path", DEFAULT_DB_PATH);
+        
         // test if we are running inside a WAR file
-        final String dbPath = ctx.getRealPath("/WEB-INF/db");
+        if(dbPath.startsWith(ServerImpl.CONTEXT_PROTOCOL)) {
+            dbPath = this.cocoonContext.getRealPath(dbPath.substring(ServerImpl.CONTEXT_PROTOCOL.length()));
+        } 
         if (dbPath == null) {
-            throw new ContextException("The hsqldb cannot be used inside a WAR file.");
-        }
-
+            throw new RuntimeException("The hsqldb cannot be used inside a WAR file.");
+        }        
+        
         try {
             arguments[8] = "-database.0";
             arguments[9] = new File(dbPath).getCanonicalPath();
-            arguments[9] += File.separator + "cocoondb";
+            arguments[9] += File.separator + params.getParameter("name", DEFAULT_DB_NAME);
             if (getLogger().isDebugEnabled()) {
                 getLogger().debug("database is " + arguments[9]);
             }
@@ -119,7 +128,13 @@
             getLogger().error("MalformedURLException - Could not get database directory ",
e);
         } catch (IOException e) {
             getLogger().error("IOException - Could not get database directory ", e);
-        }
+        }        
+        
+    }
+
+    /** Contextualize this class */
+    public void contextualize(Context context) throws ContextException {
+        cocoonContext = (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
     }
     /**
      * @param serviceManager The <@link ServiceManager} instance



Mime
View raw message