adapforms.form
Class Form

java.lang.Object
  extended by adapforms.form.Form
All Implemented Interfaces:
ElementContainer

public class Form
extends java.lang.Object
implements ElementContainer

Generic representation of an adaptive form.

The form represents the static uninitialized form, and thus cannot hold any values or adapt.

A form is in most cases read from an XML file using the See FormParser, but may also be coded by hand (not recommended).

The static form must be instantiated before practical use. See createInstance(InstanceCallback).

Author:
Henrik Gammelmark, geemark@cs.au.dk

Constructor Summary
Form(java.lang.String title, java.util.List<FormElement> elements)
          Create a form with the specified title and elements.
 
Method Summary
 FormBehaviour createBehaviourInstance()
          Create a new instance of the FormBehaviour of the form.
 FormInstance createInstance(InstanceCallback callback)
          Create a concrete instance of the form that can be filled out and adapted.
 FormInstance createInstance(InstanceCallback callback, Localization localization)
          Create a concrete instance of the form that can be filled out and adapted.
 int getDeepestLevel()
          Find out how many path elements exists to the deepest level of the structure.
 java.util.List<FormElement> getElements()
          Ordered list of the elements that make up the structure of the form.
 java.lang.String getTitle()
          Form title.
 FormElement lookupElement(FormPath path)
          Given a form path, find the form element that corresponds to it.
 void prettyPrintStructure()
          Pretty-print the form structure (form elements) to System.out.
 void setBehaviourClass(java.lang.Class<FormBehaviour> behaviour)
          Set class representing the behaviour of this form.
 java.lang.String toString()
           
 void verify()
          Verify that the form is sound.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Form

public Form(java.lang.String title,
            java.util.List<FormElement> elements)
Create a form with the specified title and elements.

Parameters:
title - Form title
elements - Form elements
Method Detail

getTitle

public java.lang.String getTitle()
Form title.


setBehaviourClass

public void setBehaviourClass(java.lang.Class<FormBehaviour> behaviour)
Set class representing the behaviour of this form.


createBehaviourInstance

public FormBehaviour createBehaviourInstance()
                                      throws FormRuntimeException
Create a new instance of the FormBehaviour of the form.

If no behaviour is attached, null is returned.

Throws:
FormRuntimeException - If the instantiation fails.

getElements

public java.util.List<FormElement> getElements()
Ordered list of the elements that make up the structure of the form.

Specified by:
getElements in interface ElementContainer

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

prettyPrintStructure

public void prettyPrintStructure()
Pretty-print the form structure (form elements) to System.out.


getDeepestLevel

public int getDeepestLevel()
Find out how many path elements exists to the deepest level of the structure.


lookupElement

public FormElement lookupElement(FormPath path)
                          throws InvalidPathException
Given a form path, find the form element that corresponds to it.

Throws:
InvalidPathException - If the given path does not match any elements in the form.

verify

public void verify()
            throws InconsistentFormException
Verify that the form is sound. This includes checking that the structure is legal, paths are unique, correctness of rules etc.

Throws:
InconsistentFormException - If a problem is found

createInstance

public FormInstance createInstance(InstanceCallback callback)
Create a concrete instance of the form that can be filled out and adapted.

Parameters:
callback - Callback that receives form events (at form completion etc.)

createInstance

public FormInstance createInstance(InstanceCallback callback,
                                   Localization localization)
Create a concrete instance of the form that can be filled out and adapted.

Parameters:
callback - Callback that receives form events (at form completion etc)
localization - Specific localization to use for this instance