Method from javax.xml.bind.helpers.AbstractUnmarshallerImpl Detail: |
protected UnmarshalException createUnmarshalException(SAXException e) {
// check the nested exception to see if it's an UnmarshalException
Exception nested = e.getException();
if(nested instanceof UnmarshalException)
return (UnmarshalException)nested;
if(nested instanceof RuntimeException)
// typically this is an unexpected exception,
// just throw it rather than wrap it, so that the full stack
// trace can be displayed.
throw (RuntimeException)nested;
// otherwise simply wrap it
if(nested!=null)
return new UnmarshalException(nested);
else
return new UnmarshalException(e);
}
Creates an UnmarshalException from a SAXException.
This is an utility method provided for the derived classes.
When a provider-implemented ContentHandler wants to throw a
JAXBException, it needs to wrap the exception by a SAXException.
If the unmarshaller implementation blindly wrap SAXException
by JAXBException, such an exception will be a JAXBException
wrapped by a SAXException wrapped by another JAXBException.
This is silly.
This method checks the nested exception of SAXException
and reduce those excessive wrapping. |
public A getAdapter(Class<A> type) {
throw new UnsupportedOperationException();
}
|
public AttachmentUnmarshaller getAttachmentUnmarshaller() {
throw new UnsupportedOperationException();
}
|
public ValidationEventHandler getEventHandler() throws JAXBException {
return eventHandler;
}
Return the current event handler or the default event handler if one
hasn't been set. |
public Listener getListener() {
throw new UnsupportedOperationException();
}
|
public Object getProperty(String name) throws PropertyException {
if( name == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) );
}
throw new PropertyException(name);
}
Default implementation of the getProperty method always
throws PropertyException since there are no required
properties. If a provider needs to handle additional
properties, it should override this method in a derived class. |
public Schema getSchema() {
throw new UnsupportedOperationException();
}
|
protected XMLReader getXMLReader() throws JAXBException {
if(reader==null) {
try {
SAXParserFactory parserFactory;
parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
// there is no point in asking a validation because
// there is no guarantee that the document will come with
// a proper schemaLocation.
parserFactory.setValidating(false);
reader = parserFactory.newSAXParser().getXMLReader();
} catch( ParserConfigurationException e ) {
throw new JAXBException(e);
} catch( SAXException e ) {
throw new JAXBException(e);
}
}
return reader;
}
Obtains a configured XMLReader.
This method is used when the client-specified
SAXSource object doesn't have XMLReader.
Unmarshaller is not re-entrant, so we will
only use one instance of XMLReader. |
public boolean isValidating() throws JAXBException {
return validating;
}
Indicates whether or not the Unmarshaller is configured to validate
during unmarshal operations.
Note: I named this method isValidating() to stay in-line
with JAXP, as opposed to naming it getValidating(). |
public void setAdapter(XmlAdapter adapter) {
if(adapter==null)
throw new IllegalArgumentException();
setAdapter((Class)adapter.getClass(),adapter);
}
|
public void setAdapter(Class<A> type,
A adapter) {
throw new UnsupportedOperationException();
}
|
public void setAttachmentUnmarshaller(AttachmentUnmarshaller au) {
throw new UnsupportedOperationException();
}
|
public void setEventHandler(ValidationEventHandler handler) throws JAXBException {
if( handler == null ) {
eventHandler = new DefaultValidationEventHandler();
} else {
eventHandler = handler;
}
}
Allow an application to register a validation event handler.
The validation event handler will be called by the JAXB Provider if any
validation errors are encountered during calls to any of the
unmarshal methods. If the client application does not register
a validation event handler before invoking the unmarshal methods, then
all validation events will be silently ignored and may result in
unexpected behaviour. |
public void setListener(Listener listener) {
throw new UnsupportedOperationException();
}
|
public void setProperty(String name,
Object value) throws PropertyException {
if( name == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) );
}
throw new PropertyException(name, value);
}
Default implementation of the setProperty method always
throws PropertyException since there are no required
properties. If a provider needs to handle additional
properties, it should override this method in a derived class. |
public void setSchema(Schema schema) {
throw new UnsupportedOperationException();
}
|
public void setValidating(boolean validating) throws JAXBException {
this.validating = validating;
}
|
public Object unmarshal(Source source) throws JAXBException {
if( source == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "source" ) );
}
if(source instanceof SAXSource)
return unmarshal( (SAXSource)source );
if(source instanceof StreamSource)
return unmarshal( streamSourceToInputSource((StreamSource)source));
if(source instanceof DOMSource)
return unmarshal( ((DOMSource)source).getNode() );
// we don't handle other types of Source
throw new IllegalArgumentException();
}
|
public final Object unmarshal(InputSource source) throws JAXBException {
if( source == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "source" ) );
}
return unmarshal( getXMLReader(), source );
}
|
public final Object unmarshal(URL url) throws JAXBException {
if( url == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "url" ) );
}
return unmarshal( url.toExternalForm() );
}
|
public final Object unmarshal(File f) throws JAXBException {
if( f == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "file" ) );
}
try {
// copied from JAXP
String path = f.getAbsolutePath();
if (File.separatorChar != '/')
path = path.replace(File.separatorChar, '/');
if (!path.startsWith("/"))
path = "/" + path;
if (!path.endsWith("/") && f.isDirectory())
path = path + "/";
return unmarshal(new URL("file", "", path));
} catch( MalformedURLException e ) {
throw new IllegalArgumentException(e.getMessage());
}
}
|
public final Object unmarshal(InputStream is) throws JAXBException {
if( is == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "is" ) );
}
InputSource isrc = new InputSource( is );
return unmarshal( isrc );
}
|
public final Object unmarshal(Reader reader) throws JAXBException {
if( reader == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "reader" ) );
}
InputSource isrc = new InputSource( reader );
return unmarshal( isrc );
}
|
public Object unmarshal(XMLEventReader reader) throws JAXBException {
throw new UnsupportedOperationException();
}
|
public Object unmarshal(XMLStreamReader reader) throws JAXBException {
throw new UnsupportedOperationException();
}
|
abstract protected Object unmarshal(XMLReader reader,
InputSource source) throws JAXBException
Unmarshals an object by using the specified XMLReader and the InputSource.
The callee should call the setErrorHandler method of the XMLReader
so that errors are passed to the client-specified ValidationEventHandler. |
public JAXBElement<T> unmarshal(Node node,
Class<T> expectedType) throws JAXBException {
throw new UnsupportedOperationException();
}
|
public JAXBElement<T> unmarshal(Source source,
Class<T> expectedType) throws JAXBException {
throw new UnsupportedOperationException();
}
|
public JAXBElement<T> unmarshal(XMLStreamReader reader,
Class<T> expectedType) throws JAXBException {
throw new UnsupportedOperationException();
}
|
public JAXBElement<T> unmarshal(XMLEventReader reader,
Class<T> expectedType) throws JAXBException {
throw new UnsupportedOperationException();
}
|