com.taursys.xml
Class ComponentFactory

java.lang.Object
  extended bycom.taursys.xml.ComponentFactory
Direct Known Subclasses:
HTMLComponentFactory

public abstract class ComponentFactory
extends java.lang.Object

Abstract class used to automate the creation of Components based on the XML Document and its Elements. It determines the Component type based on its element tag and "id" attribute). Concrete subclasses must override the initTagTable method and populate the tagTable with suggested components for the elements in the XML document.

This class contains two primary methods:


Field Summary
static java.lang.String ID_DELIMITER
           
protected  java.util.Hashtable tagTable
           
static java.lang.String TEMPLATE_NODE
           
 
Constructor Summary
ComponentFactory()
          Default constructor which initializes tag table by calling initTagTable
 
Method Summary
protected  boolean bindComponent(NodeDescriptor nd, org.w3c.dom.Element element, ValueHolder[] holders, Component component)
           
protected abstract  Component createComponentForElement(org.w3c.dom.Element element, NodeDescriptor nd)
           
protected abstract  Component createComponentForElement(java.lang.String id, org.w3c.dom.Element element, ValueHolder[] holders)
          Create a component for given element and set its properties.
 void createComponents(Container container, ValueHolder[] holders)
          Creates components based on document, set their properties (including valueHolder) and adds them to the container.
 void createComponents(Container container, ValueHolder[] holders, boolean bindExisting)
          Creates components based on document, set their properties (including valueHolder) and adds them to the container.
abstract  java.util.Vector getSuggestedComponents(org.w3c.dom.Element element)
          Returns a Vector of suggested Component class names for given Element.
protected  java.util.Vector getSuggestedComponents(java.lang.String tagName, java.lang.String id, org.w3c.dom.Element element)
          Returns a Vector of suggested Component class names for given Element.
protected abstract  void initTagTable()
          Initialize values in the tag table
protected  NodeDescriptor parseBindSyntax(java.lang.String value)
           
 void printComponentTree(Container parent, java.lang.String level)
          Prints the component tree contents to the console
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID_DELIMITER

public static final java.lang.String ID_DELIMITER
See Also:
Constant Field Values

TEMPLATE_NODE

public static final java.lang.String TEMPLATE_NODE
See Also:
Constant Field Values

tagTable

protected java.util.Hashtable tagTable
Constructor Detail

ComponentFactory

public ComponentFactory()
Default constructor which initializes tag table by calling initTagTable

Method Detail

getSuggestedComponents

public abstract java.util.Vector getSuggestedComponents(org.w3c.dom.Element element)
Returns a Vector of suggested Component class names for given Element. This method will choose the appropriate Components based on the type of Element given. The default Component type will be the first in the list.

If the Element has an ID, then the DocumentElement Component will be added to the end of the suggestion list.

If the id contains the TEMPLATE_NODE keyword, then a Template will be added to the top of the suggestion list.

If there are no suggested types of Component for the given Element, then an empty Vector will be returned.

Subclasses should override this method if more than the Element tag name is needed to determine the suggested components.

Parameters:
element - to return default Component type for
Returns:
a Vector containing any suggested Component class names

createComponents

public void createComponents(Container container,
                             ValueHolder[] holders)

Creates components based on document, set their properties (including valueHolder) and adds them to the container. As it moves through the document, it first checks to see if the component is already in the container (by matching id's). If it is, the existing component is moved to the proper place in the heirarchy. Otherwise it will create a component.

This method builds a component heirarchy which matches the document order and heirarchy. If any newly created component is itself a Container type, then all children of that component are added to it rather than its parent container.

Only bound components which are bound to one of the given value holders are created.

Parameters:
container - the Container to add components to
holders - an array of valueholders.

printComponentTree

public void printComponentTree(Container parent,
                               java.lang.String level)
Prints the component tree contents to the console

Parameters:
parent - starting parent container
level - spaces to indent initially

createComponents

public void createComponents(Container container,
                             ValueHolder[] holders,
                             boolean bindExisting)

Creates components based on document, set their properties (including valueHolder) and adds them to the container. As it moves through the document, it first checks to see if the component is already in the container (by matching id's). If it is, the existing component is moved to the proper place in the heirarchy. Otherwise it will create a component.

This method builds a component heirarchy which matches the document order and heirarchy. If any newly created component is itself a Container type, then all children of that component are added to it rather than its parent container.

Only bound components which are bound to one of the given value holders are created.

Parameters:
container - the Container to add components to
holders - an array of valueholders.

initTagTable

protected abstract void initTagTable()
Initialize values in the tag table


getSuggestedComponents

protected java.util.Vector getSuggestedComponents(java.lang.String tagName,
                                                  java.lang.String id,
                                                  org.w3c.dom.Element element)
Returns a Vector of suggested Component class names for given Element. This method will choose the appropriate Components based on the type of tag given. The default Component type will be the first in the list.

If an ID is given, then the DocumentElement Component will be added to the end of the suggestion list.

If the id contains the TEMPLATE_NODE keyword, then a Template will be added to the top of the suggestion list.

If an ID is given and the id does not contain the TEMPLATE_NODE keyword, but the given element has child nodes, then a Template will be added before the DocumentElement suggestion.

If there are no suggested types of Component for the given tag, then an empty Vector will be returned.

Parameters:
tagName - to return default Component type for
id - of the tag or null
element - the Element to get suggestions for
Returns:
a Vector containing any suggested Component class names

createComponentForElement

protected abstract Component createComponentForElement(java.lang.String id,
                                                       org.w3c.dom.Element element,
                                                       ValueHolder[] holders)
Create a component for given element and set its properties.

Parameters:
id - the id of the Element to create the Component for.
element - the Element to create the Component for.
holders - the array of ValueHolders for binding

createComponentForElement

protected abstract Component createComponentForElement(org.w3c.dom.Element element,
                                                       NodeDescriptor nd)

parseBindSyntax

protected NodeDescriptor parseBindSyntax(java.lang.String value)

bindComponent

protected boolean bindComponent(NodeDescriptor nd,
                                org.w3c.dom.Element element,
                                ValueHolder[] holders,
                                Component component)
Parameters:
nd -
element -
holders -
component -
Returns:


Copyright © 2007 Martin T Phelan. All Rights Reserved.