You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by pi...@apache.org on 2004/11/03 03:26:56 UTC

svn commit: rev 56455 - cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup

Author: pier
Date: Tue Nov  2 18:26:54 2004
New Revision: 56455

Modified:
   cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/Main.java
   cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/ServletLoader.java
Log:
Have kernel classpath in configuration rather than on command line

Modified: cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/Main.java
==============================================================================
--- cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/Main.java	(original)
+++ cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/Main.java	Tue Nov  2 18:26:54 2004
@@ -12,8 +12,10 @@
  * =============================================================================== */
 package org.apache.cocoon.kernel.startup;
 
-import java.io.File;
 import java.net.URL;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
 
 import javax.sql.DataSource;
 
@@ -68,14 +70,13 @@
      */
     public static void main(String args[])
     throws Throwable {
-        if ((args.length < 2) || (args.length > 3)) { 
+        if ((args.length < 1) || (args.length > 2)) { 
             String name = Main.class.getName();
             System.err.println("Usage:");
-            System.err.println("  " + name + " <jar-file> <conf-file>");
+            System.err.println("  " + name + " <conf-file>");
             System.err.println("or");
-            System.err.println("  " + name + " <jar-file> <desc-file> <inst-file>");
+            System.err.println("  " + name + " <desc-file> <inst-file>");
             System.err.println();
-            System.err.println("  <conf-file> The JAR of the kernel");
             System.err.println("  <conf-file> Combined descriptor/instances XML");
             System.err.println("  <desc-file> Descriptors locator XML");
             System.err.println("  <inst-file> Instances deployment XML");
@@ -87,13 +88,28 @@
         ConsoleLogger logger = new ConsoleLogger();
         try {
             /* Parse the (possibly two) configurations */
-            Configuration descriptors = ConfigurationBuilder.parse(args[1]);
-            Configuration instances = (args.length == 2 ? descriptors : 
-                    ConfigurationBuilder.parse(args[2]));
+            Configuration descriptors = ConfigurationBuilder.parse(args[0]);
+            Configuration instances = (args.length < 2 ? descriptors : 
+                    ConfigurationBuilder.parse(args[1]));
+            
+            /* Resolve the kernel class path */
+            Set classpath = new HashSet();
+            Iterator iterator = descriptors.child("classpath").children("library");
+            while (iterator.hasNext()) {
+                Configuration current = (Configuration) iterator.next();
+                String location = current.getStringAttribute("href");
+                classpath.add(new URL(current.locationURL(), location));
+            }
         
-            /* Create and initialize a new deployer */
-            URL library = new File(args[0]).toURL();
-            StartupKernel kernel = KernelLoader.load(library);
+            URL libraries[] = new URL[classpath.size()];
+            libraries = (URL []) classpath.toArray(libraries);
+            logger.debug("Kernel class path:");
+            for (int x = 0 ; x < libraries.length; x ++) {
+                logger.debug(" - " + libraries[x].toString());
+            }
+            
+            /* Create and initialize a new kernel loader and kernel */
+            StartupKernel kernel = KernelLoader.load(libraries);
             kernel.setLogger(logger);
             kernel.initialize(descriptors, instances);
 

Modified: cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/ServletLoader.java
==============================================================================
--- cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/ServletLoader.java	(original)
+++ cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/ServletLoader.java	Tue Nov  2 18:26:54 2004
@@ -13,6 +13,9 @@
 package org.apache.cocoon.kernel.startup;
 
 import java.net.URL;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
 
 import javax.servlet.Servlet;
 import javax.servlet.ServletContext;
@@ -82,42 +85,50 @@
     public void contextInitialized(ServletContextEvent event) {
         ServletContext context = event.getServletContext();
 
-        String library = context.getInitParameter("kernel-library");
-        if (library == null) {
-            String message = "Context parameter \"kernel-library\" not specified";
-            context.log(message);
-            throw new RuntimeException(message);
-        }
-
         /* Retrieve the "descriptors" configuration */
         String configuration = context.getInitParameter("kernel-configuration");
-        String descriptors = context.getInitParameter("kernel-descriptors");
-        String instances = context.getInitParameter("kernel-instances");
         
         /* Load and initialize the kernel */
         ServletLogger logger = new ServletLogger(context);
         try {
-            URL library_url = context.getResource(library);
-            if (library_url == null) {
-                String message = "Unable to resolve library \"" + library + "\"";
-                context.log(message);
-                throw new RuntimeException(message);
-            }
-            this.kernel = KernelLoader.load(library_url);
-            this.kernel.setLogger(logger);
-
             /* Parse the (possibly two) configurations and initialize the deployer */
+            Configuration descriptors = null;
+            Configuration instances = null;
+            
             if (configuration != null) {
                 URL configuration_url = context.getResource(configuration);
                 Configuration conf = ConfigurationBuilder.parse(configuration_url);
-                this.kernel.initialize(conf);
+                descriptors = instances = conf;
             } else {
-                URL descriptors_url = context.getResource(descriptors);
-                URL instances_url = context.getResource(instances);
-                Configuration desc = ConfigurationBuilder.parse(descriptors_url);
-                Configuration inst = ConfigurationBuilder.parse(instances_url);
-                this.kernel.initialize(desc, inst);
+                String desc_par = context.getInitParameter("kernel-descriptors");
+                String inst_par = context.getInitParameter("kernel-instances");
+                URL desc_url = context.getResource(desc_par);
+                URL inst_url = context.getResource(inst_par);
+                descriptors = ConfigurationBuilder.parse(desc_url);
+                instances =   ConfigurationBuilder.parse(inst_url);
+            }
+            
+            /* Resolve the kernel class path */
+            Set classpath = new HashSet();
+            Iterator iterator = descriptors.child("classpath").children("library");
+            while (iterator.hasNext()) {
+                Configuration current = (Configuration) iterator.next();
+                String location = current.getStringAttribute("href");
+                classpath.add(new URL(current.locationURL(), location));
             }
+        
+            URL libraries[] = new URL[classpath.size()];
+            libraries = (URL []) classpath.toArray(libraries);
+            logger.debug("Kernel class path:");
+            for (int x = 0 ; x < libraries.length; x ++) {
+                logger.debug(" - " + libraries[x].toString());
+            }
+
+            /* Create and initialize a new kernel loader and kernel */
+            this.kernel = KernelLoader.load(libraries);
+            this.kernel.setLogger(logger);
+            this.kernel.initialize(descriptors, instances);
+
         } catch (Throwable t) {
             logger.error("Unable to intialize kernel", t);
             throw new RuntimeException("Unable to initialize kernel", t);