org.formaria.builder.generic
Class GenericBuilder

java.lang.Object
  extended by org.formaria.builder.AriaBuilder
      extended by org.formaria.builder.generic.GenericBuilder
All Implemented Interfaces:
PageLoader
Direct Known Subclasses:
PojoFormBuilder

public class GenericBuilder
extends AriaBuilder

A generic builder for forms/pages based on generation markup. The builder can create Aria pages on-the-fly or it can be used to convert and save a page to a aria format.

Copyright (c) Formaria Ltd., 2001-2008, This software is licensed under the GNU Public License (GPL), please see license.txt for more details. If you make commercial use of this software you must purchase a commercial license from Formaria.


Field Summary
protected  java.util.ArrayList commonAttributeMapping
           
protected  java.lang.String componentsNodeName
           
protected  Panel decorationPanel
           
protected static java.net.URL documentUrl
           
protected  java.util.ArrayList escapes
           
protected  GenericBuilderAttributeEvaluator evaluator
           
protected  java.lang.String fileExtension
           
protected  Panel formPanel
           
protected  java.awt.LayoutManager layoutManager
           
protected  java.lang.String packageName
           
protected  java.util.Hashtable processors
           
protected  boolean reverseOrder
          false for normal z-ordering of new components, true to reverse the order
protected  java.util.Hashtable typeMap
           
 
Fields inherited from class org.formaria.builder.AriaBuilder
adapter, attributeSets, checkBoxGroup, componentFactory, currentAttributes, currentProject, customizer, DEFAULT_PAGE_CLASS, eventHandler, includeFileName, layoutHelper, menuBar, page, rootPage, secondaryClassloader, validationFactories
 
Constructor Summary
GenericBuilder(Project project)
          Create a new builder.
 
Method Summary
 void addBinding(java.awt.Component targetComp, java.lang.String srcStr)
          Add a data binding for the component
protected  java.lang.Object addComponent(XmlElement childNode)
          Adds an individual component element to the page (this method may be called recursively for nested elements).
protected  void addVocabulary(PageSupport page, XmlElement model)
          Adds data vocaulary associated with the page.
protected  java.lang.String escape(java.lang.String srcValue)
          Replace the [...] escaped blocks with [idx] where idx is the index of the store for the escaped value
 java.lang.String getMappedValue(java.awt.Component comp, java.lang.String srcValue)
          Get the argument value in the specified format, substituting the value into the mapping string as appropriate.
 java.lang.String getMappedValue(java.lang.String srcValue, java.lang.String mapping)
          Get the argument value in the specified format, substituting the value into the mapping string as appropriate.
 java.lang.String getType()
          Get the page loader type - a unique name identifying the loader
protected  java.io.InputStream getUrlInputStream(java.lang.String urlStr)
          Attempt to get an input stream from the specified path
protected  void init(java.lang.String packageName)
          Initialize the builder
 PageSupport loadPage(java.lang.String defPackageName, java.lang.String pageName, boolean include)
          Loads an Page via a reader obtained from the Project (searches the classpath).
 PageSupport readPage(java.io.Reader reader, java.lang.String pageName, java.lang.String ext, boolean include)
          Read an XML description of the page and construct a new Page.
protected  void setComponentAttributes(java.awt.Component comp, java.lang.String attribName, java.lang.String attribValue, XmlElement childNode)
          Iterate through the attributes and set the attributes for a component
 void setStyle(java.awt.Component comp, java.lang.String value)
          Apply a style to a component
 void setupCommonAttributeMapping(XmlElement mappingNode)
          Load the definition of the common attribute mapping
protected  void setupComponentMapping(XmlElement mappingNode)
          Setup the mapping for component elements
 void setupFileTypeHandler(java.lang.String urlStr)
          Setup the file type handling, mapping a file extension to a set of configuration files for a particular file format.
protected  void setupInstructionMapping(XmlElement mappingNode)
          Setup the mapping for process/instruction elements
protected  void setupPage(XmlElement model, java.lang.String pageName, java.lang.String ext, boolean include)
          Loads the page based on the contents of the page tag or by using default values.
 void setupPageLayout(XmlElement componentsNode)
          Setup the layout for this page
protected  java.lang.String unescape(java.lang.String srcValue)
          Replace the [...] escaped blocks with [idx] where idx is the index of the store for the escaped value
 
Methods inherited from class org.formaria.builder.AriaBuilder
addBinding, addBindings, addComponents, addEvent, addEvents, addHandler, addMenu, addScripts, addValidations, evaluateAttribute, evaluateAttributeAsString, getCurrentAttributes, getFactoryBinding, getInt, getMenuItem, getValidationFactory, insertAttributes, loadAttributeSet, loadClass, loadFrames, loadOtherElement, loadSingleTarget, popIncludeReference, popRepeatReference, pushIncludeReference, pushRepeatReference, setAttributeEvaluator, setClassLoader, setComponentAttributes, setPackageName, setPage, setPageAttribute, setPageExtension, setPageName, setResourceBundle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

evaluator

protected GenericBuilderAttributeEvaluator evaluator

typeMap

protected java.util.Hashtable typeMap

processors

protected java.util.Hashtable processors

commonAttributeMapping

protected java.util.ArrayList commonAttributeMapping

packageName

protected java.lang.String packageName

documentUrl

protected static java.net.URL documentUrl

fileExtension

protected java.lang.String fileExtension

componentsNodeName

protected java.lang.String componentsNodeName

layoutManager

protected java.awt.LayoutManager layoutManager

decorationPanel

protected Panel decorationPanel

formPanel

protected Panel formPanel

escapes

protected java.util.ArrayList escapes

reverseOrder

protected boolean reverseOrder
false for normal z-ordering of new components, true to reverse the order

Constructor Detail

GenericBuilder

public GenericBuilder(Project project)
Create a new builder. An attempt is made to configure the builder with a configuration file when the builder is constructed if the configuration file is specified as part of the startup properties via the GenericBuilderConfig setting.

Parameters:
project - the current aria project
factory - the component factory
Method Detail

init

protected void init(java.lang.String packageName)
Initialize the builder

Overrides:
init in class AriaBuilder
Parameters:
packageName - the default componnet package or use AWT if none is specified

setupFileTypeHandler

public void setupFileTypeHandler(java.lang.String urlStr)
Setup the file type handling, mapping a file extension to a set of configuration files for a particular file format. An attempt is made to load this file when the builder is constructed if the configuration file is specified as part of the startup properties via the GenericBuilderConfig setting.

Parameters:
urlStr - a filename/url for the main configuration file

setupComponentMapping

protected void setupComponentMapping(XmlElement mappingNode)
Setup the mapping for component elements

Parameters:
mappingNode - the node whose children describe the mapping of the file elements to components

setupInstructionMapping

protected void setupInstructionMapping(XmlElement mappingNode)
Setup the mapping for process/instruction elements

Parameters:
mappingNode - the node whose children describe the mapping of the file elements to components

setupCommonAttributeMapping

public void setupCommonAttributeMapping(XmlElement mappingNode)
Load the definition of the common attribute mapping


getUrlInputStream

protected java.io.InputStream getUrlInputStream(java.lang.String urlStr)
Attempt to get an input stream from the specified path

Parameters:
urlStr - the url string
Returns:
the inputstream or null if the strean cannot be opened.

loadPage

public PageSupport loadPage(java.lang.String defPackageName,
                            java.lang.String pageName,
                            boolean include)
Loads an Page via a reader obtained from the Project (searches the classpath). The pageName is assumed to be the name of an XML file. For example if the pageName is 'welcome' then the 'welcome.xml' file is read as a UTF8 encoded XML file (by default).

Specified by:
loadPage in interface PageLoader
Overrides:
loadPage in class AriaBuilder
Parameters:
defPackageName - the package or path to the page
pageName - the page name or the name of the class implementing the page
include - true if the page to be loaded is being included in another page in which case any class attribute of the included page is ignored
Returns:
the page

readPage

public PageSupport readPage(java.io.Reader reader,
                            java.lang.String pageName,
                            java.lang.String ext,
                            boolean include)
Read an XML description of the page and construct a new Page. An instance of the class specified by the class attribute is constructed or else an instance of Page if no class attribute is specified. The new page is populated but is not yet added to its parent.
The startup file parameter 'DefaultClass' is used to obtain a default for each page's class if a class parameter is not specified in the page's XML
The startup file parameter 'Validations' is used to obtain a default for each page's set of validation rules

Specified by:
readPage in interface PageLoader
Overrides:
readPage in class AriaBuilder
Parameters:
reader - a input stream from which to read the page
pageName - the name of the page
ext - the file extension
include - the page to be loaded is being included in another page
Returns:
the page

setupPage

protected void setupPage(XmlElement model,
                         java.lang.String pageName,
                         java.lang.String ext,
                         boolean include)
Loads the page based on the contents of the page tag or by using default values.

Overrides:
setupPage in class AriaBuilder
Parameters:
pageName - the name of the page
ext - the file extension
include - the page to be loaded is being included in another page

setupPageLayout

public void setupPageLayout(XmlElement componentsNode)
Setup the layout for this page


addVocabulary

protected void addVocabulary(PageSupport page,
                             XmlElement model)
Adds data vocaulary associated with the page.

Parameters:
page - the page to which the component/data bindings are added
model - the vocabulary model

addComponent

protected java.lang.Object addComponent(XmlElement childNode)
Adds an individual component element to the page (this method may be called recursively for nested elements). Several methods will be attempted until a component is successfully created. Firstly the built-in component types are checked, then any additional registered component constructors. The types can be specified by type ID, type name or class name.

Overrides:
addComponent in class AriaBuilder
Parameters:
childNode - the XML element containing the component specification.
Returns:
the new component

setComponentAttributes

protected void setComponentAttributes(java.awt.Component comp,
                                      java.lang.String attribName,
                                      java.lang.String attribValue,
                                      XmlElement childNode)
Iterate through the attributes and set the attributes for a component

Parameters:
comp - the component
attribName - the name of the attribute.
attribValue - the value of the attribute.
childNode - the source xml node

getMappedValue

public java.lang.String getMappedValue(java.lang.String srcValue,
                                       java.lang.String mapping)
Get the argument value in the specified format, substituting the value into the mapping string as appropriate. The mapping allows a value to be included from a model or a path within the model

Parameters:
mapping - e.g. /vocab/lists/${value}
srcValue - the value that is used to replace $value, or the return value if no substitution is specified in the mapping

getMappedValue

public java.lang.String getMappedValue(java.awt.Component comp,
                                       java.lang.String srcValue)
Get the argument value in the specified format, substituting the value into the mapping string as appropriate. The mapping allows a value to be included from a model or a path within the model

Parameters:
comp - the affected component
mapping - e.g. /vocab/lists/${value}
srcValue - the value that is ${compName} value if no substitution is specified in the mapping

escape

protected java.lang.String escape(java.lang.String srcValue)
Replace the [...] escaped blocks with [idx] where idx is the index of the store for the escaped value

Parameters:
srcValue - the source/unescaped value
Returns:
the escaped value

unescape

protected java.lang.String unescape(java.lang.String srcValue)
Replace the [...] escaped blocks with [idx] where idx is the index of the store for the escaped value

Parameters:
srcValue - the source/unescaped value
Returns:
the escaped value

addBinding

public void addBinding(java.awt.Component targetComp,
                       java.lang.String srcStr)
Add a data binding for the component

Parameters:
targetComp - the affected component
srcStr - the data source path

setStyle

public void setStyle(java.awt.Component comp,
                     java.lang.String value)
Apply a style to a component

Parameters:
comp - the affected component
value - the style name/value

getType

public java.lang.String getType()
Get the page loader type - a unique name identifying the loader

Specified by:
getType in interface PageLoader
Overrides:
getType in class AriaBuilder
Returns:
"generic"