junit.extensions.xml.elements
Class AbstractTagHandler

java.lang.Object
  extended byjunit.extensions.xml.elements.AbstractTagHandler
All Implemented Interfaces:
XMLConstants
Direct Known Subclasses:
AbstractAssertTagHandler, AssertTableContainsTagHandler, AssertTextFieldContainsTagHandler, AWTEventQueueTagHandler, BaseEventDataTagHandler, BaseFindTagHandler, ChooseTagHandler, ClickTagHandler, DragTagHandler, DumpTagHandler, EchoTagHandler, EvaluateTagHandler, FileTagHandler, FindTagHandler, ForeachTagHandler, IndexOfTagHandler, JFCEventManagerTagHandler, KeyTagHandler, NoOpTagHandler, ParentInstanceTagHandler, PathTagHandler, ProcedureTagHandler, PropertyTagHandler, SaveTagHandler, SleepTagHandler, StopWatchTagHandler, SuiteTagHandler, TagHandlersTagHandler, TestTagHandler, TokenizeTagHandler, WhileTagHandler

public abstract class AbstractTagHandler
extends java.lang.Object
implements XMLConstants

Sub-classes of this class will handle the processing of elements. It provides common access methods to the test case or test suite. It also provides methods for reading attributes.

Author:
Vijay Aravamudhan : ThoughtWorks Inc., Kevin Wilson

Field Summary
private  org.w3c.dom.Element m_element
          The Element to be processed.
private  IXMLTestCase m_testCase
          The IXMLTestCase that uses this element.
private  IXMLTestSuite m_testSuite
          The IXMLTestSuite that uses this element.
 
Fields inherited from interface junit.extensions.xml.XMLConstants
ACTION, ACTUALOBJ, ACTUALREFID, ADD, ASSERTENABLED, ASSERTEQUALS, ASSERTNOTEQUALS, ASSERTNOTNULL, ASSERTNOTSAME, ASSERTNULL, ASSERTSAME, CALL, CASE, CHOOSE, CLASSNAME, COLUMN, CONFIRM, DEBUG, DEFAULT, DELIMITER, DIALOG, DUMP, ECHO, ENABLED, ENCODING, EVALUATE, EXPECTEDOBJ, EXPECTEDREFID, FAIL, FILE, FOCUS, FOREACH, ID, INDEX, JFCFILELOC, LESSTHAN, LISTITEM, LOG, MARK, MESSAGE, METHOD, MODE, NAME, OTHERWISE, PATHREFID, PROCEDURE, PROPERTY, RECURSIVE, REFID, RELATIVE, REMOVE, ROW, SAVE, STDERR, STDOUT, STOPWATCH, SUITE, SWITCH, TABLECELL, TAGHANDLERS, TAGNAME, TEST, TYPE, USERE, VALUE, WHEN, WHILE
 
Constructor Summary
AbstractTagHandler(org.w3c.dom.Element element, IXMLTestCase testCase)
          Constructor for AbstractTagHandler.
AbstractTagHandler(org.w3c.dom.Element element, IXMLTestSuite testSuite)
          Constructor for AbstractTagHandler.
 
Method Summary
protected  void checkAtLeastOneRequiredAttribute(org.w3c.dom.Element root, java.lang.String[] attrName)
          Since all sub-classes might check for a required attribute, this method can be used for consistent messages.
protected  void checkAtLeastOneRequiredAttribute(java.lang.String[] attrName)
          Since all sub-classes might check for a required attribute, this method can be used for consistent messages.
protected  void checkElementTagName(java.lang.String expectedName)
          Since all sub-classes will check for the element tag name, this method can be used for consistent messages.
protected  void checkOneRequiredAttribute(org.w3c.dom.Element root, java.lang.String[] attrName)
          Since all sub-classes might check for a required attribute, this method can be used for consistent messages.
protected  void checkOneRequiredAttribute(java.lang.String[] attrName)
          Since all sub-classes might check for a required attribute, this method can be used for consistent messages.
protected  void checkRequiredAttribute(org.w3c.dom.Element e, java.lang.String attrName)
          Since all sub-classes might check for a required attribute, this method can be used for consistent messages.
protected  void checkRequiredAttribute(java.lang.String attrName)
          Since all sub-classes might check for a required attribute, this method can be used for consistent messages.
protected  boolean getBoolean(org.w3c.dom.Element e, java.lang.String attributeName)
          This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive boolean, if not, then returns false.
protected  boolean getBoolean(org.w3c.dom.Element e, java.lang.String attributeName, boolean defaultValue)
          This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive boolean, if not, then returns false.
protected  boolean getBoolean(java.lang.String attributeName)
          This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive boolean, if not, then returns false.
protected  boolean getBoolean(java.lang.String attributeName, boolean defaultValue)
          This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive boolean, if not, then returns false.
 org.w3c.dom.Element getElement()
          Returns the element.
protected  int getInt(org.w3c.dom.Element e, java.lang.String attributeName, int defaultValue)
          This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive int, if not, then returns the default value specified.
protected  int getInt(java.lang.String attributeName, int defaultValue)
          This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive int, if not, then returns the default value specified.
protected  long getLong(org.w3c.dom.Element e, java.lang.String attributeName, long defaultValue)
          This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive long, if not, then returns the default value specified.
protected  long getLong(java.lang.String attributeName, long defaultValue)
          This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive long, if not, then returns the default value specified.
protected  java.awt.Point getPoint(org.w3c.dom.Element e, java.lang.String attributeName, java.awt.Point defaultValue)
          This method checks whether the specified attribute is present, and if so, returns the value parsed as a Point, if not, then returns the default value specified.
protected  java.awt.Point getPoint(java.lang.String attributeName, java.awt.Point defaultValue)
          This method checks whether the specified attribute is present, and if so, returns the value parsed as a Point, if not, then returns the default value specified.
protected  java.lang.String getString(org.w3c.dom.Element e, java.lang.String attributeName)
          This method returns the value of the specified attribute.
protected  java.lang.String getString(org.w3c.dom.Element e, java.lang.String attributeName, java.lang.String defaultValue)
          Get the string assigned to the attributeName from the element.
protected  java.lang.String getString(java.lang.String attributeName)
          This method returns the value of the specified attribute.
protected  java.lang.String getString(java.lang.String attributeName, java.lang.String defaultValue)
          Get a the string assigned to a attribute from the current element.
protected  java.lang.String getTagName()
          Return the tag name of this element.
protected  IXMLTest getTest()
          Get the test.
 junit.framework.TestCase getTestCase()
          The JUnit framework test case.
 IXMLTestCase getXMLTestCase()
          Returns the testCase.
 IXMLTestSuite getXMLTestSuite()
          Returns the testSuite.
abstract  void processElement()
          This method is used to process the xml Element (i.e.
protected  java.lang.String resolveVariables(java.lang.String s)
          Replace variable names with the string of the variable values.
protected  void validateElement()
          Sub-classes should implement this method to provide validation of the element attributes, etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_element

private org.w3c.dom.Element m_element
The Element to be processed.


m_testCase

private IXMLTestCase m_testCase
The IXMLTestCase that uses this element.


m_testSuite

private IXMLTestSuite m_testSuite
The IXMLTestSuite that uses this element.

Constructor Detail

AbstractTagHandler

public AbstractTagHandler(org.w3c.dom.Element element,
                          IXMLTestCase testCase)
Constructor for AbstractTagHandler.

Parameters:
element - The element to be processed.
testCase - The testCase to be associated with the test.

AbstractTagHandler

public AbstractTagHandler(org.w3c.dom.Element element,
                          IXMLTestSuite testSuite)
Constructor for AbstractTagHandler.

Parameters:
element - The element to be processed.
testSuite - The testSuite to be associated with the test.
Method Detail

getElement

public final org.w3c.dom.Element getElement()
Returns the element.

Returns:
Element.

getTestCase

public final junit.framework.TestCase getTestCase()
The JUnit framework test case.

Returns:
TestCase in JUnit framework.

getXMLTestCase

public final IXMLTestCase getXMLTestCase()
Returns the testCase.

Returns:
IXMLTestCase.

getXMLTestSuite

public final IXMLTestSuite getXMLTestSuite()
Returns the testSuite.

Returns:
IXMLTestSuite.

processElement

public abstract void processElement()
                             throws XMLException
This method is used to process the xml Element (i.e. parsing and setting the attributes on XYZ objects from those parsed values.

Throws:
XMLException - Some kind of Exception might be thrown.

getTagName

protected final java.lang.String getTagName()
Return the tag name of this element.

Returns:
Tag name.

checkAtLeastOneRequiredAttribute

protected final void checkAtLeastOneRequiredAttribute(java.lang.String[] attrName)
                                               throws XMLException
Since all sub-classes might check for a required attribute, this method can be used for consistent messages.

Parameters:
attrName - The names of the attributes being checked.
Throws:
XMLException - A validation exception is thrown.

checkAtLeastOneRequiredAttribute

protected final void checkAtLeastOneRequiredAttribute(org.w3c.dom.Element root,
                                                      java.lang.String[] attrName)
                                               throws XMLException
Since all sub-classes might check for a required attribute, this method can be used for consistent messages.

Parameters:
root - The root Element whose attributes are being checked
attrName - The names of the attributes being checked.
Throws:
XMLException - A validation exception is thrown.

checkElementTagName

protected final void checkElementTagName(java.lang.String expectedName)
                                  throws XMLException
Since all sub-classes will check for the element tag name, this method can be used for consistent messages.

Parameters:
expectedName - The non-null expected string name.
Throws:
XMLException - A validation exception is thrown.

checkRequiredAttribute

protected final void checkRequiredAttribute(org.w3c.dom.Element e,
                                            java.lang.String attrName)
                                     throws XMLException
Since all sub-classes might check for a required attribute, this method can be used for consistent messages.

Parameters:
e - Element to be checked for the attribute.
attrName - The name of the attribute being checked.
Throws:
XMLException - A validation exception is thrown.

checkRequiredAttribute

protected final void checkRequiredAttribute(java.lang.String attrName)
                                     throws XMLException
Since all sub-classes might check for a required attribute, this method can be used for consistent messages.

Parameters:
attrName - The name of the attribute being checked.
Throws:
XMLException - A validation exception is thrown.

getBoolean

protected boolean getBoolean(java.lang.String attributeName)
This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive boolean, if not, then returns false.

Parameters:
attributeName - The name of the attribute whose value is needed.
Returns:
boolean The value of the attribute (false if not found).

getBoolean

protected boolean getBoolean(java.lang.String attributeName,
                             boolean defaultValue)
This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive boolean, if not, then returns false.

Parameters:
attributeName - The name of the attribute whose value is needed.
defaultValue - The default value
Returns:
boolean The value of the attribute (defaultValue if not found).

getBoolean

protected final boolean getBoolean(org.w3c.dom.Element e,
                                   java.lang.String attributeName)
This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive boolean, if not, then returns false.

Parameters:
e - Element to be searched.
attributeName - The name of the attribute whose value is needed.
Returns:
boolean The value of the attribute (false) if not found).

getBoolean

protected final boolean getBoolean(org.w3c.dom.Element e,
                                   java.lang.String attributeName,
                                   boolean defaultValue)
This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive boolean, if not, then returns false.

Parameters:
e - Element to be searched.
attributeName - The name of the attribute whose value is needed.
defaultValue - The default value.
Returns:
boolean The value of the attribute (defaultValue if not found).

getInt

protected int getInt(java.lang.String attributeName,
                     int defaultValue)
This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive int, if not, then returns the default value specified.

Parameters:
attributeName - The name of the attribute whose value is needed.
defaultValue - The default value to use if such an attribute is not present.
Returns:
int The value of the attribute.

getInt

protected int getInt(org.w3c.dom.Element e,
                     java.lang.String attributeName,
                     int defaultValue)
This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive int, if not, then returns the default value specified.

Parameters:
e - Element to be processed.
attributeName - The name of the attribute whose value is needed.
defaultValue - The default value to use if such an attribute is not present.
Returns:
int The value of the attribute.

getLong

protected long getLong(java.lang.String attributeName,
                       long defaultValue)
This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive long, if not, then returns the default value specified.

Parameters:
attributeName - The name of the attribute whose value is needed.
defaultValue - The default value to use if such an attribute is not present.
Returns:
long The value of the attribute.

getLong

protected long getLong(org.w3c.dom.Element e,
                       java.lang.String attributeName,
                       long defaultValue)
This method checks whether the specified attribute is present, and if so, returns the value parsed as a primitive long, if not, then returns the default value specified.

Parameters:
e - Element to be searched.
attributeName - The name of the attribute whose value is needed.
defaultValue - The default value to use if such an attribute is not present.
Returns:
long The value of the attribute.

getPoint

protected final java.awt.Point getPoint(java.lang.String attributeName,
                                        java.awt.Point defaultValue)
                                 throws XMLException
This method checks whether the specified attribute is present, and if so, returns the value parsed as a Point, if not, then returns the default value specified.

Parameters:
attributeName - The name of the attribute whose value is needed.
defaultValue - The default value to use if such an attribute is not present.
Returns:
Point The value of the attribute.
Throws:
XMLException - if the parse did not work.

getPoint

protected final java.awt.Point getPoint(org.w3c.dom.Element e,
                                        java.lang.String attributeName,
                                        java.awt.Point defaultValue)
                                 throws XMLException
This method checks whether the specified attribute is present, and if so, returns the value parsed as a Point, if not, then returns the default value specified.

Parameters:
e - Element to be searched.
attributeName - The name of the attribute whose value is needed.
defaultValue - The default value to use if such an attribute is not present.
Returns:
Point The value of the attribute.
Throws:
XMLException - is thrown if the element cannot be understood.

getString

protected final java.lang.String getString(java.lang.String attributeName)
This method returns the value of the specified attribute.

Parameters:
attributeName - The name of the attribute whose value is needed.
Returns:
String The value of the attribute.

getString

protected final java.lang.String getString(java.lang.String attributeName,
                                           java.lang.String defaultValue)
Get a the string assigned to a attribute from the current element.

Parameters:
attributeName - Name of the attribute to find.
defaultValue - Default value to return if the attribute is not present.
Returns:
String containing the attribute. Variable names will have been resolved.

getString

protected final java.lang.String getString(org.w3c.dom.Element e,
                                           java.lang.String attributeName)
This method returns the value of the specified attribute.

Parameters:
e - Element to be searched;
attributeName - The name of the attribute whose value is needed.
Returns:
String The value of the attribute.

getString

protected final java.lang.String getString(org.w3c.dom.Element e,
                                           java.lang.String attributeName,
                                           java.lang.String defaultValue)
Get the string assigned to the attributeName from the element. If the attributeName does not exist then return the default value.

Parameters:
e - Element to be checked.
attributeName - Name of the attribute to be returned.
defaultValue - Default value to be returned.
Returns:
String which has had variable names resolved.

checkOneRequiredAttribute

protected void checkOneRequiredAttribute(java.lang.String[] attrName)
                                  throws XMLException
Since all sub-classes might check for a required attribute, this method can be used for consistent messages.

Parameters:
attrName - The names of the attributes being checked.
Throws:
XMLException - A validation exception is thrown.

checkOneRequiredAttribute

protected void checkOneRequiredAttribute(org.w3c.dom.Element root,
                                         java.lang.String[] attrName)
                                  throws XMLException
Since all sub-classes might check for a required attribute, this method can be used for consistent messages.

Parameters:
root - The root Element whose attributes are being checked
attrName - The names of the attributes being checked.
Throws:
XMLException - A validation exception is thrown.

resolveVariables

protected final java.lang.String resolveVariables(java.lang.String s)
Replace variable names with the string of the variable values.

Parameters:
s - String to be substituted.
Returns:
String with substitutions made.

getTest

protected IXMLTest getTest()
Get the test.

Returns:
IXMLTest IXMLTest test case or test suite.

validateElement

protected void validateElement()
                        throws XMLException
Sub-classes should implement this method to provide validation of the element attributes, etc.

Throws:
XMLException - A validation exception is thrown.


Licensed under: GNU Lesser General Public License, Ver 2.1, February 1999