Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

gnu.java.beans.decoder
Class PersistenceParser  view PersistenceParser download PersistenceParser.java

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended bygnu.java.beans.decoder.PersistenceParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, Context, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class PersistenceParser
extends org.xml.sax.helpers.DefaultHandler
implements Context

The PersistenceParser parses an XML data stream and delegates actions to ElementHandler instances. The parser catches and recovers from all exception which reside from wrong usage of attributes and tags.


Nested Class Summary
(package private)  class PersistenceParser.ArrayHandlerCreator
           
(package private)  class PersistenceParser.BooleanHandlerCreator
           
(package private)  class PersistenceParser.ByteHandlerCreator
           
(package private)  class PersistenceParser.CharHandlerCreator
           
(package private)  class PersistenceParser.ClassHandlerCreator
           
(package private) static interface PersistenceParser.Creator
          Creator interface provided a mechanism to instantiate ElementHandler instances for the appropriate tag.
(package private)  class PersistenceParser.DoubleHandlerCreator
           
(package private)  class PersistenceParser.FloatHandlerCreator
           
(package private)  class PersistenceParser.IntHandlerCreator
           
(package private)  class PersistenceParser.JavaHandlerCreator
           
(package private)  class PersistenceParser.LongHandlerCreator
           
(package private)  class PersistenceParser.NullHandlerCreator
           
(package private)  class PersistenceParser.ObjectHandlerCreator
           
(package private)  class PersistenceParser.ShortHandlerCreator
           
(package private)  class PersistenceParser.StringHandlerCreator
           
(package private)  class PersistenceParser.VoidHandlerCreator
           
 
Field Summary
private  ElementHandler currentHandler
          Denotes the current ElementHandler.
private  java.beans.XMLDecoder decoder
          The XMLDecoder instance that started this PersistenceParser
private  java.beans.ExceptionListener exceptionListener
          The ExceptionListener instance which is informed of non-critical parsing exceptions.
private  java.util.HashMap handlerCreators
          Stores the Creator instances which can instantiate the appropriate handler implementation for a given element.
(package private)  JavaHandler javaHandler
          The real root element that stores all objects created during parsing.
private  java.util.List objects
          Stores the decoded objects.
private  int skipElement
          When an element was not usable all elements inside it should be skipped.
 
Constructor Summary
PersistenceParser(java.io.InputStream inputStream, java.beans.ExceptionListener exceptionListener, java.lang.ClassLoader cl, java.beans.XMLDecoder decoder)
          Creates a PersistenceParser which reads XML data from the given InputStream, reports exceptions to ExceptionListener instance, stores resulting object in the DecoderContext and uses the given ClassLoader to resolve classes.
 
Method Summary
 void addParameterObject(java.lang.Object o)
          Adds a decoded object to the Context.
 void characters(char[] ch, int start, int length)
          Transfers character data to the current handler
 java.lang.Object endContext(Context outerContext)
          Notifies that the context ends and the returns the appropriate result object.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Receive notification of the end of an element.
 java.lang.Object get(int index)
          Calls an appropriate indexed get method if it is available or throws an AssemblerException if that is not allowed on this Context.
 java.lang.String getId()
          Returns this Context's unique id or null if does not have such an id.
 java.lang.Object getResult()
          Returns the result which was calculated by calling endContext() or reportStatement().
 boolean isStatement()
          Returns whether this Context is a statement (not returning result back to parent handler's Context) or not (= expression).
 java.util.Iterator iterator()
          Returns an Iterator instance which returns the decoded objects.
 void notifyStatement(Context outerContext)
          Notifies that the next element is a statement.
 void set(int index, java.lang.Object o)
          Calls an appropriate indexed set method if it is available or throws an AssemblerException if that is not allowed on this Context.
 void setId(java.lang.String id)
          Gives this Context a unique id.
 void setStatement(boolean b)
          Sets whether this Context is a statement or not.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
          Receive notification of the start of an element.
 boolean subContextFailed()
          Notifies that the assembly of a subcontext failed and returns whether this Context is affected in a way that it fails too.
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

exceptionListener

private java.beans.ExceptionListener exceptionListener
The ExceptionListener instance which is informed of non-critical parsing exceptions.


skipElement

private int skipElement
When an element was not usable all elements inside it should be skipped. This is done by skipping startElement() and endElement() invocations whenever this value is above 0.


handlerCreators

private java.util.HashMap handlerCreators
Stores the Creator instances which can instantiate the appropriate handler implementation for a given element.


currentHandler

private ElementHandler currentHandler
Denotes the current ElementHandler. To avoid checking for null-values it is pre-assigned with a DummyHandler instance which must not be used but acts as a root element.


javaHandler

JavaHandler javaHandler
The real root element that stores all objects created during parsing. Package-private to avoid an accessor method.


objects

private java.util.List objects
Stores the decoded objects.


decoder

private java.beans.XMLDecoder decoder
The XMLDecoder instance that started this PersistenceParser

Constructor Detail

PersistenceParser

public PersistenceParser(java.io.InputStream inputStream,
                         java.beans.ExceptionListener exceptionListener,
                         java.lang.ClassLoader cl,
                         java.beans.XMLDecoder decoder)
Creates a PersistenceParser which reads XML data from the given InputStream, reports exceptions to ExceptionListener instance, stores resulting object in the DecoderContext and uses the given ClassLoader to resolve classes.

Method Detail

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: org.xml.sax.helpers.DefaultHandler
Receive notification of the start of an element.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).

Specified by:
startElement in interface org.xml.sax.ContentHandler

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Description copied from class: org.xml.sax.helpers.DefaultHandler
Receive notification of the end of an element.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).

Specified by:
endElement in interface org.xml.sax.ContentHandler

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Transfers character data to the current handler

Specified by:
characters in interface org.xml.sax.ContentHandler

addParameterObject

public void addParameterObject(java.lang.Object o)
                        throws AssemblyException
Adds a decoded object to the Context.

Specified by:
addParameterObject in interface Context

notifyStatement

public void notifyStatement(Context outerContext)
                     throws AssemblyException
Description copied from interface: Context
Notifies that the next element is a statement. This can mean that an argument list is complete to be called.

Specified by:
notifyStatement in interface Context

endContext

public java.lang.Object endContext(Context outerContext)
                            throws AssemblyException
Description copied from interface: Context
Notifies that the context ends and the returns the appropriate result object.

Specified by:
endContext in interface Context

subContextFailed

public boolean subContextFailed()
Description copied from interface: Context
Notifies that the assembly of a subcontext failed and returns whether this Context is affected in a way that it fails too.

Specified by:
subContextFailed in interface Context

set

public void set(int index,
                java.lang.Object o)
         throws AssemblyException
Description copied from interface: Context
Calls an appropriate indexed set method if it is available or throws an AssemblerException if that is not allowed on this Context. The behaviour of this method is equal to List.set(int, Object).

Specified by:
set in interface Context

get

public java.lang.Object get(int index)
                     throws AssemblyException
Description copied from interface: Context
Calls an appropriate indexed get method if it is available or throws an AssemblerException if that is not allowed on this Context. The behaviour of this method is equal to List.get(int).

Specified by:
get in interface Context

getResult

public java.lang.Object getResult()
Description copied from interface: Context
Returns the result which was calculated by calling endContext() or reportStatement(). Its the handler's responsibility to care that any of these two methods was called. This is used by sub-Contexts to access this Context's result.

Specified by:
getResult in interface Context

setId

public void setId(java.lang.String id)
Description copied from interface: Context
Gives this Context a unique id. For convenience the id may be null which means that no id exists at all.

Specified by:
setId in interface Context

getId

public java.lang.String getId()
Description copied from interface: Context
Returns this Context's unique id or null if does not have such an id.

Specified by:
getId in interface Context

isStatement

public boolean isStatement()
Description copied from interface: Context
Returns whether this Context is a statement (not returning result back to parent handler's Context) or not (= expression).

Specified by:
isStatement in interface Context

setStatement

public void setStatement(boolean b)
Description copied from interface: Context
Sets whether this Context is a statement or not.

Specified by:
setStatement in interface Context

iterator

public java.util.Iterator iterator()
Returns an Iterator instance which returns the decoded objects. This method is used by the XMLDecoder directly.