org.pf.pax
Class XMLWriteInterpreter

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.pf.pax.BaseXMLTagInterpreter
          extended by org.pf.pax.XMLWriteInterpreter
All Implemented Interfaces:
XMLTagInterpreter, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class XMLWriteInterpreter
extends BaseXMLTagInterpreter

The instances of this class are responsible for writing the tag's name, attributes and contents to the given MarkupWriter.

Version:
2.0
Author:
Manfred Duchrow

Constructor Summary
XMLWriteInterpreter(java.lang.String name, MarkupWriter writer)
          Initialize the new instance with default values.
 
Method Summary
 void characterData(java.lang.String data)
          This method is called whenever character data is received from the parser.
 java.lang.Object getResult()
          Returns the result object, created by this interpreter from the XML data .
 java.lang.String getTagName()
          Returns the name of the tag, the interpreter is responsible for.
 void restart(java.lang.String subTagName, java.lang.Object subResult)
          Restarts the receiver after interpretation of a sub tag.
 void start(java.lang.String elementName, org.xml.sax.Attributes attributes)
          Starts the work of the receiver the first time.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
          A new sub tag was found.
 
Methods inherited from class org.pf.pax.BaseXMLTagInterpreter
characters, endElement, invalidSubTagError, requiredAttributeError, setController
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
endDocument, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping
 

Constructor Detail

XMLWriteInterpreter

public XMLWriteInterpreter(java.lang.String name,
                           MarkupWriter writer)
Initialize the new instance with default values.

Method Detail

getTagName

public java.lang.String getTagName()
Description copied from class: BaseXMLTagInterpreter
Returns the name of the tag, the interpreter is responsible for.
It must be the exact tag name ( case-sensitive ) without opening and closing bracket ( '<' , '>' ).

Specified by:
getTagName in interface XMLTagInterpreter
Specified by:
getTagName in class BaseXMLTagInterpreter
Returns:
A string containing the name of the tag the receiver is made for.

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Description copied from class: BaseXMLTagInterpreter
A new sub tag was found. The control is passed to the controller for invocation of the correct tag interpreter.
After finishing this sub tag, the controller returns control to this interpreter by calling restart().
The restart method then gets the result object from this sub tag.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class BaseXMLTagInterpreter
Throws:
org.xml.sax.SAXException
See Also:
BaseXMLTagInterpreter.restart(String,Object), ContentHandler.startElement(String,String,String,Attributes)

start

public void start(java.lang.String elementName,
                  org.xml.sax.Attributes attributes)
           throws org.xml.sax.SAXException
Description copied from class: BaseXMLTagInterpreter
Starts the work of the receiver the first time.
This method must be overridden by subclasses. The subclass here normally creates a new object corresponding to the tag and the given attributes.

Specified by:
start in interface XMLTagInterpreter
Specified by:
start in class BaseXMLTagInterpreter
Parameters:
elementName - The name of the found element. Must be the same as this.getTagName().
attributes - The attributes defined in the start tag.
Throws:
org.xml.sax.SAXException - If the element name is wrong or any attribute is invalid.
See Also:
XMLTagInterpreter.getTagName()

restart

public void restart(java.lang.String subTagName,
                    java.lang.Object subResult)
             throws org.xml.sax.SAXException
Description copied from class: BaseXMLTagInterpreter
Restarts the receiver after interpretation of a sub tag.
When the work of sub tag interpreter has been finished by reaching its end tag, the control is passed back to the previous tag interpreter, one step higher in the hierarchy. The tag interpreter controller retreives the result object from that sub tag interpreter and gives it as an argument together with the sub tag's name to the restart method of the parent tag interpreter. Here the result of that sub tag can be put into a slot of this interpreter's object.

Specified by:
restart in interface XMLTagInterpreter
Specified by:
restart in class BaseXMLTagInterpreter
Parameters:
subTagName - The name of the sub tag that was completed
subResult - The resulting object build from the sub tag.
Throws:
org.xml.sax.SAXException - If the subtag is not allowed here.

getResult

public java.lang.Object getResult()
Returns the result object, created by this interpreter from the XML data .

Specified by:
getResult in class BaseXMLTagInterpreter
Returns:
The business object resulting from the parsed XML data.

characterData

public void characterData(java.lang.String data)
This method is called whenever character data is received from the parser.
In contrary to the ContentHandler.charachters() method it gets the data as string rather than a char[] array with start and length.
Subclasses must override this method, if their tag contains PCDATA. Here it's not defined as an abstract method, because the method's empty implementation is convenient for tag interpreters without PCDATA.

Overrides:
characterData in class BaseXMLTagInterpreter
Parameters:
data - The data received from the parser.
See Also:
ContentHandler.characters(char[],int,int)