de.dante.util.framework
Class AbstractFactory

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

public abstract class AbstractFactory
extends java.lang.Object
implements Configurable, LogEnabled, 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: 1.17 $
Author:
Gerd Neugebauer

Constructor Summary
AbstractFactory()
          Creates a new factory object.
 
Method Summary
 void configure(Configuration theConfiguration)
          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.String type, java.lang.Class target)
          Get a new instance.
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.String arg1)
          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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFactory

public AbstractFactory()
Creates a new factory object.

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 theConfiguration)
               throws ConfigurationException
Description copied from interface: Configurable
Configure an object according to a given Configuration.

Specified by:
configure in interface Configurable
Parameters:
theConfiguration - the configuration object to consider
Throws:
ConfigurationException - in case that something went wrong
See Also:
Configurable.configure( de.dante.util.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.String type,
                                          java.lang.Class target)
                                   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:
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.String arg1)
                                                   throws ConfigurationException
Create a new instance for a given configuration.

Parameters:
config - the configuration to use
target - the expected class or interface
arg1 - the first (String) 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.

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 ConfigurationInvalidResourceException,
                                            ConfigurationNotFoundException,
                                            ConfigurationSyntaxException,
                                            ConfigurationIOException,
                                            ConfigurationMissingAttributeException,
                                            ConfigurationMissingException
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:
ConfigurationInvalidResourceException - in case that the given resource name is null or empty.
ConfigurationNotFoundException - in case that the requested configuration does not exist.
ConfigurationSyntaxException - in case of a syntax error in the configuration.
ConfigurationIOException - in case that an IOException occurred while reading the configuration.
ConfigurationMissingAttributeException - in case that an attribute is missing.
ConfigurationMissingException - in case that the factory has not been configured yet.