net.jbeans.bean.factory
Class FactoryManager

java.lang.Object
  extended bynet.jbeans.bean.factory.FactoryManager

public class FactoryManager
extends java.lang.Object

The FactoryManager can be used to locate a factory class for any given class or class name. This factory class must support the net.jbeans.bean.factory.Factory interface for creating an instance of a given class.

The FactoryManager uses three techniques for locating a factory for a given type. First, it provides a registerFactory method to allow a factory to be specifically registered for a given type. Second it tries to locate a suitable class by adding "Factory" to the full qualified classname of the given type (e.g. "foo.bah.FozFactory"). Finally it takes the simple classname (without the package name) adds "Factory" to it and looks in a search-path of packages for a matching class.

So for an input class foo.bah.Fred, the FactoryManager would first look in its tables to see if a factory had been registered for foo.bah.Fred and if so use that. Then it will look for a foo.bah.FredFactory class. Then it will look for (say) standardFactoryPackage.FredFactory class.

Version:
$Revision: 1.1.1.1 $
Author:
Masahiro Takatsuka (masa@jbeans.net)

Constructor Summary
FactoryManager()
           
 
Method Summary
static Factory findFactory(java.lang.Class targetType)
          Locate a value editor for a given target type.
static java.lang.String[] getEditorSearchPath()
          Gets the package names that will be searched for factories.
static void registerFactory(java.lang.Class targetType, java.lang.Class factoryClass)
          Register a factory to be used to instantiate an object of a given target class.
static void setFactorySearchPath(java.lang.String[] path)
          Change the list of package names that will be used for finding factories.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FactoryManager

public FactoryManager()
Method Detail

registerFactory

public static void registerFactory(java.lang.Class targetType,
                                   java.lang.Class factoryClass)
Register a factory to be used to instantiate an object of a given target class.

Parameters:
targetType - the Class object of the type to be instantiated
factoryClass - the Class object of the factory class. If this is null, then any existing definition will be removed.

findFactory

public static Factory findFactory(java.lang.Class targetType)
Locate a value editor for a given target type.

Parameters:
targetType - The Class object for the type to be edited
Returns:
An editor object for the given target class. The result is null if no suitable editor can be found.

getEditorSearchPath

public static java.lang.String[] getEditorSearchPath()
Gets the package names that will be searched for factories.

Returns:
The array of package names that will be searched in order to find factories.

This is initially set to {"net.jbeans.bean.factory"}.


setFactorySearchPath

public static void setFactorySearchPath(java.lang.String[] path)
Change the list of package names that will be used for finding factories.

Parameters:
path - Array of package names.


Copyright © 2003 JBean project. All Rights Reserved.