Author: pier
Date: Tue Nov  2 12:01:02 2004
New Revision: 56410

Added:
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/ExtendingDescriptor.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Extension.java
   cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/plugins/
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/plugins/Plugin.java
   
cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/KernelLoader.java
   
cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/StartupKernel.java
Modified:
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Dependencies.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/DependencyException.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Deployer.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/DeployerException.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Factory.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Instance.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Wiring.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Block.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Descriptor.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Identifier.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Interface.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Library.java
   
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Module.java
   
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:
Major works... Split loading and execution, and added the ida of "Extensions" 
to the kernel embracing the idea of plug-ins

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Dependencies.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Dependencies.java
      (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Dependencies.java
      Tue Nov  2 12:01:02 2004
@@ -10,7 +10,7 @@
  * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
  * specific language governing permissions and limitations under the License.  
    *
  * 
=============================================================================== 
*/
-package org.apache.cocoon.kernel.runtime;
+package org.apache.cocoon.kernel.deployment;
 
 import java.util.ArrayList;
 import java.util.List;

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/DependencyException.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/DependencyException.java
       (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/DependencyException.java
       Tue Nov  2 12:01:02 2004
@@ -10,7 +10,7 @@
  * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
  * specific language governing permissions and limitations under the License.  
    *
  * 
=============================================================================== 
*/
-package org.apache.cocoon.kernel.runtime;
+package org.apache.cocoon.kernel.deployment;
 
 import org.apache.cocoon.kernel.description.Identifier;
 

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Deployer.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Deployer.java
  (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Deployer.java
  Tue Nov  2 12:01:02 2004
@@ -10,7 +10,7 @@
  * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
  * specific language governing permissions and limitations under the License.  
    *
  * 
=============================================================================== 
*/
-package org.apache.cocoon.kernel.runtime;
+package org.apache.cocoon.kernel.deployment;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
@@ -20,10 +20,13 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.cocoon.kernel.Kernel;
 import org.apache.cocoon.kernel.KernelException;
 import org.apache.cocoon.kernel.configuration.Configuration;
+import org.apache.cocoon.kernel.description.Block;
+import org.apache.cocoon.kernel.description.Descriptor;
 import org.apache.cocoon.kernel.description.Library;
+import org.apache.cocoon.kernel.startup.KernelLoader;
+import org.apache.cocoon.kernel.startup.StartupKernel;
 
 /**
  * <p>The [EMAIL PROTECTED] Deployer} class is the main access point of the 
framework, providing
@@ -33,36 +36,43 @@
  * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
  *         Software Foundation</a>. All rights reserved.
  */
-public class Deployer implements Kernel {
+public class Deployer implements StartupKernel {
 
     /** <p>An empty array of [EMAIL PROTECTED] Object}s to be using in 
reflection.</p> */
     private static final Object NULL[] = new Object[0];
 
+    /** <p>The [EMAIL PROTECTED] KernelLoader} loading our instance.</p> */
+    private KernelLoader loader = null;
     /** <p>The [EMAIL PROTECTED] Library} of all [EMAIL PROTECTED] Block}s and 
[EMAIL PROTECTED] Interface}s.</p> */
     private Library library = null;
     /** <p>The [EMAIL PROTECTED] Runtime} of all available [EMAIL PROTECTED] 
Instance}s.</p> */
-    private Runtime runtime = null;
+    //private Runtime runtime = null;
     /** <p>A [EMAIL PROTECTED] Map} of all initialized singleton 
components.</p> */
     private Map singletons = new HashMap();
     /** <p>A [EMAIL PROTECTED] Set} containing all components being 
initialized.</p> */
     private Set initializing = new HashSet();
+    /** <p>A simple [EMAIL PROTECTED] Map} holding all instances and 
configurations.</p> */
+    private Map wrappers = new HashMap();
 
     /**
      * <p>Create a new [EMAIL PROTECTED] Deployer} instance.</p>
      */
-    public Deployer() {
+    public Deployer(KernelLoader loader) {
+        this.loader = loader;
         this.library = new Library();
-        this.runtime = new Runtime(this.getClass().getClassLoader(), 
this.library);
     }
 
+    /* 
=========================================================================== */
+    /* PUBLIC METHODS                                                          
    */
+    /* 
=========================================================================== */
+    
     /**
      * <p>Initialize this deployer using the specified [EMAIL PROTECTED] 
Configuration}.</p>
      * 
      * @param configuration A [EMAIL PROTECTED] Configuration} containing 
descriptors locations
      *                      and block instances.
      */
-    public void initialize(Configuration configuration)
-    throws DeployerException {
+    public void initialize(Configuration configuration) {
         this.initialize(configuration, configuration);
     }
 
@@ -72,17 +82,39 @@
      * @param descriptors A [EMAIL PROTECTED] Configuration} containing 
descriptors locations.
      * @param instances A [EMAIL PROTECTED] Configuration} containing block 
instances.
      */
-    public void initialize(Configuration descriptors, Configuration instances)
-    throws DeployerException {
-        Factory.configure(this.library, descriptors);
-        Factory.configure(this.runtime, instances);
+    public void initialize(Configuration descriptors, Configuration instances) 
{
+        try {
+            /* Retrieve all descriptors and put them in the library */
+            Factory.configure(this.library, descriptors);
 
-        /* Initialize all singletons */
-        Iterator iterator = this.runtime.iterator();
-        while (iterator.hasNext()) {
-            /* Retrieve the instance and configuration */
-            String name = (String) iterator.next();
-            this.singletons.put(name, this.instantiate(name));
+            /* Make sure that our loader adds _all_ the libraries we need */
+            Iterator extensions = library.iterator(Descriptor.EXTENSION);
+            while (extensions.hasNext()) {
+                Descriptor descriptor = ((Descriptor) extensions.next());
+                this.loader.addURL(this, descriptor.getLibraries());
+            }
+
+            Iterator interfaces = library.iterator(Descriptor.INTERFACE);
+            while (interfaces.hasNext()) {
+                Descriptor descriptor = ((Descriptor) interfaces.next());
+                this.loader.addURL(this, descriptor.getLibraries());
+            }
+            
+            /* Configure all instances and be done with it */
+            Factory.configure(this, instances);
+
+            /* Initialize all singletons */
+            Iterator iterator = this.iterator();
+            System.err.println("INSTANCES:");
+            while (iterator.hasNext()) {
+                /* Retrieve the instance and configuration */
+                String name = (String) iterator.next();
+                System.err.println(" " + name);
+                this.singletons.put(name, this.instantiate(name));
+            }
+
+        } catch (DeployerException exception) {
+            throw new KernelException("Unable to initialize kernel", 
exception);
         }
     }
 
@@ -94,7 +126,7 @@
         while (iterator.hasNext()) {
             String current = (String) iterator.next();
             Object component = this.singletons.get(current);
-            Instance instance = this.runtime.getInstance(current);
+            Instance instance = this.getInstance(current);
             Method destructor = instance.getComponentDestroyerMethod();
             try {
                 if (destructor != null) destructor.invoke(component, NULL);
@@ -113,7 +145,7 @@
     throws KernelException {
 
         /* Retrieve and check the instance */
-        Instance instance = this.runtime.getInstance(name);
+        Instance instance = this.getInstance(name);
         if (instance == null) {
             throw new KernelException("Block instance \"" + name + "\" 
unknown");
         }
@@ -121,7 +153,7 @@
         /* Prepare wiring and component */
         Object component = this.singletons.get(instance);
         if (component == null) try {
-            component = this.instantiate(name, instance);
+            component = this.instantiate(name);
         } catch (Throwable t) {
             throw new KernelException("Unable to create non-singleton 
component "
                     + " instance for block \"" + instance.getBlock().toString()
@@ -132,7 +164,7 @@
         /* Create and return the proxy instance */
         Class interfaces[] = instance.getImplementedInterfaces();
         try {
-            return Proxy.newProxyInstance(this.runtime, interfaces, wiring);
+            return Proxy.newProxyInstance(this.loader, interfaces, wiring);
         } catch (Throwable t) {
             throw new KernelException("Unable to create component proxy 
instance "
                     + " for block \"" + instance.getBlock().toString()
@@ -140,26 +172,75 @@
         }
     }
 
+    /* 
=========================================================================== */
+    /* PROTECTED METHODS                                                       
    */
+    /* 
=========================================================================== */
+
+    /**
+     * <p>Push a new [EMAIL PROTECTED] Block} [EMAIL PROTECTED] Instance} into 
this [EMAIL PROTECTED] Runtime}.</p>
+     */
+    protected void add(String name, Instance instance, Configuration 
configuration) {
+        if (name == null) throw new NullPointerException("Null name");
+        if (instance == null) throw new NullPointerException("Null instance");
+        if (configuration == null) throw new NullPointerException("Null 
config");
+        this.wrappers.put(name, new Wrapper(instance, configuration));
+    }
+
     /**
-     * <p>Return the [EMAIL PROTECTED] Runtime} instance associated with 
this.</p>
+     * <p>Return an [EMAIL PROTECTED] Iterator} over all [EMAIL PROTECTED] 
Instance} names configured.</p>
      */
-    protected Runtime getRuntime() {
-        return this.runtime;
+    protected Iterator iterator() {
+        return(this.wrappers.keySet().iterator());
     }
 
     /**
-     * <p>Instantiate a new component given its block instance name.</p>
+     * <p>Return the [EMAIL PROTECTED] Block} associated with the given 
name.</p>
      */
-    private Object instantiate(String name)
-    throws DeployerException {
-        return this.instantiate(name, this.runtime.getInstance(name));
+    protected Block getBlock(String name) {
+        Wrapper wrapper = (Wrapper) this.wrappers.get(name);
+        return (wrapper == null? null : wrapper.instance.getBlock());
+    }
+
+    /**
+     * <p>Return the [EMAIL PROTECTED] Instance} associated with the given 
name.</p>
+     */
+    protected Instance getInstance(String name) {
+        Wrapper wrapper = (Wrapper) this.wrappers.get(name);
+        return (wrapper == null? null : wrapper.instance);
+    }
+
+    /**
+     * <p>Return the [EMAIL PROTECTED] Configuration} associated with the 
given name.</p>
+     */
+    protected Configuration getConfiguration(String name) {
+        Wrapper wrapper = (Wrapper) this.wrappers.get(name);
+        return (wrapper == null? null : wrapper.configuration);
+    }
+    
+    /**
+     * <p>Return the [EMAIL PROTECTED] Library} associated with this [EMAIL 
PROTECTED] Runtime}.</p>
+     */
+    protected Library getLibrary() {
+        return(this.library);
+    }
+
+    /**
+     * <p>Return the [EMAIL PROTECTED] Runtime} instance associated with 
this.</p>
+     */
+    protected KernelLoader getLoader() {
+        return(this.loader);
     }
 
+    /* 
=========================================================================== */
+    /* PRIVATE METHODS                                                         
    */
+    /* 
=========================================================================== */
+
     /**
      * <p>Instantiate a new component given its block instance and name.</p>
      */
-    private Object instantiate(String name, Instance instance)
+    private Object instantiate(String name)
     throws DeployerException {
+        Instance instance = this.getInstance(name);
         if (instance == null) {
             throw new DeployerException("Invalid instance \"" + name + "\"");
         }
@@ -174,7 +255,7 @@
         }
 
         /* Configure this component instance */
-        Configuration configuration = this.runtime.getConfiguration(name);
+        Configuration configuration = this.getConfiguration(name);
         if (this.initializing.contains(name)) {
             throw new DeployerException("Circular dependancy found 
initializing "
                     + "instance \"" + name + "\"");
@@ -195,5 +276,20 @@
 
         /* Return the initialized component */
         return (component);
+    }
+
+    /**
+     * <p>A simple class wrapping aroung a [EMAIL PROTECTED] Block} [EMAIL 
PROTECTED] Instance} and its
+     * [EMAIL PROTECTED] Configuration}s.</p>
+     */
+    private static final class Wrapper {
+        protected Instance instance = null;
+        protected Configuration configuration = null;
+        private Wrapper(Instance instance, Configuration config) {
+            if (instance == null) throw new NullPointerException("Null 
instance");
+            if (config == null) throw new NullPointerException("Null 
configuration");
+            this.instance = instance;
+            this.configuration = config;
+        }
     }
 }

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/DeployerException.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/DeployerException.java
 (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/DeployerException.java
 Tue Nov  2 12:01:02 2004
@@ -10,7 +10,7 @@
  * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
  * specific language governing permissions and limitations under the License.  
    *
  * 
=============================================================================== 
*/
-package org.apache.cocoon.kernel.runtime;
+package org.apache.cocoon.kernel.deployment;
 
 /**
  * <p>A [EMAIL PROTECTED] DeployerException} is thrown whenever an error 
occurred in the

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Factory.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Factory.java
   (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Factory.java
   Tue Nov  2 12:01:02 2004
@@ -10,7 +10,7 @@
  * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
  * specific language governing permissions and limitations under the License.  
    *
  * 
=============================================================================== 
*/
-package org.apache.cocoon.kernel.runtime;
+package org.apache.cocoon.kernel.deployment;
 
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Array;
@@ -24,6 +24,7 @@
 import org.apache.cocoon.kernel.Kernel;
 import org.apache.cocoon.kernel.configuration.Configuration;
 import org.apache.cocoon.kernel.configuration.ConfigurationBuilder;
+import org.apache.cocoon.kernel.description.Extension;
 import org.apache.cocoon.kernel.description.Module;
 import org.apache.cocoon.kernel.description.Block;
 import org.apache.cocoon.kernel.description.Descriptor;
@@ -68,6 +69,8 @@
                 library.add(new Block(descriptor));
             } else if (Descriptor.NAMES[Descriptor.INTERFACE].equals(name)) {
                 library.add(new Interface(descriptor));
+            } else if (Descriptor.NAMES[Descriptor.EXTENSION].equals(name)) {
+                library.add(new Extension(descriptor));
             } else {
                 throw new DeployerException("Invalid descriptor root element 
\""
                         + descriptor.name() + "\" found in descriptor at "
@@ -84,7 +87,7 @@
     /**
      * <p>Configure the specified [EMAIL PROTECTED] Runtime} from a [EMAIL 
PROTECTED] Configuration}.</p>
      */
-    public static void configure(Runtime runtime, Configuration config)
+    public static void configure(Deployer runtime, Configuration config)
     throws DeployerException {
         if (runtime == null) throw new NullPointerException("Null runtime");
         if (config == null) throw new NullPointerException("Null 
configuration");
@@ -194,7 +197,7 @@
             if (curr.getBooleanAttribute("kernel", false)) try {
                 Wiring w = new Wiring(depl);
                 Class i[] = new Class[] { Kernel.class };
-                Object value = Proxy.newProxyInstance(depl.getRuntime(), i, w);
+                Object value = Proxy.newProxyInstance(depl.getLoader(), i, w);
                 descr.getWriteMethod().invoke(obj, new Object[] { value });
                 continue;
             } catch (Throwable t) {

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Instance.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Instance.java
  (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Instance.java
  Tue Nov  2 12:01:02 2004
@@ -10,7 +10,7 @@
  * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
  * specific language governing permissions and limitations under the License.  
    *
  * 
=============================================================================== 
*/
-package org.apache.cocoon.kernel.runtime;
+package org.apache.cocoon.kernel.deployment;
 
 import java.lang.reflect.Method;
 import java.net.URL;
@@ -20,6 +20,7 @@
 
 import org.apache.cocoon.kernel.description.Block;
 import org.apache.cocoon.kernel.description.Descriptor;
+import org.apache.cocoon.kernel.description.ExtendingDescriptor;
 import org.apache.cocoon.kernel.description.Identifier;
 import org.apache.cocoon.kernel.description.Interface;
 import org.apache.cocoon.kernel.description.Library;
@@ -43,13 +44,17 @@
     private Method destroyer = null;
     /** <p>The [EMAIL PROTECTED] Block} instance associated with this [EMAIL 
PROTECTED] Instance}.</p> */
     private Block block = null;
+    /** <p>A set of all known [EMAIL PROTECTED] URL}s to avoid 
duplications.</p> */
+    private Set urls = new HashSet();
 
     /**
      * <p>Create a new [EMAIL PROTECTED] Instance} instance.</p>
      */
-    public Instance(Runtime runtime, Block block)
+    public Instance(Deployer deployer, Block block)
     throws DeployerException {
-        super(block.getLibraries(), runtime);
+        super(block.getLibraries(), deployer.getLoader());
+        URL libraries[] = block.getLibraries();
+        for (int k = 0; k < libraries.length; k ++) urls.add(libraries[k]);
         this.block = block;
 
         /* Process all interfaces, all extended blocks and all modules */
@@ -57,11 +62,11 @@
         dependencies.push(block);
         Set interfaces = new HashSet();
 
-        this.process(runtime.getLibrary(), block.getImplementedInterfaces(),
+        this.process(deployer.getLibrary(), block.getImplementedInterfaces(),
                      dependencies, interfaces, Descriptor.INTERFACE);
-        this.process(runtime.getLibrary(), block.getExtendedBlocks(),
+        this.process(deployer.getLibrary(), block.getExtendedDescriptors(),
                     dependencies, interfaces, Descriptor.BLOCK);
-        this.process(runtime.getLibrary(), block.getRequiredModules(),
+        this.process(deployer.getLibrary(), block.getRequiredModules(),
                     dependencies, interfaces, Descriptor.MODULE);
 
         this.interfaces = new Class[interfaces.size()];
@@ -187,11 +192,14 @@
         /* Add the libraries if this is a block or a module */
         if ((type == Descriptor.BLOCK) || (type == Descriptor.MODULE)) {
             URL libs[] = desc.getLibraries();
-            for (int x = 0; x < libs.length; x ++) super.addURL(libs[x]);
+            for (int x = 0; x < libs.length; x ++) {
+                if (this.urls.contains(libs[x])) continue;
+                super.addURL(libs[x]);
+            }
         }
 
         /* Process extensions declared by the descriptor */
-        Identifier identifiers[] = desc.getExtendedBlocks();
+        Identifier identifiers[] = ((ExtendingDescriptor) 
desc).getExtendedDescriptors();
         this.process(library, identifiers, dependencies, interfaces, type);
 
         /* Process interfaces and modules of a block */

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Wiring.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Wiring.java
    (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/deployment/Wiring.java
    Tue Nov  2 12:01:02 2004
@@ -10,7 +10,7 @@
  * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
  * specific language governing permissions and limitations under the License.  
    *
  * 
=============================================================================== 
*/
-package org.apache.cocoon.kernel.runtime;
+package org.apache.cocoon.kernel.deployment;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Block.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Block.java
    (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Block.java
    Tue Nov  2 12:01:02 2004
@@ -13,19 +13,19 @@
 package org.apache.cocoon.kernel.description;
 
 import org.apache.cocoon.kernel.configuration.Configuration;
-import org.apache.cocoon.kernel.runtime.DeployerException;
+import org.apache.cocoon.kernel.deployment.DeployerException;
 
 /**
- * <p>A [EMAIL PROTECTED] Module} is a specialized implementation of a [EMAIL 
PROTECTED] Descriptor}
- * encloses an kernel interface descriptor in a bean-like object.</p>
+ * <p>A [EMAIL PROTECTED] Block} is a specialized implementation of a [EMAIL 
PROTECTED] Descriptor}
+ * encloseing a kernel block descriptor in a bean-like object.</p>
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
  * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
  *         Software Foundation</a>. All rights reserved.
  */
-public class Block extends Descriptor {
+public class Block extends ExtendingDescriptor {
 
-    /** <p>The name of the exposed Java interface.</p> */ 
+    /** <p>The name of the provided Java component.</p> */ 
     private String clazz = null;
     /** <p>The name (if any) of the initializer method.</p> */
     private String initializer = null;

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Descriptor.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Descriptor.java
       (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Descriptor.java
       Tue Nov  2 12:01:02 2004
@@ -20,7 +20,7 @@
 
 import org.apache.cocoon.kernel.configuration.Configuration;
 import org.apache.cocoon.kernel.configuration.ConfigurationException;
-import org.apache.cocoon.kernel.runtime.DeployerException;
+import org.apache.cocoon.kernel.deployment.DeployerException;
 
 /**
  * <p>A [EMAIL PROTECTED] Descriptor} encloses an XML descriptor in a 
bean-like object.</p>
@@ -39,14 +39,16 @@
     public static final int BLOCK = 1;
     /** <p>The type identifying an interface descriptor.</p> */
     public static final int INTERFACE = 2;
+    /** <p>The type identifying an plugin descriptor.</p> */
+    public static final int EXTENSION = 3;
 
     /** <p>The names associated with each descriptor type.</p> */
-    public static final String NAMES[] = new String [] {"module", "block", 
"interface"};
+    public static final String NAMES[] = new String [] {
+        "module", "block", "interface", "extension",
+    };
 
     /** <p>The array of libraries associated with this descriptor.</p> */ 
     private URL[] libraries = null;
-    /** <p>The array of identifiers of all extended blocks.</p> */
-    private Identifier[] extensions = null;
 
     /**
      * <p>Create a new [EMAIL PROTECTED] Descriptor} instance.</p>
@@ -96,10 +98,6 @@
         }
 
         this.libraries = (URL[]) collector.toArray(new URL[collector.size()]);
-
-        /* Extensions */
-        this.extensions = this.collectIdentifiers(configuration, "extensions",
-                                                  "extends", 
configuration.name());
     }
 
     /**
@@ -110,13 +108,6 @@
         return(this.libraries);
     }
 
-    /**
-     * <p>Return an array of all extended block identifers.</p>
-     */
-    public Identifier[] getExtendedBlocks() {
-        return(this.extensions);
-    }
-
     /* 
=========================================================================== */
     /* ABSTRACT METHODS                                                        
    */
     /* 
=========================================================================== */
@@ -126,43 +117,4 @@
      */
     public abstract int getType();
 
-    /* 
=========================================================================== */
-    /* PROTECTED METHODS                                                       
    */
-    /* 
=========================================================================== */
-
-    /**
-     * <p>Iterate through a given configuration trying to find the identifiers
-     * located in all element with a given name and in a specified 
attribute.</p>
-     * 
-     * @throws ConfigurationException if an element did not contain the 
attribute.
-     */
-    protected Identifier[] collectIdentifiers(Configuration configuration,
-            String parent, String element, String attribute)
-    throws DeployerException {
-
-        /* Check if we were given a parent element name */
-        if (parent != null) configuration = configuration.child(NAMESPACE, 
parent);
-
-        /* Prepare the iterator of all named children of the configuration */
-        Iterator iterator = configuration.children(NAMESPACE, element);
-        Set collector = new HashSet();
-
-        while (iterator.hasNext()) try {
-            configuration = (Configuration) iterator.next();
-            String identifier = configuration.getStringAttribute(attribute);
-            collector.add(new Identifier(identifier));
-
-        } catch (MalformedURLException exception) {
-            throw new DeployerException("Invalid identifier specified in 
descriptor "
-                    + configuration.location(), exception);
-
-        } catch (ConfigurationException exception) {
-            throw new DeployerException("Element <" + element + "/> does not "
-                    + "contain the required " + attribute + " attribute at "
-                    + configuration.location(), exception);
-        }
-
-        /* Return whatever we have collected */
-        return (Identifier[]) collector.toArray(new 
Identifier[collector.size()]);
-    }
 }

Added: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/ExtendingDescriptor.java
==============================================================================
--- (empty file)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/ExtendingDescriptor.java
      Tue Nov  2 12:01:02 2004
@@ -0,0 +1,97 @@
+/* 
=============================================================================== 
*
+ * Copyright (C) 1999-2004, The Apache Software Foundation.   All rights 
reserved. *
+ *                                                                             
    *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not 
use *
+ * this file except in  compliance with the License.  You may obtain a copy of 
the *
+ * License at <http://www.apache.org/licenses/LICENSE-2.0>.                    
    *
+ *                                                                             
    *
+ * Unless required by applicable law or agreed to in writing, software 
distributed *
+ * under the License  is distributed on an  "AS IS"  BASIS,  WITHOUT 
WARRANTIES OR *
+ * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
+ * specific language governing permissions and limitations under the License.  
    *
+ * 
=============================================================================== 
*/
+package org.apache.cocoon.kernel.description;
+
+import java.net.MalformedURLException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.cocoon.kernel.configuration.Configuration;
+import org.apache.cocoon.kernel.configuration.ConfigurationException;
+import org.apache.cocoon.kernel.deployment.DeployerException;
+
+/**
+ * <p>A [EMAIL PROTECTED] ExtendingDescriptor} defines a descriptor extending 
others.</p>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
+ * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
+ *         Software Foundation</a>. All rights reserved.
+ */
+public abstract class ExtendingDescriptor extends Descriptor {
+
+    /** <p>The array of identifiers of all extended blocks.</p> */
+    private Identifier[] extensions = null;
+
+    /**
+     * <p>Create a new [EMAIL PROTECTED] ExtendingDescriptor} instance.</p>
+     *
+     * @param configuration A [EMAIL PROTECTED] Configuration} object 
enclosing the XML data.
+     * @throws DeployerException If an error occurred processing the XML data.
+     */
+    protected ExtendingDescriptor(Configuration configuration)
+    throws DeployerException {
+        super(configuration);
+
+        /* Extensions */
+        this.extensions = this.collectIdentifiers(configuration, "extensions",
+                                                  "extends", 
configuration.name());
+    }
+
+    /**
+     * <p>Return an array of identifiers of all the extended descriptors.</p>
+     */
+    public Identifier[] getExtendedDescriptors() {
+        return(this.extensions);
+    }
+
+    /* 
=========================================================================== */
+    /* PROTECTED METHODS                                                       
    */
+    /* 
=========================================================================== */
+
+    /**
+     * <p>Iterate through a given configuration trying to find the identifiers
+     * located in all element with a given name and in a specified 
attribute.</p>
+     * 
+     * @throws ConfigurationException if an element did not contain the 
attribute.
+     */
+    protected Identifier[] collectIdentifiers(Configuration configuration,
+            String parent, String element, String attribute)
+    throws DeployerException {
+
+        /* Check if we were given a parent element name */
+        if (parent != null) configuration = configuration.child(NAMESPACE, 
parent);
+
+        /* Prepare the iterator of all named children of the configuration */
+        Iterator iterator = configuration.children(NAMESPACE, element);
+        Set collector = new HashSet();
+
+        while (iterator.hasNext()) try {
+            configuration = (Configuration) iterator.next();
+            String identifier = configuration.getStringAttribute(attribute);
+            collector.add(new Identifier(identifier));
+
+        } catch (MalformedURLException exception) {
+            throw new DeployerException("Invalid identifier specified in 
descriptor "
+                    + configuration.location(), exception);
+
+        } catch (ConfigurationException exception) {
+            throw new DeployerException("Element <" + element + "/> does not "
+                    + "contain the required " + attribute + " attribute at "
+                    + configuration.location(), exception);
+        }
+
+        /* Return whatever we have collected */
+        return (Identifier[]) collector.toArray(new 
Identifier[collector.size()]);
+    }
+}

Added: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Extension.java
==============================================================================
--- (empty file)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Extension.java
        Tue Nov  2 12:01:02 2004
@@ -0,0 +1,90 @@
+/* 
=============================================================================== 
*
+ * Copyright (C) 1999-2004, The Apache Software Foundation.   All rights 
reserved. *
+ *                                                                             
    *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not 
use *
+ * this file except in  compliance with the License.  You may obtain a copy of 
the *
+ * License at <http://www.apache.org/licenses/LICENSE-2.0>.                    
    *
+ *                                                                             
    *
+ * Unless required by applicable law or agreed to in writing, software 
distributed *
+ * under the License  is distributed on an  "AS IS"  BASIS,  WITHOUT 
WARRANTIES OR *
+ * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
+ * specific language governing permissions and limitations under the License.  
    *
+ * 
=============================================================================== 
*/
+package org.apache.cocoon.kernel.description;
+
+import org.apache.cocoon.kernel.configuration.Configuration;
+import org.apache.cocoon.kernel.deployment.DeployerException;
+
+/**
+ * <p>A [EMAIL PROTECTED] Extension} is a specialized implementation of a 
[EMAIL PROTECTED] Descriptor}
+ * enclosing kernel extension XML descriptor in a bean-like object.</p> 
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
+ * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
+ *         Software Foundation</a>. All rights reserved.
+ */
+public class Extension extends Descriptor {
+
+    /** <p>The name of the provided Java plugin.</p> */ 
+    private String clazz = null;
+    /** <p>The name (if any) of the initializer method.</p> */
+    private String initializer = null;
+    /** <p>The name (if any) of the destroyer method.</p> */
+    private String destroyer = null;
+
+    /**
+     * <p>Create a new [EMAIL PROTECTED] Extension} instance.</p>
+     */
+    public Extension(Configuration configuration)
+    throws DeployerException {
+        super(configuration);
+
+        /* Specific block stuff */
+        if (! NAMES[EXTENSION].equals(configuration.name())) {
+            throw new DeployerException("Invalid root element name for plugin "
+                    + " descriptor at " + configuration.location());
+        }
+
+        /* Plugin provision */
+        Configuration plugin = configuration.child(NAMESPACE, "plugin");
+        this.clazz = plugin.getStringAttribute("class", null);
+
+        /* No class? Abstract block, only libraries */
+        if (this.clazz == null) {
+            throw new DeployerException("Extension descriptor does not specify 
"
+                    + "  plugin class name at " + plugin.location());
+        }
+
+        /* Process initializer, destroyer, and singleton */
+        this.initializer = plugin.getStringAttribute("initialize", null);
+        this.destroyer = plugin.getStringAttribute("destroy", null);
+    }
+
+    /**
+     * <p>Return the class name of the provided Java&trade; class.</p>
+     */
+    public String getPlugin() {
+        return(this.clazz);
+    }
+
+    /**
+     * <p>Return the name of the metod to call at initialization.</p>
+     */
+    public String getPluginInitializer() {
+        return(this.initializer);
+    }
+
+    /**
+     * <p>Return the name of the metod to call at destruction.</p>
+     */
+    public String getPluginDestroyer() {
+        return(this.initializer);
+    }
+
+    /**
+     * <p>Return the type of this descriptor.</p>
+     */
+    public int getType() {
+        return Descriptor.BLOCK;
+    }
+}

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Identifier.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Identifier.java
       (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Identifier.java
       Tue Nov  2 12:01:02 2004
@@ -17,7 +17,7 @@
 import java.util.StringTokenizer;
 
 /**
- * <p>The [EMAIL PROTECTED] Identifier} class encloses a kernel descriptor 
identifier.</p> 
+ * <p>The [EMAIL PROTECTED] Identifier} class encloses a kernel 
identifier.</p> 
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
  * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Interface.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Interface.java
        (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Interface.java
        Tue Nov  2 12:01:02 2004
@@ -13,17 +13,17 @@
 package org.apache.cocoon.kernel.description;
 
 import org.apache.cocoon.kernel.configuration.Configuration;
-import org.apache.cocoon.kernel.runtime.DeployerException;
+import org.apache.cocoon.kernel.deployment.DeployerException;
 
 /**
  * <p>An [EMAIL PROTECTED] Interface} is a specialized implementation of a 
[EMAIL PROTECTED] Descriptor}
- * encloses an kernel interface descriptor in a bean-like object.</p>
+ * enclosing an kernel interface descriptor in a bean-like object.</p>
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
  * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
  *         Software Foundation</a>. All rights reserved.
  */
-public class Interface extends Descriptor {
+public class Interface extends ExtendingDescriptor {
 
     /** <p>The name of the exposed Java interface.</p> */ 
     private String clazz = null;

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Library.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Library.java
  (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Library.java
  Tue Nov  2 12:01:02 2004
@@ -123,9 +123,9 @@
         private int type = 0;
 
         private LibraryIterator(int type, Iterator iterator) {
-            if ((type == Descriptor.BLOCK) || (type == Descriptor.INTERFACE)) {
-                this.type = type;
-            } else {
+            try {
+                String name = Descriptor.NAMES[type];
+            } catch (Throwable throwable) {
                 throw new IllegalArgumentException("Invalid type " + type);
             }
             this.iterator = iterator;

Modified: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Module.java
==============================================================================
--- 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Module.java
   (original)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/description/Module.java
   Tue Nov  2 12:01:02 2004
@@ -13,17 +13,17 @@
 package org.apache.cocoon.kernel.description;
 
 import org.apache.cocoon.kernel.configuration.Configuration;
-import org.apache.cocoon.kernel.runtime.DeployerException;
+import org.apache.cocoon.kernel.deployment.DeployerException;
 
 /**
  * <p>A [EMAIL PROTECTED] Module} is a specialized implementation of a [EMAIL 
PROTECTED] Descriptor}
- * encloses an kernel interface descriptor in a bean-like object.</p>
+ * encloses an kernel module descriptor in a bean-like object.</p>
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
  * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
  *         Software Foundation</a>. All rights reserved.
  */
-public class Module extends Descriptor {
+public class Module extends ExtendingDescriptor {
 
     /**
      * <p>Create a new [EMAIL PROTECTED] Module} instance.</p>

Added: 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/plugins/Plugin.java
==============================================================================
--- (empty file)
+++ 
cocoon/whiteboard/kernel/sources/runtime/org/apache/cocoon/kernel/plugins/Plugin.java
       Tue Nov  2 12:01:02 2004
@@ -0,0 +1,24 @@
+/* 
=============================================================================== 
*
+ * Copyright (C) 1999-2004, The Apache Software Foundation.   All rights 
reserved. *
+ *                                                                             
    *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not 
use *
+ * this file except in  compliance with the License.  You may obtain a copy of 
the *
+ * License at <http://www.apache.org/licenses/LICENSE-2.0>.                    
    *
+ *                                                                             
    *
+ * Unless required by applicable law or agreed to in writing, software 
distributed *
+ * under the License  is distributed on an  "AS IS"  BASIS,  WITHOUT 
WARRANTIES OR *
+ * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
+ * specific language governing permissions and limitations under the License.  
    *
+ * 
=============================================================================== 
*/
+package org.apache.cocoon.kernel.plugins;
+
+/**
+ * <p>The [EMAIL PROTECTED] Plugin} interface identifies a.</p> 
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
+ * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
+ *         Software Foundation</a>. All rights reserved.
+ */
+public interface Plugin {
+
+}

Added: 
cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/KernelLoader.java
==============================================================================
--- (empty file)
+++ 
cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/KernelLoader.java
 Tue Nov  2 12:01:02 2004
@@ -0,0 +1,108 @@
+/* 
=============================================================================== 
*
+ * Copyright (C) 1999-2004, The Apache Software Foundation.   All rights 
reserved. *
+ *                                                                             
    *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not 
use *
+ * this file except in  compliance with the License.  You may obtain a copy of 
the *
+ * License at <http://www.apache.org/licenses/LICENSE-2.0>.                    
    *
+ *                                                                             
    *
+ * Unless required by applicable law or agreed to in writing, software 
distributed *
+ * under the License  is distributed on an  "AS IS"  BASIS,  WITHOUT 
WARRANTIES OR *
+ * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
+ * specific language governing permissions and limitations under the License.  
    *
+ * 
=============================================================================== 
*/
+package org.apache.cocoon.kernel.startup;
+
+import java.lang.reflect.Constructor;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * <p>TODO.</p> 
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
+ * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
+ *         Software Foundation</a>. All rights reserved.
+ */
+public class KernelLoader extends URLClassLoader {
+
+    /** <p>The deployer class name.</p> */
+    private static final String CLASS = 
"org.apache.cocoon.kernel.deployment.Deployer";
+    /** <p>The instance of the [EMAIL PROTECTED] Kernel} able to add URLs to 
this.</p> */
+    private StartupKernel kernel = null;
+    /** <p>A set of all known [EMAIL PROTECTED] URL}s to avoid 
duplications.</p> */
+    private Set urls = new HashSet();
+    
+    /** <p>Deny public construction.</p> */
+    private KernelLoader(ClassLoader loader, URL libraries[]) {
+        super(libraries, loader);
+        if (libraries == null) return;
+        for (int k = 0; k < libraries.length; k ++) urls.add(libraries[k]);
+    }
+
+    /**
+     * <p>Load a new [EMAIL PROTECTED] StartupKernel} instance.
+     */
+    protected static final StartupKernel load(URL library)
+    throws Throwable {
+        return KernelLoader.load(null, library);
+    }
+
+    /**
+     * <p>Load a new [EMAIL PROTECTED] StartupKernel} instance.
+     */
+    protected static final StartupKernel load(URL libraries[])
+    throws Throwable {
+        return KernelLoader.load(null, libraries);
+    }
+
+    /**
+     * <p>Load a new [EMAIL PROTECTED] StartupKernel} instance.
+     */
+    protected static final StartupKernel load(ClassLoader loader, URL library)
+    throws Throwable {
+        if (library == null) return KernelLoader.load(loader, new URL[0]);
+        return KernelLoader.load(loader, new URL [] { library });
+    }
+
+    /**
+     * <p>Load a new [EMAIL PROTECTED] StartupKernel} instance.
+     */
+    protected static final StartupKernel load(ClassLoader loader, URL 
libraries[])
+    throws Throwable {
+        if (loader == null) loader = 
Thread.currentThread().getContextClassLoader();
+        if (libraries == null) libraries = new URL[0];
+        KernelLoader kernel_loader = new KernelLoader(loader, libraries);
+
+        Class clazz = kernel_loader.loadClass(KernelLoader.CLASS);
+        Class signature[] = new Class [] { KernelLoader.class };
+        Constructor constructor = clazz.getConstructor(signature);
+        Object parameters[] = new Object [] { kernel_loader };
+
+        StartupKernel kernel = (StartupKernel) 
constructor.newInstance(parameters);
+        kernel_loader.kernel = kernel;
+
+        return(kernel); 
+    }
+    
+    /**
+     * <p>Add a [EMAIL PROTECTED] URL} to the class path handled by this 
[EMAIL PROTECTED] KernelLoader}
+     * instance.</p>
+     */
+    public void addURL(StartupKernel kernel, URL url) {
+        if (this.kernel != kernel) throw new SecurityException("Invalid 
instance");
+        if ((url == null) || (this.urls.contains(url))) return;
+        super.addURL(url);
+    }
+
+    /**
+     * <p>Add an array of [EMAIL PROTECTED] URL}s to the class path handled by 
this.</p>
+     * [EMAIL PROTECTED] KernelLoader} instance.</p>
+     */
+    public void addURL(StartupKernel kernel, URL urls[]) {
+        if (this.kernel != kernel) throw new SecurityException("Invalid 
instance");
+        if (urls == null) return;
+        for (int x = 0; x < urls.length; x ++) super.addURL(urls[x]);
+    }
+}

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 12:01:02 2004
@@ -12,10 +12,15 @@
  * 
=============================================================================== 
*/
 package org.apache.cocoon.kernel.startup;
 
+import java.io.File;
+import java.net.URL;
+
+import javax.sql.DataSource;
+
 import org.apache.cocoon.kernel.Kernel;
 import org.apache.cocoon.kernel.configuration.Configuration;
 import org.apache.cocoon.kernel.configuration.ConfigurationBuilder;
-import org.apache.cocoon.kernel.runtime.Deployer;
+import org.apache.cocoon.kernel.deployment.Deployer;
 
 /**
  * <p>A simple class initializing a [EMAIL PROTECTED] Kernel} from a the 
command line.</p> 
@@ -38,14 +43,17 @@
 public class Main implements Runnable {
 
     /** <p>The current [EMAIL PROTECTED] Deployer} instance.</p> */
-    private Deployer deployer = null;
+    private StartupKernel kernel = null;
 
     /**
      * <p>Create a new [EMAIL PROTECTED] Main} instance.</p>
      */
-    private Main(Deployer deployer) {
-        if (deployer == null) throw new NullPointerException("Null deployer");
-        this.deployer = deployer;
+    private Main(StartupKernel kernel) throws Throwable {
+        if (kernel == null) throw new NullPointerException("Null deployer");
+        this.kernel = kernel;
+        
+        DataSource ds = (DataSource)this.kernel.lookup("test");
+        ds.getConnection();
     }
     
     /**
@@ -53,7 +61,7 @@
      * configured [EMAIL PROTECTED] Deployer} instance before the JVM is 
terminated.</p>
      */
     public void run() {
-        this.deployer.destroy();
+        this.kernel.destroy();
     }
 
     /**
@@ -61,13 +69,14 @@
      */
     public static void main(String args[])
     throws Throwable {
-        if ((args.length < 1) || (args.length > 2)) { 
+        if ((args.length < 2) || (args.length > 3)) { 
             String name = Main.class.getName();
             System.err.println("Usage:");
-            System.err.println("    " + name + " <conf-file>");
-            System.err.println("  or");
-            System.err.println("    " + name + " <desc-file> <inst-file>");
+            System.err.println("  " + name + " <jar-file> <conf-file>");
+            System.err.println("or");
+            System.err.println("  " + name + " <jar-file> <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");
@@ -77,17 +86,17 @@
         }
 
         /* Parse the (possibly two) configurations */
-        Configuration descriptors = ConfigurationBuilder.parse(args[0]);
-        Configuration instances = (args.length == 1 ? descriptors : 
-                ConfigurationBuilder.parse(args[0]));
+        Configuration descriptors = ConfigurationBuilder.parse(args[1]);
+        Configuration instances = (args.length == 2 ? descriptors : 
+                ConfigurationBuilder.parse(args[2]));
         
         /* Create and initialize a new deployer */
-        
Thread.currentThread().setContextClassLoader(Main.class.getClassLoader());
-        Deployer deployer = new Deployer();
-        deployer.initialize(descriptors, instances);
+        URL library = new File(args[0]).toURL();
+        StartupKernel kernel = KernelLoader.load(library);
+        kernel.initialize(descriptors, instances);
 
         /* Add the shutdown hook */
-        Runtime.getRuntime().addShutdownHook(new Thread(new Main(deployer)));
+        Runtime.getRuntime().addShutdownHook(new Thread(new Main(kernel)));
 
         /* 
          * If non-daemon threads are still running, this thread will siply 
exit but

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 12:01:02 2004
@@ -23,8 +23,8 @@
 import org.apache.cocoon.kernel.Kernel;
 import org.apache.cocoon.kernel.configuration.Configuration;
 import org.apache.cocoon.kernel.configuration.ConfigurationBuilder;
-import org.apache.cocoon.kernel.runtime.Deployer;
-import org.apache.cocoon.kernel.runtime.Wiring;
+import org.apache.cocoon.kernel.deployment.Deployer;
+import org.apache.cocoon.kernel.deployment.Wiring;
 
 /**
  * <p>The [EMAIL PROTECTED] ServletLoader} is a [EMAIL PROTECTED] 
ServletContextListener} managing the
@@ -34,7 +34,7 @@
  * looking for the <code>&quot;org.apache.cocoon.kernel.Kernel&quot;</code>
  * [EMAIL PROTECTED] #ATTRIBUTE attribute} in their [EMAIL PROTECTED] 
ServletContext}.</p>
  *
- * <p>The initialization of the kernel is dependant on three context 
initialization
+ * <p>The initialization of the kernel is dependant on four context 
initialization
  * parameters:</p>
  * 
  * <ul>
@@ -51,6 +51,12 @@
  *   <li><code>kernel-instances</code>: an instances deployer document.</li>
  * </ul>
  *     
+ * <p>and:</p>
+ * 
+ * <ul>
+ *   <li><code>kernel-library</code>: the library containing the kernel 
code.</li>
+ * </ul>
+ *
  * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
  * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
  *         Software Foundation</a>. All rights reserved.
@@ -64,13 +70,13 @@
     public static final String ATTRIBUTE = "org.apache.cocoon.kernel.Kernel";
 
     /** <p>The current [EMAIL PROTECTED] Deployer} instance.</p> */
-    Deployer deployer = null;
+    StartupKernel kernel = null;
 
     /**
      * <p>Create a new [EMAIL PROTECTED] ServletLoader} instance.</p>
      */
     public ServletLoader() {
-        this.deployer = new Deployer();
+        super();
     }
 
     /**
@@ -79,33 +85,49 @@
     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");
         
-        /* Parse the (possibly two) configurations and initialize the deployer 
*/
+        /* Load and initialize the kernel */
         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);
+
+            /* Parse the (possibly two) configurations and initialize the 
deployer */
             if (configuration != null) {
                 URL configuration_url = context.getResource(configuration);
                 Configuration conf = 
ConfigurationBuilder.parse(configuration_url);
-                this.deployer.initialize(conf);
+                this.kernel.initialize(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.deployer.initialize(desc, inst);
+                this.kernel.initialize(desc, inst);
             }
         } catch (Throwable t) {
             context.log("Unable to intialize kernel", t);
             throw new RuntimeException("Unable to initialize kernel", t);
         }
 
-        /* Make the kernel available to the servlet loader */
+        /* Make the kernel available through the servlet context */
         ClassLoader loader = this.getClass().getClassLoader();
         Class interfaces[] = new Class[] { Kernel.class };
-        Wiring wiring = new Wiring(this.deployer);
+        Wiring wiring = new Wiring(this.kernel);
         Kernel kernel = (Kernel) Proxy.newProxyInstance(loader, interfaces, 
wiring);
         context.setAttribute(ServletLoader.ATTRIBUTE, kernel);
     }
@@ -115,14 +137,14 @@
      */
     public void contextDestroyed(ServletContextEvent event) {
         ServletContext context = event.getServletContext();
-        context.removeAttribute("KERNEL");
+        context.removeAttribute(ServletLoader.ATTRIBUTE);
         try {
-            this.deployer.destroy();
+            this.kernel.destroy();
         } catch (Throwable t) {
             context.log("Unable to intialize destroy", t);
             throw new RuntimeException("Unable to destroy kernel", t);
         } finally {
-            this.deployer = null;
+            this.kernel = null;
         }
     }
 }

Added: 
cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/StartupKernel.java
==============================================================================
--- (empty file)
+++ 
cocoon/whiteboard/kernel/sources/startup/org/apache/cocoon/kernel/startup/StartupKernel.java
        Tue Nov  2 12:01:02 2004
@@ -0,0 +1,48 @@
+/* 
=============================================================================== 
*
+ * Copyright (C) 1999-2004, The Apache Software Foundation.   All rights 
reserved. *
+ *                                                                             
    *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not 
use *
+ * this file except in  compliance with the License.  You may obtain a copy of 
the *
+ * License at <http://www.apache.org/licenses/LICENSE-2.0>.                    
    *
+ *                                                                             
    *
+ * Unless required by applicable law or agreed to in writing, software 
distributed *
+ * under the License  is distributed on an  "AS IS"  BASIS,  WITHOUT 
WARRANTIES OR *
+ * CONDITIONS  OF ANY KIND,  either express  or implied.  See the License  for 
the *
+ * specific language governing permissions and limitations under the License.  
    *
+ * 
=============================================================================== 
*/
+package org.apache.cocoon.kernel.startup;
+
+import org.apache.cocoon.kernel.Kernel;
+import org.apache.cocoon.kernel.configuration.Configuration;
+
+/**
+ * <p>TODO.</p> 
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
+ * @author Copyright &copy; 2000-2004 <a href="http://www.apache.org/";>The 
Apache
+ *         Software Foundation</a>. All rights reserved.
+ */
+public interface StartupKernel extends Kernel {
+
+    /**
+     * <p>Initialize this deployer using the specified [EMAIL PROTECTED] 
Configuration}.</p>
+     * 
+     * @param configuration A [EMAIL PROTECTED] Configuration} containing 
descriptors locations
+     *                      and block instances.
+     */
+    public void initialize(Configuration configuration);
+
+    /**
+     * <p>Initialize this deployer using the specified [EMAIL PROTECTED] 
Configuration}s.</p>
+     * 
+     * @param descriptors A [EMAIL PROTECTED] Configuration} containing 
descriptors locations.
+     * @param instances A [EMAIL PROTECTED] Configuration} containing block 
instances.
+     */
+    public void initialize(Configuration descriptors, Configuration instances);
+
+    /**
+     * <p>Destroy this deployer and all block instances.</p>
+     */
+    public void destroy();
+
+}

Reply via email to