org.formproc
Class FormManager

java.lang.Object
  |
  +--org.formproc.FormManager
All Implemented Interfaces:
com.anthonyeden.lib.Reloadable, com.anthonyeden.lib.resource.ResourceRecipient

public class FormManager
extends java.lang.Object
implements com.anthonyeden.lib.Reloadable, com.anthonyeden.lib.resource.ResourceRecipient

The FormManager is the central class for configuring Form objects. Form objects must be configured before they can be used by calling this class's configure(Form form) method.

Author:
Anthony Eden

Field Summary
static java.lang.String CLASS_TYPE_VALIDATOR
          Keyword for class type validators (the keyword is "class")
static java.lang.String CONFIGURATION_FILE
          The default configuration file name (formproc.xml).
static java.lang.String DEFAULT_RESOURCE_LOADER
          The default resource loader (com.anthonyeden.lib.resource.FileResourceLoader)
static java.lang.String SHARED_TYPE_VALIDATOR
          Keyword for shared validators (the keyword is "shared")
 
Constructor Summary
FormManager()
          Construct a new FormManager.
FormManager(java.io.File configurationFile)
          Construct a new FormManager using the given configuration file to configure the FormManager.
FormManager(org.apache.commons.vfs.FileObject configurationFile)
          Construct a new FormManager using the given configuration file to configure the FormManager.
FormManager(java.io.InputStream configurationStream)
          Construct a new FormManager using the given InputStream to configure the FormManager.
 
Method Summary
 void configure(Form form)
          Configure the given form.
protected  java.lang.String findPath(com.anthonyeden.lib.config.Configuration configuration, org.apache.commons.vfs.FileObject relativeFile)
          Find the path specified in the given configuration object.
 org.apache.commons.vfs.FileSystemManager getFileSystemManager()
          Get the FileSystemManager.
 FormConfiguration getFormConfiguration(java.lang.String name)
          Get the FormConfiguration for the given form name.
 java.util.Map getSharedValidators()
          Get a Map of shared validators.
 Validator getValidator(com.anthonyeden.lib.config.Configuration configuration)
          Get the validator which is defined by the given configuration object.
 java.util.Map getValidatorMap()
          Get the validator map.
 void load(java.io.InputStream in)
          Deprecated. Use loadConfiguration() instead
 void loadConfiguration()
          Load the configuration using this class's ClassLoader to locate the configuration file as a resource stream.
 void loadConfiguration(java.io.File file)
          Load the configuration from the given file.
 void loadConfiguration(org.apache.commons.vfs.FileObject configurationFile)
          Load the configuration from the given file.
 void loadConfiguration(java.io.InputStream in)
          Load the configuration from the given InputStream.
protected  void loadForm(com.anthonyeden.lib.config.Configuration configuration)
          Load the form configuration defined by the given configuration object.
protected  void loadInclude(com.anthonyeden.lib.config.Configuration configuration)
          Load the included configuration defined by the given configuration object.
protected  void loadSharedValidator(com.anthonyeden.lib.config.Configuration configuration)
          Load the shared validator defined by the given configuration object.
protected  void loadValidatorMap(com.anthonyeden.lib.config.Configuration configuration)
          Load the validator map defined by the given configuration object.
 void reload()
          Reload the configuration.
 void setFormConfiguration(java.lang.String name, FormConfiguration configuration)
          Set the FormConfiguration for the given form name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_TYPE_VALIDATOR

public static final java.lang.String CLASS_TYPE_VALIDATOR
Keyword for class type validators (the keyword is "class")

See Also:
Constant Field Values

SHARED_TYPE_VALIDATOR

public static final java.lang.String SHARED_TYPE_VALIDATOR
Keyword for shared validators (the keyword is "shared")

See Also:
Constant Field Values

DEFAULT_RESOURCE_LOADER

public static final java.lang.String DEFAULT_RESOURCE_LOADER
The default resource loader (com.anthonyeden.lib.resource.FileResourceLoader)

See Also:
Constant Field Values

CONFIGURATION_FILE

public static final java.lang.String CONFIGURATION_FILE
The default configuration file name (formproc.xml).

See Also:
Constant Field Values
Constructor Detail

FormManager

public FormManager()
            throws java.lang.Exception
Construct a new FormManager.

Throws:
java.lang.Exception - Any exception

FormManager

public FormManager(java.io.File configurationFile)
            throws java.lang.Exception
Construct a new FormManager using the given configuration file to configure the FormManager.

Parameters:
configurationFile - The configuration File
Throws:
java.lang.Exception - Any Exception

FormManager

public FormManager(org.apache.commons.vfs.FileObject configurationFile)
            throws java.lang.Exception
Construct a new FormManager using the given configuration file to configure the FormManager.

Parameters:
configurationFile - The configuration File
Throws:
java.lang.Exception - Any Exception

FormManager

public FormManager(java.io.InputStream configurationStream)
            throws java.lang.Exception
Construct a new FormManager using the given InputStream to configure the FormManager. The InputStream should provide a stream of XML data.

Parameters:
configurationStream - The configuration InputStream
Throws:
java.lang.Exception - Any Exception
Method Detail

getFileSystemManager

public org.apache.commons.vfs.FileSystemManager getFileSystemManager()
                                                              throws org.apache.commons.vfs.FileSystemException
Get the FileSystemManager.

Returns:
The FileSystemManager
Throws:
org.apache.commons.vfs.FileSystemException

configure

public void configure(Form form)
               throws java.lang.Exception
Configure the given form. Forms must be configured before they can be used.

Parameters:
form - The Form
Throws:
java.lang.Exception - Any exception

getFormConfiguration

public FormConfiguration getFormConfiguration(java.lang.String name)
                                       throws java.lang.Exception
Get the FormConfiguration for the given form name.

Parameters:
name - The name of the form
Throws:
java.lang.Exception - Any Exception

setFormConfiguration

public void setFormConfiguration(java.lang.String name,
                                 FormConfiguration configuration)
Set the FormConfiguration for the given form name. This method will replace any FormConfiguration previously specified for the given form.

Parameters:
name - The form name
configuration - The FormConfiguration

getValidatorMap

public java.util.Map getValidatorMap()
Get the validator map. The validator map is a mapping of validator classes to type Strings. Each validator must be specified in the configuration file (except for customer FormValidator implementations which can specify their type as 'class' in the configuration file of each form.)

Returns:
The validator map

getSharedValidators

public java.util.Map getSharedValidators()
Get a Map of shared validators. Shared validators are referenced by name.

Returns:
A Map of shared validators

getValidator

public Validator getValidator(com.anthonyeden.lib.config.Configuration configuration)
                       throws java.lang.Exception
Get the validator which is defined by the given configuration object.

Parameters:
configuration - The Configuration object
Returns:
The FormElementValidator
Throws:
java.lang.Exception

loadConfiguration

public void loadConfiguration()
                       throws java.lang.Exception
Load the configuration using this class's ClassLoader to locate the configuration file as a resource stream.

Throws:
java.lang.Exception - Any Exception

loadConfiguration

public void loadConfiguration(java.io.File file)
                       throws com.anthonyeden.lib.config.ConfigurationException
Load the configuration from the given file. The file will be monitored for changes. Changes will cause the configuration to reload.

Throws:
java.lang.Exception - Any Exception
com.anthonyeden.lib.config.ConfigurationException

loadConfiguration

public void loadConfiguration(org.apache.commons.vfs.FileObject configurationFile)
                       throws com.anthonyeden.lib.config.ConfigurationException
Load the configuration from the given file. The file will be monitored for changes. Changes will cause the configuration to reload.

Parameters:
configurationFile - The file
Throws:
java.lang.Exception - Any Exception
com.anthonyeden.lib.config.ConfigurationException

load

public void load(java.io.InputStream in)
          throws java.lang.Exception
Deprecated. Use loadConfiguration() instead

Load the configuration from the given InputStream.

Specified by:
load in interface com.anthonyeden.lib.resource.ResourceRecipient
Parameters:
in - The InputStream
Throws:
java.lang.Exception - Any Exception

loadConfiguration

public void loadConfiguration(java.io.InputStream in)
                       throws java.lang.Exception
Load the configuration from the given InputStream.

Parameters:
in - The InputStream
Throws:
java.lang.Exception - Any Exception

reload

public void reload()
Reload the configuration.

Specified by:
reload in interface com.anthonyeden.lib.Reloadable

loadInclude

protected void loadInclude(com.anthonyeden.lib.config.Configuration configuration)
                    throws java.lang.Exception
Load the included configuration defined by the given configuration object.

Parameters:
configuration - The Configuration object
Throws:
com.anthonyeden.lib.config.ConfigurationException
java.lang.Exception

loadValidatorMap

protected void loadValidatorMap(com.anthonyeden.lib.config.Configuration configuration)
                         throws java.lang.Exception
Load the validator map defined by the given configuration object.

Parameters:
configuration - The Configuration object
Throws:
com.anthonyeden.lib.config.ConfigurationException
java.lang.Exception

loadSharedValidator

protected void loadSharedValidator(com.anthonyeden.lib.config.Configuration configuration)
                            throws java.lang.Exception
Load the shared validator defined by the given configuration object.

Parameters:
configuration - The Configuration object
Throws:
com.anthonyeden.lib.config.ConfigurationException
java.lang.Exception

loadForm

protected void loadForm(com.anthonyeden.lib.config.Configuration configuration)
                 throws java.lang.Exception
Load the form configuration defined by the given configuration object.

Parameters:
configuration - The Configuration object
Throws:
com.anthonyeden.lib.config.ConfigurationException
java.lang.Exception

findPath

protected java.lang.String findPath(com.anthonyeden.lib.config.Configuration configuration,
                                    org.apache.commons.vfs.FileObject relativeFile)
                             throws org.apache.commons.vfs.FileSystemException
Find the path specified in the given configuration object. If the "path" attribute is specified in the configuration, then use that. If not then check for the "file" attribute. If the file attribute is absolute then use that. If the file is not absolute then make it relative to the value of the relativeFile argument.

Parameters:
configuration - The configuration object
relativeFile - The file which the path is relative to
Returns:
The path or null
Throws:
org.apache.commons.vfs.FileSystemException


Copyright (c) 2001-2003 Anthony Eden. All Rights Reserved.