org.exolab.castor.xml

Class UnmarshalHandler

Implemented Interfaces:
ContentHandler, DocumentHandler, ErrorHandler

public final class UnmarshalHandler
extends MarshalFramework
implements ContentHandler, DocumentHandler, ErrorHandler

An unmarshaller to allowing unmarshalling of XML documents to Java Objects. The Class must specify the proper access methods (setters/getters) in order for instances of the Class to be properly unmarshalled.
Version:
$Revision: 6392 $ $Date: 2006-05-25 06:41:12 -0600 (Thu, 25 May 2006) $
Author:
Keith Visco

Nested Class Summary

(package private) class
UnmarshalHandler.Arguments
Internal class used for passing constructor argument information
static class
UnmarshalHandler.ArrayHandler
A class for handling Arrays during unmarshalling.
(package private) class
UnmarshalHandler.ElementInfo
A utility class for keeping track of the qName and how the SAX parser passed attributes
(package private) class
UnmarshalHandler.IDResolverImpl
Local IDResolver
(package private) class
UnmarshalHandler.ReferenceInfo
Internal class used to save state for reference resolving

Nested classes/interfaces inherited from class org.exolab.castor.xml.MarshalFramework

MarshalFramework.InheritanceMatch, MarshalFramework.InternalXMLClassDescriptor

Field Summary

Fields inherited from class org.exolab.castor.xml.MarshalFramework

INTERNAL_XML_NAME, JAVA_PREFIX, LANG_ATTR, NIL_ATTR, NO_FIELD_DESCRIPTORS, QNAME_NAME, SPACE_ATTR, TRUE_VALUE, TYPE_ATTR, XML_LANG_ATTR, XML_SPACE_ATTR, XSI_NAMESPACE, XSI_NIL_ATTR, XSI_NO_NAMESPACE_SCHEMA_LOCATION, XSI_SCHEMA_LOCATION

Constructor Summary

UnmarshalHandler()
Creates a new UnmarshalHandler The "root" class will be obtained by looking into the mapping for a descriptor that matches the root element.
UnmarshalHandler(Class _class)
Creates a new UnmarshalHandler

Method Summary

void
addNamespaceToPackageMapping(String nsURI, String packageName)
Adds a mapping from the given namespace URI to the given package name
void
characters(char[] ch, int start, int length)
void
endDocument()
void
endElement(String name)
void
endElement(String namespaceURI, String localName, String qName)
ContentHandler#endElement Signals the end of an element
void
endPrefixMapping(String prefix)
Signals to end the namespace prefix mapping
void
error(SAXParseException exception)
void
fatalError(SAXParseException exception)
Object
getCurrentObject()
Returns the Object that the UnmarshalHandler is currently handling (within the object model), or null if the current element is a simpleType.
Locator
getDocumentLocator()
Object
getObject()
Returns the "root" Object (ie.
ObjectFactory
getObjectFactory()
Returns the ObjectFactory instance in use.
void
ignorableWhitespace(char[] ch, int start, int length)
void
processingInstruction(String target, String data)
void
setClassLoader(ClassLoader loader)
Sets the ClassLoader to use when loading classes
void
setClearCollections(boolean clear)
Sets whether or not to clear collections (including arrays) upon first use to remove default values.
protected void
setConfiguration(Configuration config)
Sets the current Castor configuration.
void
setDebug(boolean debug)
Turns debuging on or off.
void
setDocumentLocator(Locator locator)
void
setIDResolver(IDResolver idResolver)
Sets the IDResolver to use when resolving IDREFs for which no associated element may exist in XML document.
void
setIgnoreExtraAttributes(boolean ignoreExtraAtts)
Sets whether or not attributes that do not match a specific field should simply be ignored or reported as an error.
void
setIgnoreExtraElements(boolean ignoreExtraElems)
Sets whether or not elements that do not match a specific field should simply be ignored or reported as an error.
void
setLogWriter(PrintWriter printWriter)
Sets the PrintWriter used for printing log messages
void
setObjectFactory(ObjectFactory objectFactory)
Sets a (custom) ObjectFactory instance.
void
setResolver(XMLClassDescriptorResolver cdResolver)
Sets the ClassDescriptorResolver to use for loading and resolving ClassDescriptors
void
setReuseObjects(boolean reuse)
Sets a boolean that when true indicates that objects contained within the object model should be re-used where appropriate.
void
setRootObject(Object root)
Sets the root (top-level) object to use for unmarshalling into.
void
setUnmarshalListener(UnmarshalListener listener)
Sets an UnmarshalListener.
void
setValidation(boolean validate)
Sets the flag for validation.
void
setWhitespacePreserve(boolean preserve)
Sets the top-level whitespace (xml:space) to either preserving or non preserving.
void
skippedEntity(String name)
Signals that an entity was skipped by the parser
void
startDocument()
Signals the start of a new document
void
startElement(String name, AttributeList attList)
DocumentHandler#startElement Signals the start of element.
void
startElement(String namespaceURI, String localName, String qName, Attributes atts)
ContentHandler#startElement Signals the start of element.
void
startPrefixMapping(String prefix, String uri)
Signals to start the namespace - prefix mapping
static Object
toPrimitiveObject(Class type, String value)
Converts a String to the given primitive object type
void
warning(SAXParseException exception)

Methods inherited from class org.exolab.castor.xml.MarshalFramework

getCollectionHandler, hasFieldsAtLocation, isCollection, isPrimitive, namespaceEquals, primitiveOrWrapperEquals, searchInheritance

Constructor Details

UnmarshalHandler

protected UnmarshalHandler()
Creates a new UnmarshalHandler The "root" class will be obtained by looking into the mapping for a descriptor that matches the root element.

UnmarshalHandler

protected UnmarshalHandler(Class _class)
Creates a new UnmarshalHandler
Parameters:
_class - the Class to create the UnmarshalHandler for

Method Details

addNamespaceToPackageMapping

public void addNamespaceToPackageMapping(String nsURI,
                                         String packageName)
Adds a mapping from the given namespace URI to the given package name
Parameters:
nsURI - the namespace URI to map from
packageName - the package name to map to

characters

public void characters(char[] ch,
                       int start,
                       int length)
            throws SAXException

endDocument

public void endDocument()
            throws org.xml.sax.SAXException

endElement

public void endElement(String name)
            throws org.xml.sax.SAXException

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
            throws org.xml.sax.SAXException
ContentHandler#endElement Signals the end of an element
Parameters:
localName - The name of the element.

endPrefixMapping

public void endPrefixMapping(String prefix)
            throws SAXException
Signals to end the namespace prefix mapping
Parameters:
prefix - the namespace prefix

error

public void error(SAXParseException exception)
            throws org.xml.sax.SAXException

fatalError

public void fatalError(SAXParseException exception)
            throws org.xml.sax.SAXException

getCurrentObject

public Object getCurrentObject()
Returns the Object that the UnmarshalHandler is currently handling (within the object model), or null if the current element is a simpleType.
Returns:
the Object currently being unmarshalled, or null if the current element is a simpleType.

getDocumentLocator

public Locator getDocumentLocator()

getObject

public Object getObject()
Returns the "root" Object (ie. the entire object model) being unmarshalled.
Returns:
the root Object being unmarshalled.

getObjectFactory

public ObjectFactory getObjectFactory()
Returns the ObjectFactory instance in use.
Returns:
the ObjectFactory instance in use.

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
            throws org.xml.sax.SAXException

processingInstruction

public void processingInstruction(String target,
                                  String data)
            throws org.xml.sax.SAXException

setClassLoader

public void setClassLoader(ClassLoader loader)
Sets the ClassLoader to use when loading classes
Parameters:
loader - the ClassLoader to use

setClearCollections

public void setClearCollections(boolean clear)
Sets whether or not to clear collections (including arrays) upon first use to remove default values. By default, and for backward compatibility with previous versions of Castor this value is false, indicating that collections are not cleared before initial use by Castor.
Parameters:
clear - the boolean value that when true indicates collections should be cleared upon first use.

setConfiguration

protected void setConfiguration(Configuration config)
Sets the current Castor configuration. Currently this Configuration is only used during Validation (which is why this method is currently protected, since it has no effect at this point on the actual configuration of the unmarshaller) Currently, this method should only be called by the Unmarshaller.

setDebug

public void setDebug(boolean debug)
Turns debuging on or off. If no Log Writer has been set, then System.out will be used to display debug information
Parameters:
debug - the flag indicating whether to generate debug information. A value of true, will turn debuggin on.

setDocumentLocator

public void setDocumentLocator(Locator locator)

setIDResolver

public void setIDResolver(IDResolver idResolver)
Sets the IDResolver to use when resolving IDREFs for which no associated element may exist in XML document.
Parameters:
idResolver - the IDResolver to use when resolving IDREFs for which no associated element may exist in the XML document.

setIgnoreExtraAttributes

public void setIgnoreExtraAttributes(boolean ignoreExtraAtts)
Sets whether or not attributes that do not match a specific field should simply be ignored or reported as an error. By default, extra attributes are ignored.
Parameters:
ignoreExtraAtts - a boolean that when true will allow non-matched attributes to simply be ignored.

setIgnoreExtraElements

public void setIgnoreExtraElements(boolean ignoreExtraElems)
Sets whether or not elements that do not match a specific field should simply be ignored or reported as an error. By default, extra attributes are ignored.
Parameters:
ignoreExtraElems - a boolean that when true will allow non-matched attributes to simply be ignored.

setLogWriter

public void setLogWriter(PrintWriter printWriter)
Sets the PrintWriter used for printing log messages
Parameters:
printWriter - the PrintWriter to use when printing log messages

setObjectFactory

public void setObjectFactory(ObjectFactory objectFactory)
Sets a (custom) ObjectFactory instance.
Parameters:
objectFactory - A (custom) ObjectFactory instance

setResolver

public void setResolver(XMLClassDescriptorResolver cdResolver)
Sets the ClassDescriptorResolver to use for loading and resolving ClassDescriptors
Parameters:
cdResolver - the ClassDescriptorResolver to use

setReuseObjects

public void setReuseObjects(boolean reuse)
Sets a boolean that when true indicates that objects contained within the object model should be re-used where appropriate. This is only valid when unmarshalling to an existing object.
Parameters:
reuse - the boolean indicating whether or not to re-use existing objects in the object model.

setRootObject

public void setRootObject(Object root)
Sets the root (top-level) object to use for unmarshalling into.
Parameters:
root - the instance to unmarshal into.

setUnmarshalListener

public void setUnmarshalListener(UnmarshalListener listener)
Parameters:
listener - the UnmarshalListener to use with this instance of the UnmarshalHandler.

setValidation

public void setValidation(boolean validate)
Sets the flag for validation.
Parameters:
validate - A boolean to indicate whether or not validation should be done during umarshalling.
By default, validation will be performed.

setWhitespacePreserve

public void setWhitespacePreserve(boolean preserve)
Sets the top-level whitespace (xml:space) to either preserving or non preserving. The XML document can override this value using xml:space on specific elements. This sets the "default" behavior when xml:space="default".
Parameters:
preserve - a boolean that when true enables whitespace preserving by default.

skippedEntity

public void skippedEntity(String name)
            throws SAXException
Signals that an entity was skipped by the parser
Parameters:
name - the skipped entity's name

startDocument

public void startDocument()
            throws org.xml.sax.SAXException
Signals the start of a new document

startElement

public void startElement(String name,
                         AttributeList attList)
            throws org.xml.sax.SAXException
DocumentHandler#startElement Signals the start of element.
Parameters:
name - The name of the element.
attList - The AttributeList containing the associated attributes for the element.

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes atts)
            throws org.xml.sax.SAXException
ContentHandler#startElement Signals the start of element.
Parameters:
localName - The name of the element.
atts - The AttributeList containing the associated attributes for the element.

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
            throws SAXException
Signals to start the namespace - prefix mapping
Parameters:
prefix - the namespace prefix to map
uri - the namespace URI

toPrimitiveObject

public static Object toPrimitiveObject(Class type,
                                       String value)
Converts a String to the given primitive object type
Parameters:
type - the class type of the primitive in which to convert the String to
value - the String to convert to a primitive
Returns:
the new primitive Object

warning

public void warning(SAXParseException exception)
            throws org.xml.sax.SAXException

Intalio Inc. (C) 1999-2006. All rights reserved http://www.intalio.com