com.werken.forehead
Class Forehead

java.lang.Object
  extended by com.werken.forehead.Forehead

public class Forehead
extends java.lang.Object

ClassLoader configurator and application launcher.

This is the main command-line entry-point into the forehead framework. Please see the forehead documentation for usage instructions.

Author:
bob mcwhirter

Field Summary
private  java.util.Map classLoaders
          ClassLoaders indexed by name.
private  java.lang.Class entryClass
          The entry-point class.
private  ForeheadClassLoader entryLoader
          The loader to use for entry-point lookup.
private  java.lang.reflect.Method entryMethod
          The entry-point method.
private static Forehead INSTANCE
          Singleton.
private  ForeheadClassLoader rootLoader
          Root unnamed loader.
 
Constructor Summary
Forehead()
          Construct.
 
Method Summary
 void config(java.io.BufferedReader in)
          Configure from an BufferedReader.
 void config(java.io.InputStream in)
          Configure from an InputStream.
 void config(java.io.Reader in)
          Configure from an Reader.
protected  ForeheadClassLoader createClassLoader(ForeheadClassLoader parent, java.lang.String name)
          Create a new ClassLoader given a parent and a name.
 ForeheadClassLoader getClassLoader(java.lang.String name)
          Retrieve a ClassLoader by name.
static Forehead getInstance()
           
protected  void load(java.lang.String line, ForeheadClassLoader loader)
          Load a glob, file, or URL into the specified classloader.
protected  void loadFileOrUrl(java.lang.String line, ForeheadClassLoader loader)
          Load a file or URL into the specified classloader.
protected  void loadGlob(java.lang.String line, ForeheadClassLoader loader)
          Load a glob into the specified classloader.
static void main(java.lang.String[] args)
          Main.
 java.lang.String resolveProperties(java.lang.String input, java.util.Properties props)
          Resolve imported properties.
 void run(java.lang.String[] args)
          Launch the wrapped application.
protected  void setupEntry(java.lang.String line)
          Setup the entry-point.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

private static final Forehead INSTANCE
Singleton.


classLoaders

private java.util.Map classLoaders
ClassLoaders indexed by name.


rootLoader

private ForeheadClassLoader rootLoader
Root unnamed loader.


entryLoader

private ForeheadClassLoader entryLoader
The loader to use for entry-point lookup.


entryClass

private java.lang.Class entryClass
The entry-point class.


entryMethod

private java.lang.reflect.Method entryMethod
The entry-point method.

Constructor Detail

Forehead

public Forehead()
Construct.

Method Detail

config

public void config(java.io.InputStream in)
            throws ForeheadException,
                   java.io.IOException,
                   java.lang.ClassNotFoundException
Configure from an InputStream.

Parameters:
in - InputStream carrying configuration information.
Throws:
ForeheadException - If there is an error during configuration.
java.io.IOException - If there is an error reading configuration information.
java.lang.ClassNotFoundException - If unable to locate entry-point class.

config

public void config(java.io.Reader in)
            throws ForeheadException,
                   java.io.IOException,
                   java.lang.ClassNotFoundException
Configure from an Reader.

Parameters:
in - Reader carrying configuration information.
Throws:
ForeheadException - If there is an error during configuration.
java.io.IOException - If there is an error reading configuration information.
java.lang.ClassNotFoundException - If unable to locate entry-point class.

config

public void config(java.io.BufferedReader in)
            throws ForeheadException,
                   java.io.IOException,
                   java.lang.ClassNotFoundException
Configure from an BufferedReader.

Parameters:
in - BufferedReader carrying configuration information.
Throws:
ForeheadException - If there is an error during configuration.
java.io.IOException - If there is an error reading configuration information.
java.lang.ClassNotFoundException - If unable to locate entry-point class.

setupEntry

protected void setupEntry(java.lang.String line)
                   throws MalformedEntryDescriptorException,
                          NoSuchClassLoaderException,
                          java.lang.ClassNotFoundException
Setup the entry-point.

Parameters:
line - The entry-point configuration line.
Throws:
MalformedEntryDescriptorException - If the entry-point descriptor is malformed.
NoSuchClassLoaderException - If the entry-point descriptor references an unknown ClassLoader.
java.lang.ClassNotFoundException - If unable to locate the entry-point class.

load

protected void load(java.lang.String line,
                    ForeheadClassLoader loader)
             throws java.net.MalformedURLException
Load a glob, file, or URL into the specified classloader.

Parameters:
line - The path configuration line.
loader - The loader to populate
Throws:
java.net.MalformedURLException - If the line does not represent a valid path element.

loadGlob

protected void loadGlob(java.lang.String line,
                        ForeheadClassLoader loader)
                 throws java.net.MalformedURLException
Load a glob into the specified classloader.

Parameters:
line - The path configuration line.
loader - The loader to populate
Throws:
java.net.MalformedURLException - If the line does not represent a valid path element.

loadFileOrUrl

protected void loadFileOrUrl(java.lang.String line,
                             ForeheadClassLoader loader)
                      throws java.net.MalformedURLException
Load a file or URL into the specified classloader.

Parameters:
line - The path configuration line.
loader - The loader to populate
Throws:
java.net.MalformedURLException - If the line does not represent a valid path element.

createClassLoader

protected ForeheadClassLoader createClassLoader(ForeheadClassLoader parent,
                                                java.lang.String name)
Create a new ClassLoader given a parent and a name.

Parameters:
parent - The parent of the ClassLoader to create.
name - The name of the ClassLoader to create.
Returns:
A newly configured ClassLoader.

getClassLoader

public ForeheadClassLoader getClassLoader(java.lang.String name)
Retrieve a ClassLoader by name.

Parameters:
name - The name of the ClassLoader to retrieve.
Returns:
The associated ClassLoader, or null if none.

resolveProperties

public java.lang.String resolveProperties(java.lang.String input,
                                          java.util.Properties props)
Resolve imported properties.

Parameters:
input - The string input to resolve properties.
props - Properties to resolve against.
Returns:
The string with properties resolved.

run

public void run(java.lang.String[] args)
         throws NoSuchEntryMethodException,
                java.lang.IllegalAccessException,
                java.lang.reflect.InvocationTargetException
Launch the wrapped application.

Parameters:
args - Command-line args to pass to wrapped application.
Throws:
NoSuchEntryMethodException - If unable to find the entry method on the class.
java.lang.IllegalAccessException - If an error occurs while attempting to invoke the entry-point method.
java.lang.reflect.InvocationTargetException - If an error occurs while attempting to invoke the entry-point method.

getInstance

public static Forehead getInstance()

main

public static void main(java.lang.String[] args)
Main.

Parameters:
args - Command-line arguments to pass to the wrapped application.