org.apache.shale.clay.config.beans
Class ComponentConfigBean

java.lang.Object
  extended by org.apache.shale.clay.config.beans.ComponentConfigBean
All Implemented Interfaces:
Comparable, ConfigBean
Direct Known Subclasses:
TemplateConfigBean

public class ComponentConfigBean
extends Object
implements ConfigBean

This class is kind of the metadata object pool for configuration data loaded from XML files on startup in the ClayConfigureListener by the ClayXmlParser. An instance of this class will be registered with the ConfigBeanFactory.


Nested Class Summary
protected  class ComponentConfigBean.WatchDog
          This inner class watches for changes in a array of ConfigBean.ConfigDefinition's.
protected  class ComponentConfigBean.XmlConfigDef
          This class defines a single configration file that is watched for changes.
 
Nested classes/interfaces inherited from interface org.apache.shale.clay.config.beans.ConfigBean
ConfigBean.ConfigDefinition
 
Field Summary
protected  ServletContext context
          Reference to the ServletContext.
protected  Map displayElements
          Collection holding all the top-level components defined in the XML config files.
protected  boolean isWatchDogOn
          This parameter is initialized from the init method from the org.apache.shale.clay.AUTO_RELOAD_CONFIG_FILES init parameter in the web.xml.
protected static org.apache.shale.util.Messages messages
           Message resources for this class.
protected static String[] NAMING_CONTAINER_TYPES
          A static string array of faces component types that are naming containers.
protected  ClayConfigParser parser
          Uses the digester to load the configuration files into a object graph cached in displayElements.
protected  String[] suffixes
          The suffixes used to identify that a jsfid is a template style of composition.
protected  Map watchDogs
          Map of ComponentConfigBean.WatchDog that watches the configuration files looking for changes.
 
Constructor Summary
ComponentConfigBean()
          Constructor initializes the displayElements collection.
 
Method Summary
 void addChild(ComponentBean obj)
          Adds a {link ComponentBean} to the displayElement map collection using the jsfid as the key.
 void assignParent(ComponentBean b)
          Called to assign the IsA parent to the ComponentBean using the extends attribute.
protected  void checkCircularInheritance(ComponentBean b)
          Passed a ComponentBean, the method looks for several types of circular inheritances.
 void checkTree(ComponentBean b)
          Recursively walks the tree of component metadata verifying there is not a duplicate component id within a naming container.
protected  void checkTree(List componentIds, ComponentBean b)
          Verifies there is not a duplicate component id within a naming container.
protected  void clear(String watchDogName)
          Cleans up before a group of files are reloaded.
 int compareTo(Object config)
          Implementation of the Comparable interface.
protected  StringBuffer describeRelationships(Stack heritage)
          Returns a StringBuffer with an xpath like expression of jsfid that describes the Stack of ComponentBean.
 void destroy()
          The destroy method is invoked to clean up resources.
protected  Stack getAssociations(ComponentBean b)
          Walks up the hasA parent chain looking for circular relationships.
protected  ConfigBean.ConfigDefinition[] getConfigDefinitions(String configFiles)
          Passed a comma delimited list of configuration files, this method returns an array of ConfigBean.ConfigDefinition defining the files.
 ComponentBean getElement(String jsfid)
          Factory method that returns a top-level {link ComponentBean} with a matching jsfid or null if not found.
protected  Stack getGeneralizations(ComponentBean b)
          Walks up the isA parent chain looking for circular relationships.
 ServletContext getServletContext()
          Returns the web container ServletContext.
protected  ComponentBean getTopLevelElement(String jsfid)
          Returns the root metadata component that is used to add to the component tree.
 int getWeight()
          The weight is an attempt to make a plug-able system for registering ConfigBean objects with the ConfigBeanFactory.
 void init(ServletContext context)
          Initialization method that is passed the ServletContext as a parameter.
 boolean isDesigntime()
          Returns true if the current mode is design time.
protected  boolean isNamingContainer(String componentType)
          Checks the componentType against the NAMING_CONTAINER_TYPES list to determine if it is a naming container.
protected  void loadConfigFiles()
          Loads the Clay configration files into the displayElements Map.
protected  void realizingInheritance(AttributeBean a)
          This overload handles fixing up AttributeBean inheritance.
 void realizingInheritance(ComponentBean b)
          This method is passed a ComponentBean and is recursively called for each contained component.
 boolean refresh(boolean forceReload)
          This method should be called from key points in the application to invoke automatic reloading of the configuration files if they have been modified since last reloaded.
 void resolveInheritance()
          This method is called on startup to resolve the meta inheritance relationships for each top-level components in the displayElements collection.
 void setDesigntime(boolean isDesigntime)
          Sets the design time to somthing other than the default false value.
protected  void unassignParent(ComponentBean b)
          Recursively called to unassign isA and hasA parent relationships.
 boolean validMoniker(String id)
          Called by the ConfigBeanFactory to determine if this instance of ConfigBean can handle finding the ConfigBean from the jsfid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

protected ClayConfigParser parser

Uses the digester to load the configuration files into a object graph cached in displayElements.


isWatchDogOn

protected boolean isWatchDogOn

This parameter is initialized from the init method from the org.apache.shale.clay.AUTO_RELOAD_CONFIG_FILES init parameter in the web.xml. The default value is true which will trigger reloading the files when a change has occurred.


watchDogs

protected Map watchDogs

Map of ComponentConfigBean.WatchDog that watches the configuration files looking for changes. The configuration files are defined by the ConfigBean.ConfigDefinition top level interface.


messages

protected static org.apache.shale.util.Messages messages

Message resources for this class.


suffixes

protected String[] suffixes

The suffixes used to identify that a jsfid is a template style of composition. If it has a matching suffix, it will be handled by the TemplateConfigBean or TemplateComponentConfigBean; Otherwise, it's handled by ComponentConfigBean.


context

protected transient ServletContext context

Reference to the ServletContext.


displayElements

protected Map displayElements

Collection holding all the top-level components defined in the XML config files.


NAMING_CONTAINER_TYPES

protected static final String[] NAMING_CONTAINER_TYPES

A static string array of faces component types that are naming containers.

Constructor Detail

ComponentConfigBean

public ComponentConfigBean()

Constructor initializes the displayElements collection.

Method Detail

isDesigntime

public boolean isDesigntime()

Returns true if the current mode is design time.

Returns:
true if design time

setDesigntime

public void setDesigntime(boolean isDesigntime)

Sets the design time to somthing other than the default false value.

Parameters:
isDesigntime - load config descriptions

init

public void init(ServletContext context)

Initialization method that is passed the ServletContext as a parameter. Loads the sufixes for the ServletContext initialization parameter.

Specified by:
init in interface ConfigBean
Parameters:
context - servlet context

loadConfigFiles

protected void loadConfigFiles()

Loads the Clay configration files into the displayElements Map. The files are defined by the clay-template-suffix initialization parameter in the web deployment descriptor. The default configuration file "META-INF/view-config.xml" is always loaded from the shale-clay java archive.


getConfigDefinitions

protected ConfigBean.ConfigDefinition[] getConfigDefinitions(String configFiles)

Passed a comma delimited list of configuration files, this method returns an array of ConfigBean.ConfigDefinition defining the files.

Parameters:
configFiles - comma seperated list of config files
Returns:
config definitions for the files

getServletContext

public ServletContext getServletContext()

Returns the web container ServletContext.

Specified by:
getServletContext in interface ConfigBean
Returns:
servlet context

getElement

public ComponentBean getElement(String jsfid)

Factory method that returns a top-level {link ComponentBean} with a matching jsfid or null if not found.

Specified by:
getElement in interface ConfigBean
Parameters:
jsfid - id of component definition
Returns:
component definition for the jsfid

addChild

public void addChild(ComponentBean obj)

Adds a {link ComponentBean} to the displayElement map collection using the jsfid as the key.

Parameters:
obj - component bean added to the map of elements

resolveInheritance

public void resolveInheritance()

This method is called on startup to resolve the meta inheritance relationships for each top-level components in the displayElements collection. There are three steps, find parents, check for circular relationships, and realize the relationships.


getTopLevelElement

protected ComponentBean getTopLevelElement(String jsfid)

Returns the root metadata component that is used to add to the component tree. This method might be overridden to broaden the scope to search for components outside of the displayElement cache.

Parameters:
jsfid - id of a component bean
Returns:
component bean

assignParent

public void assignParent(ComponentBean b)

Called to assign the IsA parent to the ComponentBean using the extends attribute.

Specified by:
assignParent in interface ConfigBean
Parameters:
b - component bean needing isa parent assigned

realizingInheritance

protected void realizingInheritance(AttributeBean a)

This overload handles fixing up AttributeBean inheritance.

Parameters:
a - attribute needing inheritance resolved

realizingInheritance

public void realizingInheritance(ComponentBean b)

This method is passed a ComponentBean and is recursively called for each contained component. It fixes up the meta inheritance relationships.

Specified by:
realizingInheritance in interface ConfigBean
Parameters:
b - component bean needing inheritance realized

getGeneralizations

protected Stack getGeneralizations(ComponentBean b)

Walks up the isA parent chain looking for circular relationships. It returns a Stack of ComponentBean documenting the heritage. A runtime exception is thrown if a circular relationship is found.

Parameters:
b - component bean having inheritance checked
Returns:
inheritance stack

getAssociations

protected Stack getAssociations(ComponentBean b)

Walks up the hasA parent chain looking for circular relationships. It returns a Stack of ComponentBean documenting the composition. A runtime exception is thrown if a circular relationship is found.

Parameters:
b - component bean having composition checked
Returns:
stack of parents

describeRelationships

protected StringBuffer describeRelationships(Stack heritage)

Returns a StringBuffer with an xpath like expression of jsfid that describes the Stack of ComponentBean.

Parameters:
heritage - stack of relationships to report on
Returns:
description of the stack

checkCircularInheritance

protected void checkCircularInheritance(ComponentBean b)

Passed a ComponentBean, the method looks for several types of circular inheritances. It's recursively called for all contained components, children, validators, actionListeners, valueChangeListeners and Converter. A runtime exception is thrown if a invalid relationship is found.

Parameters:
b - component bean to check

unassignParent

protected void unassignParent(ComponentBean b)

Recursively called to unassign isA and hasA parent relationships.

Parameters:
b - component bean

clear

protected void clear(String watchDogName)

Cleans up before a group of files are reloaded.

Parameters:
watchDogName - group name for a group of config files or templates

destroy

public void destroy()

The destroy method is invoked to clean up resources. By dereferencing the complex graph of display elements

Specified by:
destroy in interface ConfigBean

validMoniker

public boolean validMoniker(String id)

Called by the ConfigBeanFactory to determine if this instance of ConfigBean can handle finding the ConfigBean from the jsfid.

Specified by:
validMoniker in interface ConfigBean
Parameters:
id - jsfid
Returns:
true if the jsfid can be handled

compareTo

public int compareTo(Object config)

Implementation of the Comparable interface. The weight is used to determine the ordering of the registered ConfigBean objects within the ConfigBeanFactory.

Specified by:
compareTo in interface Comparable
Parameters:
config - object to compare to
Returns:
compares the weight of two config handlers

getWeight

public int getWeight()

The weight is an attempt to make a plug-able system for registering ConfigBean objects with the ConfigBeanFactory. A custom implementation could be registered for a different composition technique adding or overriding an existing implementation.

Specified by:
getWeight in interface ConfigBean
Returns:
0

refresh

public boolean refresh(boolean forceReload)

This method should be called from key points in the application to invoke automatic reloading of the configuration files if they have been modified since last reloaded. If the forceReload flag is true the files are reloaded. A true return value indicates the config files were reloaded.

Specified by:
refresh in interface ConfigBean
Parameters:
forceReload - reload the files
Returns:
files were reloaded

isNamingContainer

protected boolean isNamingContainer(String componentType)

Checks the componentType against the NAMING_CONTAINER_TYPES list to determine if it is a naming container. Component id's must be unique within a naming container. Returns a true value if the componentType is a naming container; otherwise, returns false.

Parameters:
componentType - type of the component
Returns:
true if the component type is a naming comtainer

checkTree

public void checkTree(ComponentBean b)

Recursively walks the tree of component metadata verifying there is not a duplicate component id within a naming container. A root ComponentBean is passed as a single parameter. The overloaded checkTree(List, ComponentBean) is invoked to process components under a naming container.

Specified by:
checkTree in interface ConfigBean
Parameters:
b - root of the component tree

checkTree

protected void checkTree(List componentIds,
                         ComponentBean b)

Verifies there is not a duplicate component id within a naming container. A list of accumulating componentIds and a root ComponentBean is passed as parameters. A runtime exception is thrown if a duplicate id is encountered.

Parameters:
componentIds - list of component id's in the naming container
b - parent component bean


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.