javax.xml.bind.helpers
Class AbstractUnmarshallerImpl
java.lang.Object
javax.xml.bind.helpers.AbstractUnmarshallerImpl
- Unmarshaller
public abstract class AbstractUnmarshallerImpl
extends java.lang.Object
This is an abstract default implementation of an
Unmarshaller
. Subclasses only need to implement
Unmarshaller.getUnmarshallerHandler()
,
javax.xml.bind.Unmarshaller.unmarshal(org.w3c.dom.Node)
, and
unmarshal(org.xml.sax.XMLReader, org.xml.sax.InputSource)
.
protected UnmarshalException | createUnmarshalException(SAXException pException) - Helper method to concert a
org.xml.sax.SAXException
into an UnmarshalException .
|
ValidationEventHandler | getEventHandler() - If the JAXB application has registered a custom handler
for validation events, returns that handler.
|
Object | getProperty(String pName) - Always throws a
PropertyException ,
because the default implementation does not support any
properties.
|
protected XMLReader | getXMLReader() - Creates a configured
org.xml.sax.XMLReader .
|
boolean | isValidating() - Sets whether the
Unmarshaller is validating
the objects that it reads.
|
void | setEventHandler(ValidationEventHandler pHandler) - An application may customize the Unmarshallers behaviour
in case of validation problems by supplying a custom handler
for validation events.
|
void | setProperty(String pName, Object pValue) - Always throws a
PropertyException ,
because the default implementation does not support any
properties.
|
void | setValidating(boolean pValidating) - Sets whether the
Unmarshaller is validating
the objects that it reads.
|
Object | unmarshal(InputSource pSource) - The Unmarshaller reads the byte stream or character
stream referred by the
org.xml.sax.InputSource
and converts it into an equivalent JAXB object.
|
java.lang.Object | unmarshal(InputStream pSource)
|
Object | unmarshal(Source pSource) - The Unmarshaller reads the XML representation from the given
Source and converts it into an equivalent JAXB object.
|
protected abstract java.lang.Object | unmarshal(XMLReader pReader, InputSource pSource) - Unmarshals an object by using the given instance
of
org.xml.sax.XMLReader to parse the XML
document read from the byte or character stream
given by the org.xml.sax.InputSource
pSource .
|
java.lang.Object | unmarshal(java.io.File pFile) - This method takes opens the given file
pFile
for input.
|
java.lang.Object | unmarshal(java.net.URL pURL) - This method takes connects to the given
pURL
and opens a byte stream for input.
|
AbstractUnmarshallerImpl
public AbstractUnmarshallerImpl()
Creates a new instance of AbstractUnmarshallerImpl.
createUnmarshalException
protected UnmarshalException createUnmarshalException(SAXException pException)
getEventHandler
public ValidationEventHandler getEventHandler()
throws JAXBException
If the JAXB application has registered a custom handler
for validation events, returns that handler. Otherwise returns
the default handler, which is triggering an exception in case
of errors and fatal errors.
- getEventHandler in interface Unmarshaller
getXMLReader
protected XMLReader getXMLReader()
throws JAXBException
Creates a configured org.xml.sax.XMLReader
.
Unmarshaller is not re-entrant, so we will use a single instance
of org.xml.sax.XMLReader
.
JAXBException
- Encapsulates a
javax.xml.parsers.ParserConfigurationException
isValidating
public boolean isValidating()
throws JAXBException
Sets whether the Unmarshaller
is validating
the objects that it reads. The default is false.
- isValidating in interface Unmarshaller
- True, if the
Unmarshaller
is validating the objects
that it reads, false otherwise.
setEventHandler
public void setEventHandler(ValidationEventHandler pHandler)
throws JAXBException
An application may customize the Unmarshallers behaviour
in case of validation problems by supplying a custom handler
for validation events. The default handler will trigger an
exception in case of errors and fatal errors.
- setEventHandler in interface Unmarshaller
pHandler
- The custom event handler or null to restore
the default event handler.
setValidating
public void setValidating(boolean pValidating)
throws JAXBException
Sets whether the
Unmarshaller
is validating
the objects that it reads. The default is false.
Note: A validating unmarshaller will rarely use
a validating SAX parser by default! It does so, because the
SAX parsers validation and the Unmarshallers builtin
validation would most probably validate the same things,
resulting in no additional safety at the cost of wasting
performance. Second, a SAX parser is not always in use.
For example, you do not need a parser when
converting a DOM Node. If you insist in a validating XML
parser, then you should create your own
org.xml.sax.XMLReader
and use the method
unmarshal(javax.xml.transform.Source)
.
- setValidating in interface Unmarshaller
pValidating
- Whether the Unmarshaller
should validate
or not.
unmarshal
public final Object unmarshal(InputSource pSource)
throws JAXBException
The Unmarshaller reads the byte stream or character
stream referred by the org.xml.sax.InputSource
and converts it into an equivalent JAXB object.
- unmarshal in interface Unmarshaller
pSource
- The InputSource
referring to a byte or
character stream. It is recommended, that the system ID is
set. This may be required, if the XML in the stream refers
to external entities.
- The JAXB object read from the byte or character stream.
JAXBException
- An unexpected problem (for example an
IOException) occurred.
unmarshal
public final java.lang.Object unmarshal(InputStream pSource)
throws JAXBException
unmarshal
public Object unmarshal(Source pSource)
throws JAXBException
The Unmarshaller reads the XML representation from the given
Source
and converts it into an equivalent JAXB object.
The JAXB provider must support at least
javax.xml.transform.sax.SAXSource
,
javax.xml.transform.dom.DOMSource
, and
javax.xml.transform.stream.StreamSource
. A possible
implementation could validate whether the argument is actually
an instance of these subinterfaces. If so, it might simply
act like
Unmarshaller.getUnmarshallerHandler()
,
unmarshal(org.w3c.dom.Node)
,
Unmarshaller.unmarshal(InputStream)
, or
unmarshal(org.xml.sax.InputSource)
, respectively.
Note: If you are not using the standard JAXP
mechanism for obtaining an
org.xml.sax.XMLReader
,
then you might create your own SAX parser and invoke the
pSource
arguments
javax.xml.transform.sax.SAXSource.setXMLReader(org.xml.sax.XMLReader)
.
The JAXB provider will detect and use your SAX parser.
- unmarshal in interface Unmarshaller
pSource
- The Source
being read.
- The JAXB object read from the DOM node.
unmarshal
protected abstract java.lang.Object unmarshal(XMLReader pReader,
InputSource pSource)
throws JAXBException
Unmarshals an object by using the given instance
of
org.xml.sax.XMLReader
to parse the XML
document read from the byte or character stream
given by the
org.xml.sax.InputSource
pSource
.
The implementation should call the method
org.xml.sax.XMLReader.setErrorHandler(org.xml.sax.ErrorHandler)
in order to pass errors provided by the SAX parser to the
ValidationEventHandler
provided by
the client.
JAXBException
- An error occurred while unmarshalling
the JAXB object.
unmarshal
public final java.lang.Object unmarshal(java.io.File pFile)
throws JAXBException
This method takes opens the given file pFile
for input. The Unmarshaller reads the byte stream contained in
the file and converts it into an equivalent JAXB object.
- unmarshal in interface Unmarshaller
pFile
- The file being read.
- The JAXB object read from the file.
JAXBException
- An unexpected problem (for example an
IOException) occurred.
unmarshal
public final java.lang.Object unmarshal(java.net.URL pURL)
throws JAXBException
This method takes connects to the given pURL
and opens a byte stream for input. The Unmarshaller reads the
byte stream and converts it into an equivalent JAXB object.
- unmarshal in interface Unmarshaller
pURL
- The URL being read.
- The JAXB object read from the URL.
JAXBException
- An unexpected problem (for example an
IOException) occurred.