/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Partial default <tt>Unmarshaller</tt> implementation.
*
* <p>
* This class provides a partial default implementation for the
* {@link javax.xml.bind.Unmarshaller}interface.
*
* <p>
* A JAXB Provider has to implement five methods (getUnmarshallerHandler,
* unmarshal(Node), unmarshal(XMLReader,InputSource),
* unmarshal(XMLStreamReader), and unmarshal(XMLEventReader).
*
* @author <ul>
* <li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li>
* </ul>
* @see javax.xml.bind.Unmarshaller
* @since JAXB1.0
*/
{
/** handler that will be used to process errors and warnings during unmarshal */
/** whether or not the unmarshaller will validate */
protected boolean validating = false;
/**
* XMLReader that will be used to parse a document.
*/
/**
* 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.
*/
try {
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);
} catch( ParserConfigurationException e ) {
throw new JAXBException(e);
} catch( SAXException e ) {
throw new JAXBException(e);
}
}
return reader;
}
throw new IllegalArgumentException(
}
if(source instanceof StreamSource)
// we don't handle other types of Source
throw new IllegalArgumentException();
}
// use the client specified XMLReader contained in the SAXSource.
if( r == null )
r = getXMLReader();
}
/**
* 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.
*/
throw new IllegalArgumentException(
}
}
}
throw new IllegalArgumentException(
}
}
if( f == null ) {
throw new IllegalArgumentException(
}
try {
// copied from JAXP
} catch( MalformedURLException e ) {
throw new IllegalArgumentException(e.getMessage());
}
}
throws JAXBException {
throw new IllegalArgumentException(
}
}
throw new IllegalArgumentException(
}
}
return is;
}
/**
* Indicates whether or not the Unmarshaller is configured to validate
* during unmarshal operations.
* <p>
* <i><b>Note:</b> I named this method isValidating() to stay in-line
* with JAXP, as opposed to naming it getValidating(). </i>
*
* @return true if the Unmarshaller is configured to validate during
* unmarshal operations, false otherwise
* @throws JAXBException if an error occurs while retrieving the validating
* flag
*/
return validating;
}
/**
* Allow an application to register a validation event handler.
* <p>
* The validation event handler will be called by the JAXB Provider if any
* validation errors are encountered during calls to any of the
* <tt>unmarshal</tt> 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.
*
* @param handler the validation event handler
* @throws JAXBException if an error was encountered while setting the
* event handler
*/
throws JAXBException {
} else {
}
}
/**
* Specifies whether or not the Unmarshaller should validate during
* unmarshal operations. By default, the <tt>Unmarshaller</tt> does
* not validate.
* <p>
* This method may only be invoked before or after calling one of the
* unmarshal methods.
*
* @param validating true if the Unmarshaller should validate during
* unmarshal, false otherwise
* @throws JAXBException if an error occurred while enabling or disabling
* validation at unmarshal time
*/
this.validating = validating;
}
/**
* Return the current event handler or the default event handler if one
* hasn't been set.
*
* @return the current ValidationEventHandler or the default event handler
* if it hasn't been set
* @throws JAXBException if an error was encountered while getting the
* current event handler
*/
return eventHandler;
}
/**
* Creates an UnmarshalException from a SAXException.
*
* This is an utility method provided for the derived classes.
*
* <p>
* 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.
*
* <p>
* This method checks the nested exception of SAXException
* and reduce those excessive wrapping.
*
* @return the resulting UnmarshalException
*/
// check the nested exception to see if it's an UnmarshalException
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
return new UnmarshalException(nested);
else
return new UnmarshalException(e);
}
/**
* 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.
*/
throws PropertyException {
throw new IllegalArgumentException(
}
}
/**
* 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.
*/
throws PropertyException {
throw new IllegalArgumentException(
}
throw new PropertyException(name);
}
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException {
throw new UnsupportedOperationException();
}
public <T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> expectedType) throws JAXBException {
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
throw new IllegalArgumentException();
}
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
}