org.sadun.util.xml.configuration
Class BaseConfigurator

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byorg.sadun.util.xml.configuration.BaseConfigurator
All Implemented Interfaces:
Configurator, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
Direct Known Subclasses:
AutoConfigurator

public abstract class BaseConfigurator
extends org.xml.sax.helpers.DefaultHandler
implements Configurator

A base Configurator.

This class extends SAX's DefaultHandler and provides support for:

Subclasses which override endElement() should either invoke this class' implementation or set to true the protected completed field when the configured object is complete.

Author:
Cristiano Sadun

Field Summary
protected  java.lang.StringBuffer buffer
          The buffer collecting text received by characters().
protected  boolean completed
          Indicate that the object built from the XML is ready.
 
Constructor Summary
BaseConfigurator()
          Constructor for BaseConfigurator.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
protected  void checkCompleted()
          Throw an IllegalStateException if completed is not true.
protected abstract  java.lang.Object doGetConfiguredObject()
           
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
          Set completed to true.
protected  boolean getBooleanText(java.lang.String localName)
           
protected  byte getByteText(java.lang.String localName)
           
 java.lang.Object getConfiguredObject()
          Return the object resulting from the parsing of the specific XML element handled by this configurator, or null.
protected  double getDoubleText(java.lang.String localName)
           
protected  float getFloatText(java.lang.String localName)
           
protected  int getIntText(java.lang.String localName)
           
protected  long getLongText(java.lang.String localName)
           
protected  short getShortText(java.lang.String localName)
           
 java.lang.String getText()
          Return the text nodes resulting from the parsing of the specific XML element (if any) handled by this configurator, or null.
 java.lang.String getTextAndResetBuffer()
           
 java.lang.String getTextAndResetBuffer(boolean trim)
           
 boolean isCompleted()
          Returns the completed.
 java.lang.String toString()
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.sadun.util.xml.configuration.Configurator
startElement
 
Methods inherited from interface org.xml.sax.ContentHandler
endDocument, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping
 

Field Detail

buffer

protected java.lang.StringBuffer buffer
The buffer collecting text received by characters().


completed

protected boolean completed
Indicate that the object built from the XML is ready.

Constructor Detail

BaseConfigurator

public BaseConfigurator()
Constructor for BaseConfigurator.

Method Detail

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Set completed to true.

Specified by:
endElement in interface Configurator
Throws:
org.xml.sax.SAXException

getConfiguredObject

public final java.lang.Object getConfiguredObject()
                                           throws org.xml.sax.SAXException
Description copied from interface: Configurator
Return the object resulting from the parsing of the specific XML element handled by this configurator, or null.

Specified by:
getConfiguredObject in interface Configurator
Throws:
org.xml.sax.SAXException

checkCompleted

protected void checkCompleted()
Throw an IllegalStateException if completed is not true.


doGetConfiguredObject

protected abstract java.lang.Object doGetConfiguredObject()
                                                   throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Specified by:
characters in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

isCompleted

public boolean isCompleted()
Returns the completed.

Returns:
boolean

getText

public final java.lang.String getText()
Description copied from interface: Configurator
Return the text nodes resulting from the parsing of the specific XML element (if any) handled by this configurator, or null.

Specified by:
getText in interface Configurator

getTextAndResetBuffer

public final java.lang.String getTextAndResetBuffer()

getTextAndResetBuffer

public final java.lang.String getTextAndResetBuffer(boolean trim)

toString

public java.lang.String toString()

getBooleanText

protected boolean getBooleanText(java.lang.String localName)
                          throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

getShortText

protected short getShortText(java.lang.String localName)
                      throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

getIntText

protected int getIntText(java.lang.String localName)
                  throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

getLongText

protected long getLongText(java.lang.String localName)
                    throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

getByteText

protected byte getByteText(java.lang.String localName)
                    throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

getFloatText

protected float getFloatText(java.lang.String localName)
                      throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

getDoubleText

protected double getDoubleText(java.lang.String localName)
                        throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException