org.extex.framework
Class AbstractFactory

java.lang.Object
  extended by org.extex.framework.AbstractFactory
All Implemented Interfaces:
Configurable, LogEnabled, RegistrarObserver, ResourceAware
Direct Known Subclasses:
BackendFactory, BaseLanguageManager, ColorConverterFacory, ContextFactory, DocumentWriterFactory, ErrorHandlerFactory, FontFactoryImpl, FontKeyFactory, InterpreterFactory, LanguageManagerFactory, LoaderFactory, LoadUnit, NativeDef.Factory, OutputFactory, OutputRoutineFactory, TokenFactoryFactory, TokenFactoryFactory, TokenStreamFactory, TypesetterFactory, TypesettingContextFactory, UnitInfoFactory

public abstract class AbstractFactory
extends java.lang.Object
implements Configurable, LogEnabled, ResourceAware, RegistrarObserver

This is the abstract base class for factories. It contains some common methods which should make it easy to create a custom factory.

The abstract factory supports utility events:

Version:
$Revision: 7197 $
Author:
Gerd Neugebauer

Field Summary
protected static java.lang.String CLASS_ATTRIBUTE
          The constant CLASS_ATTRIBUTE contains the name of the attribute used to get the class name.
protected static java.lang.String DEFAULT_ATTRIBUTE
          The constant DEFAULT_ATTRIBUTE contains the name of the attribute used to get the default configuration.
protected static java.lang.String SELECT_ATTRIBUTE
          The constant SELECT_ATTRIBUTE contains the name of the attribute used to get the default configuration.
 
Constructor Summary
AbstractFactory()
          Creates a new factory object.
AbstractFactory(Configuration configuration)
          Creates a new factory object.
 
Method Summary
 void configure(Configuration configuration)
          Configure an object according to a given Configuration.
static void configure(java.lang.Object instance, Configuration configuration)
          Configure an instance if this instance supports configuration.
protected  java.lang.Object createInstance(java.lang.Class<?> target)
          Get an instance.
protected  java.lang.Object createInstance(java.lang.Class<?> target, java.lang.Object arg)
          Get a new instance.
protected  java.lang.Object createInstance(java.lang.String type, java.lang.Class<?> target)
          Create a new instance for a given configuration with an additional argument for the constructor.
protected  java.lang.Object createInstance(java.lang.String type, java.lang.Class<?> target, java.lang.Class<?> argClass, java.lang.Object arg)
          Create a new instance for a given configuration with an additional argument for the constructor.
protected  java.lang.Object createInstanceForConfiguration(Configuration config, java.lang.Class<?> target)
          Create a new instance for a given configuration.
protected  java.lang.Object createInstanceForConfiguration(Configuration config, java.lang.Class<?> target, java.lang.Class<?> argClass, java.lang.Object arg)
          Create a new instance for a given configuration with an additional argument for the constructor.
protected  java.lang.Object createInstanceForConfiguration(Configuration config, java.lang.Class<?> target, java.lang.Object arg)
          Create a new instance for a given configuration.
 void enableLogging(java.util.logging.Logger theLogger)
          Setter for the logger.
static void enableLogging(java.lang.Object instance, java.util.logging.Logger logger)
          Utility method to pass a logger to an object if it has a method to take it.
 Configuration getConfiguration()
          Getter for configuration.
 java.util.logging.Logger getLogger()
          Getter for logger.
 ResourceFinder getResourceFinder()
          Getter for resourceFinder.
 java.lang.Object reconnect(java.lang.Object instance)
          Reconnect an object.
protected  Configuration selectConfiguration(java.lang.String type)
          Select a sub-configuration with a given name.
 void setResourceFinder(ResourceFinder finder)
          Setter for the resource finder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_ATTRIBUTE

protected static final java.lang.String CLASS_ATTRIBUTE
The constant CLASS_ATTRIBUTE contains the name of the attribute used to get the class name.

See Also:
Constant Field Values

DEFAULT_ATTRIBUTE

protected static final java.lang.String DEFAULT_ATTRIBUTE
The constant DEFAULT_ATTRIBUTE contains the name of the attribute used to get the default configuration.

See Also:
Constant Field Values

SELECT_ATTRIBUTE

protected static final java.lang.String SELECT_ATTRIBUTE
The constant SELECT_ATTRIBUTE contains the name of the attribute used to get the default configuration.

See Also:
Constant Field Values
Constructor Detail

AbstractFactory

public AbstractFactory()
Creates a new factory object.


AbstractFactory

public AbstractFactory(Configuration configuration)
Creates a new factory object.

Parameters:
configuration - the configuration object to consider
Method Detail

configure

public static void configure(java.lang.Object instance,
                             Configuration configuration)
                      throws ConfigurationException
Configure an instance if this instance supports configuration. If configuration is not supported then nothing is done.

Parameters:
instance - the instance to configure
configuration - the configuration to use. If this parameter is null then it is not passed to the instance.
Throws:
ConfigurationException - in case of an error

enableLogging

public static void enableLogging(java.lang.Object instance,
                                 java.util.logging.Logger logger)
Utility method to pass a logger to an object if it has a method to take it. If the logger is null then this method simply does nothing.

Parameters:
instance - the instance to pass the logger to
logger - the logger to pass. If the logger is null then nothing is done.

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Configure an object according to a given Configuration.

Specified by:
configure in interface Configurable
Parameters:
configuration - the configuration object to consider
Throws:
ConfigurationException - in case that something went wrong
See Also:
Configurable.configure( org.extex.framework.configuration.Configuration)

createInstance

protected java.lang.Object createInstance(java.lang.Class<?> target)
                                   throws ConfigurationException
Get an instance.

Parameters:
target - the expected class or interface
Returns:
a new instance
Throws:
ConfigurationException - in case of an configuration error

createInstance

protected java.lang.Object createInstance(java.lang.Class<?> target,
                                          java.lang.Object arg)
                                   throws ConfigurationException
Get a new instance. This method selects one of the entries in the configuration. The selection is done with the help of a type String. If the type is null or the empty string then the default from the configuration is used.

Parameters:
target - the expected class or interface
arg - the argument for the constructor
Returns:
a new instance
Throws:
ConfigurationException - in case of an configuration error

createInstance

protected java.lang.Object createInstance(java.lang.String type,
                                          java.lang.Class<?> target)
                                   throws ConfigurationException
Create a new instance for a given configuration with an additional argument for the constructor.

Parameters:
type - the type to use
target - the expected class or interface
Returns:
a new instance
Throws:
ConfigurationException - in case of an configuration error

createInstance

protected java.lang.Object createInstance(java.lang.String type,
                                          java.lang.Class<?> target,
                                          java.lang.Class<?> argClass,
                                          java.lang.Object arg)
                                   throws ConfigurationException
Create a new instance for a given configuration with an additional argument for the constructor.

Parameters:
type - the type to use
target - the expected class or interface
argClass - the class of the argument
arg - the argument
Returns:
a new instance
Throws:
ConfigurationException - in case of an configuration error

createInstanceForConfiguration

protected java.lang.Object createInstanceForConfiguration(Configuration config,
                                                          java.lang.Class<?> target)
                                                   throws ConfigurationException
Create a new instance for a given configuration.

Parameters:
config - the configuration to use
target - the expected class or interface
Returns:
a new instance
Throws:
ConfigurationException - in case of an configuration error

createInstanceForConfiguration

protected java.lang.Object createInstanceForConfiguration(Configuration config,
                                                          java.lang.Class<?> target,
                                                          java.lang.Class<?> argClass,
                                                          java.lang.Object arg)
                                                   throws ConfigurationException
Create a new instance for a given configuration with an additional argument for the constructor.

Parameters:
config - the configuration to use
target - the expected class or interface
argClass - the class of the argument
arg - the argument
Returns:
a new instance
Throws:
ConfigurationException - in case of an configuration error

createInstanceForConfiguration

protected java.lang.Object createInstanceForConfiguration(Configuration config,
                                                          java.lang.Class<?> target,
                                                          java.lang.Object arg)
                                                   throws ConfigurationException
Create a new instance for a given configuration.

Parameters:
config - the configuration to use
target - the expected class or interface
arg - the constructor argument
Returns:
a new instance
Throws:
ConfigurationException - in case of an configuration error

enableLogging

public void enableLogging(java.util.logging.Logger theLogger)
Description copied from interface: LogEnabled
Setter for the logger.

Specified by:
enableLogging in interface LogEnabled
Parameters:
theLogger - the logger to use
See Also:
LogEnabled.enableLogging( java.util.logging.Logger)

getConfiguration

public Configuration getConfiguration()
Getter for configuration.

Returns:
the configuration.

getLogger

public java.util.logging.Logger getLogger()
Getter for logger.

Returns:
the logger.

getResourceFinder

public ResourceFinder getResourceFinder()
Getter for resourceFinder.

Returns:
the resourceFinder

reconnect

public java.lang.Object reconnect(java.lang.Object instance)
                           throws RegistrarException
Description copied from interface: RegistrarObserver
Reconnect an object. It should return the object which should actually be used. This is normally the object which is passed in as argument. Nevertheless the as a side effect the object can be attached to an internal list in a factory or augmented with additional information by invoking some of its methods.

Specified by:
reconnect in interface RegistrarObserver
Parameters:
instance - the object to reconnect
Returns:
the object to be actually used
Throws:
RegistrarException - in case of an error during configuration
See Also:
RegistrarObserver.reconnect(java.lang.Object)

selectConfiguration

protected Configuration selectConfiguration(java.lang.String type)
                                     throws ConfigurationException
Select a sub-configuration with a given name. If this does not exist then the attribute default is used to find an alternative.

Parameters:
type - the tag name for the sub-configuration to find
Returns:
the desired sub-configuration
Throws:
ConfigurationException - in case of an error

setResourceFinder

public void setResourceFinder(ResourceFinder finder)
Setter for the resource finder.

Specified by:
setResourceFinder in interface ResourceAware
Parameters:
finder - the resource finder
See Also:
ResourceAware.setResourceFinder( org.extex.resource.ResourceFinder)