gnu.java.beans.decoder

Class PersistenceParser

Implemented Interfaces:
ContentHandler, gnu.java.beans.decoder.Context, DTDHandler, EntityResolver, ErrorHandler

public class PersistenceParser
extends DefaultHandler
implements gnu.java.beans.decoder.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.

Constructor Summary

PersistenceParser(InputStream inputStream, ExceptionListener exceptionListener, ClassLoader cl, 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(Object o)
Adds a decoded object to the Context.
void
characters(char[] ch, int start, int length)
Transfers character data to the current handler
Object
endContext(gnu.java.beans.decoder.Context outerContext)
Notifies that the context ends and the returns the appropriate result object.
void
endElement(String uri, String localName, String qName)
Receive notification of the end of an element.
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.
String
getId()
Returns this Context's unique id or null if does not have such an id.
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).
Iterator<E>
iterator()
Returns an Iterator instance which returns the decoded objects.
void
notifyStatement(gnu.java.beans.decoder.Context outerContext)
Notifies that the next element is a statement.
void
set(int index, 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(String id)
Gives this Context a unique id.
void
setStatement(boolean b)
Sets whether this Context is a statement or not.
void
startElement(String uri, String localName, String qName, 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

characters, endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl, warning

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

PersistenceParser

public PersistenceParser(InputStream inputStream,
                         ExceptionListener exceptionListener,
                         ClassLoader cl,
                         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.
Parameters:
inputStream -
exceptionListener -
cl -

Method Details

addParameterObject

public void addParameterObject(Object o)
            throws gnu.java.beans.decoder.AssemblyException
Adds a decoded object to the Context.
Specified by:
addParameterObject in interface gnu.java.beans.decoder.Context

characters

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

endContext

public Object endContext(gnu.java.beans.decoder.Context outerContext)
            throws gnu.java.beans.decoder.AssemblyException
Notifies that the context ends and the returns the appropriate result object.
Specified by:
endContext in interface gnu.java.beans.decoder.Context
Parameters:
outerContext -
Returns:

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
            throws SAXException
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 ContentHandler
Overrides:
endElement in interface DefaultHandler
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

get

public Object get(int index)
            throws gnu.java.beans.decoder.AssemblyException
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 gnu.java.beans.decoder.Context
Parameters:
index - Index position of the object return.

getId

public String getId()
Returns this Context's unique id or null if does not have such an id.
Specified by:
getId in interface gnu.java.beans.decoder.Context
Returns:
This Context's id or null.

getResult

public Object getResult()
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 gnu.java.beans.decoder.Context
Returns:

isStatement

public boolean isStatement()
Returns whether this Context is a statement (not returning result back to parent handler's Context) or not (= expression).
Specified by:
isStatement in interface gnu.java.beans.decoder.Context
Returns:

iterator

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

notifyStatement

public void notifyStatement(gnu.java.beans.decoder.Context outerContext)
            throws gnu.java.beans.decoder.AssemblyException
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 gnu.java.beans.decoder.Context

set

public void set(int index,
                Object o)
            throws gnu.java.beans.decoder.AssemblyException
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 gnu.java.beans.decoder.Context
Parameters:
index - Index position to be set.
o - Object to be set at the given index position.

setId

public void setId(String id)
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 gnu.java.beans.decoder.Context
Parameters:
id -

setStatement

public void setStatement(boolean b)
Sets whether this Context is a statement or not.
Specified by:
setStatement in interface gnu.java.beans.decoder.Context
Parameters:
b -

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes attributes)
            throws SAXException
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 ContentHandler
Overrides:
startElement in interface DefaultHandler
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
attributes - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

subContextFailed

public boolean subContextFailed()
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 gnu.java.beans.decoder.Context
Returns:
Whether the failure of a subcontext lets this context fail, too.

gnu.java.beans.PersistenceParser Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.