You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/03/08 16:28:16 UTC
cvs commit: avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/impl DefaultKernelLoader.java KernelLoader.java
mcconnell 2003/03/08 07:28:16
Added: merlin/src/java/org/apache/avalon/merlin/kernel/impl
DefaultKernelLoader.java
Removed: merlin/src/java/org/apache/avalon/merlin/kernel/impl
KernelLoader.java
Log:
KernelLoader moved to DefaultKernelLoader.
Revision Changes Path
1.1 avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernelLoader.java
Index: DefaultKernelLoader.java
===================================================================
package org.apache.avalon.merlin.kernel.impl;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.util.Enumeration;
import java.util.List;
import java.util.Iterator;
import java.util.jar.JarFile;
import java.util.ArrayList;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.net.URLClassLoader;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.net.MalformedURLException;
import java.net.JarURLConnection;
import org.xml.sax.SAXException;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.merlin.block.Block;
import org.apache.avalon.merlin.block.BlockException;
import org.apache.avalon.assembly.util.ExceptionHelper;
import org.apache.avalon.assembly.locator.Contextualizable;
import org.apache.avalon.assembly.locator.DefaultLocator;
import org.apache.avalon.assembly.locator.Locator;
import org.apache.avalon.merlin.kernel.Kernel;
import org.apache.avalon.merlin.kernel.KernelLoader;
import org.apache.avalon.merlin.kernel.KernelException;
import org.apache.avalon.merlin.kernel.KernelRuntimeException;
/**
* The DefaultKernelLoader provides support for the establishment of a kernel
* instance assuming a file system deployment environment.
*
* @see Kernel
* @see KernelLoader
* @see DefaultKernel
*/
public class DefaultKernelLoader
{
/**
* Creation of a new Kernel instance. Arguments passed
* passed to the kernel build operation are detailed in the following
* table.
*
* <table BORDER="1" CELLSPACING="0" CELLPADDING="3" WIDTH="90%" >
* <tr BGCOLOR="#EEEEFF">
* <td><b>key</b></td><td><b>type</b></td><td><b>description</b></td>
* </tr>
* <tr>
* <td><code>urn:merlin:home</code></td>
* <td>{@link java.io.File}</td>
* <td>The working home directory.</td>
* </tr>
* <tr>
* <td><code>urn:merlin:system</code></td>
* <td>{@link java.io.File}</td>
* <td>The Merlin system directory.</td>
* </tr>
* <tr>
* <td><code>urn:merlin:classloader.common</code></td>
* <td>{@link java.lang.ClassLoader}</td>
* <td>The shared classloader.</td>
* </tr>
* <tr>
* <td><code>urn:merlin:classloader.system</code></td>
* <td>{@link java.lang.ClassLoader}</td>
* <td>The Merlin internal classloader.</td>
* </tr>
* <tr>
* <td><code>urn:merlin:debug</code></td>
* <td>{@link java.lang.String}</td>
* <td>An optional system logging priority (a value of INFO, WARN, ERROR, or DEBUG) to
* be used for internal Merlin execution.</td>
* </tr>
* </table>
*
* @param map a map of initialization arguments
* @return the kernel instance
*/
public Kernel build( Map map ) throws KernelException
{
//
// get the kernel configuration profile
//
File profile = (File) map.get( "urn:merlin:kernel.profile" );
//
// contextualize, configure, initialize and start the kernel
//
Throwable cause = null;
DefaultLocator context = new DefaultLocator( map );
context.makeReadOnly();
DefaultKernel kernel = null;
try
{
kernel = new DefaultKernel();
kernel.contextualize( context );
kernel.configure( getKernelConfiguration( profile ) );
kernel.initialize();
}
catch( KernelException e )
{
// its already been logged
cause = e;
}
catch( BlockException e )
{
// its already been logged
cause = e;
}
catch( Throwable e )
{
final String error = "Unexpected kernel deployment failure.";
String message = ExceptionHelper.packException( error, e );
System.err.println( message );
cause = new Exception( error );
}
finally
{
if( cause != null )
{
throw new KernelException( "Kernel error.", cause );
}
else
{
return kernel;
}
}
}
private Configuration getKernelConfiguration( final File file )
throws ConfigurationException, IOException, SAXException
{
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
InputStream is = new FileInputStream( file );
if( is == null )
{
throw new IOException(
"Could not load kernel configuration resource \"" + file + "\"" );
}
return builder.build( is );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org