com.softwareag.tamino.db.api.objectModel.stream
Class TStreamRootElementHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.softwareag.tamino.db.api.objectModel.stream.TStreamRootElementHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class TStreamRootElementHandler
extends org.xml.sax.helpers.DefaultHandler

TStreamRootElementHandler is a DefaultHandler that simply handles all events until the startElement event for the root element has been processed. It analyzes the entire content of the root element and keeps it accessible. After processing the root elements start tag event a TSAXRootElementEnded exception is thrown so that the associated SAX parser is stopped in a controlled way. However an ino:id and ino:docname attribute can be set on the underlying root element tag.

Version:
$Revision: 1.5 $
Author:
Marcus Schreyer

Constructor Summary
TStreamRootElementHandler()
          Initialzes the handler.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Receive notification of character content for a specific element.
 void endDocument()
          Receive notification for the end of the document.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
          Receive notification of the ending of an element.
 java.lang.String getDocname()
          Gets the ino:docname from the underlying root element.
 java.lang.String getId()
          Gets the ino:id from the underlying root element.
 java.lang.String getRootElementAsString()
          Gets the root element given by the previous event handling as a String.
static java.lang.Exception getRootElementEndedException()
          Gets the static TSAXRootElementEnded exception instances which this handler always throws to its associated parser once the processing of the root element ended.
 java.lang.String getTagName()
          Gets the name of the root element.
 boolean hasRootElement()
          Indicates if currently a root element is given defined by the event handling of the previous parsing.
 void setDocname(java.lang.String docname)
          Sets the ino:docname on the for the underlying root element.
 void setId(java.lang.String id)
          Sets the ino:id for the underlying root element.
 void startDocument()
          Receive notification for the start of a document.
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
          Receive notification of the beginning of an element.
 void writeRootElementTo(java.io.Writer writer)
          Writes the internal root element given by the previous event handling to the given character output stream.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TStreamRootElementHandler

public TStreamRootElementHandler()
Initialzes the handler.

Method Detail

getRootElementEndedException

public static java.lang.Exception getRootElementEndedException()
Gets the static TSAXRootElementEnded exception instances which this handler always throws to its associated parser once the processing of the root element ended. Can be used on the client side to verify if a SAXException is related to this exception instance.

Returns:
TSAXRootElementEnded exception instance.

setDocname

public void setDocname(java.lang.String docname)
Sets the ino:docname on the for the underlying root element.

Parameters:
docname - is the ino:docname attribute of the data object.

setId

public void setId(java.lang.String id)
Sets the ino:id for the underlying root element.

Parameters:
id - denotes the ino:id that has to be set on the underlying element.

getDocname

public java.lang.String getDocname()
Gets the ino:docname from the underlying root element.

Returns:
the ino:docname of the root element, an empty string if none is available.

getId

public java.lang.String getId()
Gets the ino:id from the underlying root element.

Returns:
the ino:id of the root element, an empty string if none is available.

getTagName

public java.lang.String getTagName()
Gets the name of the root element.

Returns:
the name of the root element, an empty string if none is given yet.

hasRootElement

public boolean hasRootElement()
Indicates if currently a root element is given defined by the event handling of the previous parsing.

Returns:
true if a root element is currently given, false otherwise.

writeRootElementTo

public void writeRootElementTo(java.io.Writer writer)
                        throws java.io.IOException
Writes the internal root element given by the previous event handling to the given character output stream. If either an id or docname has been explicitly set by a client it is appropiately reflected by the correspoding attributes for the root element.

Parameters:
writer - is the character output stream to which to root element is written.
Throws:
java.io.IOException

getRootElementAsString

public java.lang.String getRootElementAsString()
Gets the root element given by the previous event handling as a String. If either an id or docname has been explicitly set by a client it is appropiately reflected by the correspoding attributes for the root element.


startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Receive notification for the start of a document.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Receive notification of the beginning of an element. If the event is referred to the root element its corresponding state is safed. For any other element event a PreconditionViolation is thrown.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Receive notification of the ending of an element. Always throws a PreconditionViolation.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Receive notification of character content for a specific element. Always throws a PreconditionViolation.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Receive notification for the end of the document. Always throws a PreconditionViolation.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException


Copyright (c) 2013 Software AG. All Rights Reserved.