org.geotools.factory
Class FactoryFinder

java.lang.Object
  extended byorg.geotools.factory.FactoryFinder

Deprecated. The proposed replacement is FactoryRegistry, which is built on top of a J2SE class (ServiceRegistry). Guidlines are provided in the org.geotools.factory package description.

public final class FactoryFinder
extends java.lang.Object

This code was mostly spiked from SAXParserFactory, which I know runs in applets. The former way of doing things was to use System.getProperty, which cause security problems. Because EVERYTHING in geotools uses factories, I thought, "hey, we should make a class for this, or something". The other problem was using the ServiceProvider thing from sun, BUT THIS COMPLETELY VIOLATES ALL THE PRINCIPLES OF MAKING OUR CODE JVM INDEPENDENT!!!!!!!!!!! This package works the same way.
The mechanism for finding factories (which must implement Factory) is as follows:

 
  1. Look up key in System properties. If key doesn't exist or a SecurityException is thrown, fall through. Otherwise attempt to instantiate the given class.
  2. Search the resource paths for the key in META-INF/services. If the resource is found, the file is read and the class is instantiated. If the resource does not exist, fall through
  3. Finally, each call to findFactory must provide a default implementation class name. If this class is found, it is instantiated and used. If not, a grave error is thrown (FactoryConfigurationError).
The ClassLoader used to search for resources can be specfied, and if not provided, the search mechanism uses first Thread.getContextClassLoader and then falls back on the system ClassLoader.

Version:
$Id: FactoryFinder.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Ian Schneider

Method Summary
static java.util.Iterator factories(java.lang.Class key)
          Deprecated. A convenience method for factories(key,null).
static java.util.Iterator factories(java.lang.Class key, java.lang.ClassLoader loader)
          Deprecated. Obtain an Iterator of Factory Objects which are found using the given key.
static java.lang.ClassLoader[] findClassLoaders()
          Deprecated. Returns the context class loaded (if available) as well as the system class loader.
static Factory findFactory(java.lang.String factoryKey, java.lang.String defaultImpl)
          Deprecated. A convienience method for calling findFactory(factoryKey,defaultImpl,null).
static Factory findFactory(java.lang.String factoryKey, java.lang.String defaultImpl, java.lang.ClassLoader classLoader)
          Deprecated. Find a Factory using the given key, the given default backup implementation, and the specified ClassLoader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

findClassLoaders

public static java.lang.ClassLoader[] findClassLoaders()
Deprecated. 
Returns the context class loaded (if available) as well as the system class loader.


findFactory

public static Factory findFactory(java.lang.String factoryKey,
                                  java.lang.String defaultImpl,
                                  java.lang.ClassLoader classLoader)
                           throws FactoryConfigurationError,
                                  java.lang.ClassCastException
Deprecated. 
Find a Factory using the given key, the given default backup implementation, and the specified ClassLoader. If the ClassLoader is null, the ClassLoader will be assigned using the search mechanism discussed above.

Parameters:
factoryKey - The key to search for an implementation with.
defaultImpl - The name of a default implementation to use.
classLoader - The ClassLoader to search in. May be null.
Returns:
A Factory object.
Throws:
FactoryConfigurationError - If the given arguments do not yield a findable, instantiable Factory.
java.lang.ClassCastException - If the given arguments yield an Object which is not a Factory

findFactory

public static Factory findFactory(java.lang.String factoryKey,
                                  java.lang.String defaultImpl)
                           throws FactoryConfigurationError,
                                  java.lang.ClassCastException
Deprecated. 
A convienience method for calling findFactory(factoryKey,defaultImpl,null).

Parameters:
factoryKey - The key to search for an implementation with.
defaultImpl - The name of a default implementation to use.
Returns:
A Factory object.
Throws:
FactoryConfigurationError - If the given arguments do not yield a findable, instantiable Factory.
java.lang.ClassCastException - If the given arguments yield an Object which is not a Factory

factories

public static java.util.Iterator factories(java.lang.Class key)
Deprecated. 
A convenience method for factories(key,null).

Parameters:
key - The key to search with. The actual key to search with will be key.getName().
Returns:
An Iterator of Factory objects. May have no entries.

factories

public static java.util.Iterator factories(java.lang.Class key,
                                           java.lang.ClassLoader loader)
Deprecated. 
Obtain an Iterator of Factory Objects which are found using the given key. This is a replacement for the sun.misc.Service class, and can be used to implement a service provider architecture.

Parameters:
key - The key to search with. The actual key to search with will be key.getName().
loader - The ClassLoader to search for resources with.
Returns:
An Iterator of Factory objects. May have no entries.


Copyright © GeoTools. All Rights Reserved.