Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 26858 invoked from network); 3 Nov 2004 02:27:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 3 Nov 2004 02:27:53 -0000 Received: (qmail 3657 invoked by uid 500); 3 Nov 2004 02:27:25 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 3534 invoked by uid 500); 3 Nov 2004 02:27:24 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 3454 invoked by uid 99); 3 Nov 2004 02:27:22 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 02 Nov 2004 18:27:19 -0800 Received: (qmail 26460 invoked by uid 65534); 3 Nov 2004 02:26:56 -0000 Date: 3 Nov 2004 02:26:56 -0000 Message-ID: <20041103022656.26456.qmail@minotaur.apache.org> From: pier@apache.org To: cvs@cocoon.apache.org Subject: svn commit: rev 56455 - cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 + " "); + System.err.println(" " + name + " "); System.err.println("or"); - System.err.println(" " + name + " "); + System.err.println(" " + name + " "); System.err.println(); - System.err.println(" The JAR of the kernel"); System.err.println(" Combined descriptor/instances XML"); System.err.println(" Descriptors locator XML"); System.err.println(" 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);