org.backsource.utils.lang
Class Factory

java.lang.Object
  extended byorg.backsource.utils.lang.Factory
Direct Known Subclasses:
CachedStreamFactory

public class Factory
extends java.lang.Object

A baseclass or helper to make it easier to create factories following the JAXP pattern; but with more configuration options.

The normal pattern is to have an abstract factory through which an implementing factory is obtainable through the newInstance() method. The implementing factory then has a method implementation to get the class the factory is meant to be able to produce. This class helps in defining the behaviour that is used by the abstract factory to lookup the implementing factory.

Factories that uses this class to implement its factory handling must either inherit from this class or demand that the implementing factories have default constructors with public access.

Version:
$Revision: 1.1.1.1 $
Author:
Peter Antman

Constructor Summary
Factory()
           
 
Method Summary
static java.lang.Object findInstance(java.lang.String key, java.util.Properties env, java.lang.String defaultClass, boolean reverseOrder)
          Find and instantiate an implementing factory.
static java.lang.String getProperty(java.lang.String prop)
          The property is not null only if it is not null, and has a length of > 0 after its been trimed;
static java.lang.String jarService(java.lang.ClassLoader cl, java.lang.String key, boolean reverseOrder)
          Lookup the resource META-INF/services/key where key is the name of the property file to look for.
static java.lang.String jarService(java.lang.String key, boolean reverseOrder)
          Lookup the resource META-INF/services/key where key is the name of the property file to look for.
static java.util.List list(java.util.Enumeration e)
          Implement the jdk 1.4.1 Collection list behaviour.
static java.lang.Object newInstance(java.lang.String className)
          Load the given classname from the thread context classloader, or Class.forName if no context loader was found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Factory

public Factory()
Method Detail

findInstance

public static java.lang.Object findInstance(java.lang.String key,
                                            java.util.Properties env,
                                            java.lang.String defaultClass,
                                            boolean reverseOrder)
                                     throws java.lang.ClassNotFoundException
Find and instantiate an implementing factory. The following search order is used:

The reverse order mechanism makes it possible to specify component specific factory configurations in environments which deploys components int their owne classloader.

Parameters:
key - the property name of the factory; the normal pattern is to use the fully qualified classname of the abstract factory.
env - a possibly null Properties that contains a locally given value for key.
defaultClass - the default class to load if no configuration is found.
reverseOrder - in reverse order the service API will be used before any System properties are checked; and the resource file will be searched in leaf class loader order first.
Throws:
java.lang.ClassNotFoundException - if not default or property was found to create the factory or if the configured factory was not available in the classpath.
java.lang.IllegalArgumentException - thrown if key is null.
java.lang.IllegalStateException - if no configuration was found and defaultClass was also null.

getProperty

public static java.lang.String getProperty(java.lang.String prop)
The property is not null only if it is not null, and has a length of > 0 after its been trimed;


newInstance

public static java.lang.Object newInstance(java.lang.String className)
                                    throws java.lang.ClassNotFoundException
Load the given classname from the thread context classloader, or Class.forName if no context loader was found.

Parameters:
className - the fully qualified name of the class to load.
Throws:
java.lang.ClassNotFoundException - if it was not possible to load the given class or if it was null.

jarService

public static java.lang.String jarService(java.lang.String key,
                                          boolean reverseOrder)
Lookup the resource META-INF/services/key where key is the name of the property file to look for.

The context classloader is searched first and if the service property was not found the classloader of this class is used.

Parameters:
key - the name of the resource/property.
reverseOrder - if true return the last resource in the enumeration returned by getResource.
Returns:
the value of the service resource or null of not found.

jarService

public static java.lang.String jarService(java.lang.ClassLoader cl,
                                          java.lang.String key,
                                          boolean reverseOrder)
Lookup the resource META-INF/services/key where key is the name of the property file to look for.

Parameters:
cl - the classloader to use to lookup the resource.
key - the name of the resource/property.
reverseOrder - if true return the last resource in the enumeration returned by getResource.
Returns:
the value of the service resource or null of not found.

list

public static java.util.List list(java.util.Enumeration e)
Implement the jdk 1.4.1 Collection list behaviour.



Copyright © 2000-2004 Backsource. All Rights Reserved.