Methods Summary |
---|
protected javax.xml.bind.UnmarshalException | createUnmarshalException(org.xml.sax.SAXException 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.
// 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);
|
public A | getAdapter(java.lang.Class type)
throw new UnsupportedOperationException();
|
public javax.xml.bind.attachment.AttachmentUnmarshaller | getAttachmentUnmarshaller()
throw new UnsupportedOperationException();
|
public javax.xml.bind.ValidationEventHandler | getEventHandler()Return the current event handler or the default event handler if one
hasn't been set.
return eventHandler;
|
public Listener | getListener()
throw new UnsupportedOperationException();
|
public java.lang.Object | getProperty(java.lang.String 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.
if( name == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) );
}
throw new PropertyException(name);
|
public javax.xml.validation.Schema | getSchema()
throw new UnsupportedOperationException();
|
protected org.xml.sax.XMLReader | getXMLReader()Obtains a configured XMLReader.
This method is used when the client-specified
{@link SAXSource} object doesn't have XMLReader.
{@link Unmarshaller} is not re-entrant, so we will
only use one instance of XMLReader.
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;
|
public boolean | isValidating()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().
return validating;
|
public void | setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter adapter)
if(adapter==null)
throw new IllegalArgumentException();
setAdapter((Class)adapter.getClass(),adapter);
|
public void | setAdapter(java.lang.Class type, A adapter)
throw new UnsupportedOperationException();
|
public void | setAttachmentUnmarshaller(javax.xml.bind.attachment.AttachmentUnmarshaller au)
throw new UnsupportedOperationException();
|
public void | setEventHandler(javax.xml.bind.ValidationEventHandler 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.
if( handler == null ) {
eventHandler = new DefaultValidationEventHandler();
} else {
eventHandler = handler;
}
|
public void | setListener(Listener listener)
throw new UnsupportedOperationException();
|
public void | setProperty(java.lang.String name, java.lang.Object 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.
if( name == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) );
}
throw new PropertyException(name, value);
|
public void | setSchema(javax.xml.validation.Schema schema)
throw new UnsupportedOperationException();
|
public void | setValidating(boolean validating)Specifies whether or not the Unmarshaller should validate during
unmarshal operations. By default, the Unmarshaller does
not validate.
This method may only be invoked before or after calling one of the
unmarshal methods.
this.validating = validating;
|
private static org.xml.sax.InputSource | streamSourceToInputSource(javax.xml.transform.stream.StreamSource ss)
InputSource is = new InputSource();
is.setSystemId( ss.getSystemId() );
is.setByteStream( ss.getInputStream() );
is.setCharacterStream( ss.getReader() );
return is;
|
public final java.lang.Object | unmarshal(java.io.Reader reader)
if( reader == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "reader" ) );
}
InputSource isrc = new InputSource( reader );
return unmarshal( isrc );
|
public java.lang.Object | unmarshal(javax.xml.stream.XMLEventReader reader)
throw new UnsupportedOperationException();
|
public java.lang.Object | unmarshal(javax.xml.transform.Source source)
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 java.lang.Object | unmarshal(javax.xml.stream.XMLStreamReader reader)
throw new UnsupportedOperationException();
|
public javax.xml.bind.JAXBElement | unmarshal(org.w3c.dom.Node node, java.lang.Class expectedType)
throw new UnsupportedOperationException();
|
public javax.xml.bind.JAXBElement | unmarshal(javax.xml.transform.Source source, java.lang.Class expectedType)
throw new UnsupportedOperationException();
|
public javax.xml.bind.JAXBElement | unmarshal(javax.xml.stream.XMLStreamReader reader, java.lang.Class expectedType)
throw new UnsupportedOperationException();
|
public javax.xml.bind.JAXBElement | unmarshal(javax.xml.stream.XMLEventReader reader, java.lang.Class expectedType)
throw new UnsupportedOperationException();
|
private java.lang.Object | unmarshal(javax.xml.transform.sax.SAXSource source)
XMLReader reader = source.getXMLReader();
if( reader == null )
reader = getXMLReader();
return unmarshal( reader, source.getInputSource() );
|
protected abstract java.lang.Object | unmarshal(org.xml.sax.XMLReader reader, org.xml.sax.InputSource source)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 final java.lang.Object | unmarshal(org.xml.sax.InputSource source)
if( source == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "source" ) );
}
return unmarshal( getXMLReader(), source );
|
private java.lang.Object | unmarshal(java.lang.String url)
return unmarshal( new InputSource(url) );
|
public final java.lang.Object | unmarshal(java.net.URL url)
if( url == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "url" ) );
}
return unmarshal( url.toExternalForm() );
|
public final java.lang.Object | unmarshal(java.io.File f)
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 java.lang.Object | unmarshal(java.io.InputStream is)
if( is == null ) {
throw new IllegalArgumentException(
Messages.format( Messages.MUST_NOT_BE_NULL, "is" ) );
}
InputSource isrc = new InputSource( is );
return unmarshal( isrc );
|