/*
* 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.
*/
/**
* Default Unmarshaller implementation.
*
* <p>
* This class can be extended by the generated code to provide
* type-safe unmarshall methods.
*
* @author
* <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
*/
public final class UnmarshallerImpl extends AbstractUnmarshallerImpl implements ValidationEventHandler, Closeable
{
/** Owning {@link JAXBContext} */
/**
* schema which will be used to validate during calls to unmarshal
*/
/** Unmarshaller.Listener */
/**
* The attachment unmarshaller used to support MTOM and swaRef.
*/
try {
setEventHandler(this);
} catch (JAXBException e) {
throw new AssertionError(e); // impossible
}
}
return getUnmarshallerHandler(true,null);
}
if(intern)
h = new InterningXmlVisitor(h);
return new SAXConnector(h,null);
}
/**
* Creates and configures a new unmarshalling pipe line.
* Depending on the setting, we put a validator as a filter.
*
* @return
* A component that implements both {@link UnmarshallerHandler}
* and {@link ValidationEventHandler}. All the parsing errors
* should be reported to this error handler for the unmarshalling
* process to work correctly.
*
* Also, returned handler expects all the XML names to be interned.
*
*/
public final XmlVisitor createUnmarshallerHandler(InfosetScanner scanner, boolean inplace, JaxBeanInfo expectedType ) {
// delegate to JAXP 1.3 for validation if the client provided a schema
return unmarshaller;
}
// attempt to set it to true, which could fail
try {
} catch (SAXException e) {
// if it fails that's fine. we'll work around on our side
}
try {
return false; // no need for intern
} catch (SAXException e) {
}
// otherwise we need intern
return true;
}
}
protected <T> JAXBElement<T> unmarshal( XMLReader reader, InputSource source, Class<T> expectedType ) throws JAXBException {
if(expectedType==null)
throw new IllegalArgumentException();
}
private Object unmarshal0( XMLReader reader, InputSource source, JaxBeanInfo expectedType ) throws JAXBException {
// saxErrorHandler will be set by the getUnmarshallerHandler method.
// configure XMLReader so that the error will be sent to it.
// This is essential for the UnmarshallerHandler to be able to abort
// unmarshalling when an error is found.
//
// Note that when this XMLReader is provided by the client code,
// it might be already configured to call a client error handler.
// This will clobber such handler, if any.
//
// Ryan noted that we might want to report errors to such a client
// error handler as well.
try {
} catch( IOException e ) {
throw new UnmarshalException(e);
} catch( SAXException e ) {
throw createUnmarshalException(e);
}
// avoid keeping unnecessary references too long to let the GC
// reclaim more memory.
// setting null upsets some parsers, so use a dummy instance instead.
return result;
}
reader = getXMLReader();
}
if(source instanceof StreamSource) {
}
// we don't handle other types of Source
throw new IllegalArgumentException();
}
reader = getXMLReader();
}
if(source instanceof StreamSource) {
}
// we don't handle other types of Source
throw new IllegalArgumentException();
}
try {
return super.getEventHandler();
} catch (JAXBException e) {
// impossible
throw new AssertionError();
}
}
/**
* Returns true if an event handler is installed.
* <p>
* The default handler ignores any errors, and for that this method returns false.
*/
public final boolean hasEventHandler() {
return getEventHandler()!=this;
}
if(expectedType==null)
throw new IllegalArgumentException();
}
}
// just to make the the test harness happy by making this method accessible
}
try {
InterningXmlVisitor handler = new InterningXmlVisitor(createUnmarshallerHandler(null,false,expectedType));
else
else
// no other type of input is supported
return retVal;
} catch( SAXException e ) {
throw createUnmarshalException(e);
}
}
}
public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException {
if(expectedType==null)
throw new IllegalArgumentException();
}
throw new IllegalArgumentException(
}
// TODO: convert eventType into event name
throw new IllegalStateException(
}
try {
} catch (XMLStreamException e) {
throw handleStreamException(e);
}
h.getContext().clearResult();
return retVal;
}
public <T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> expectedType) throws JAXBException {
if(expectedType==null)
throw new IllegalArgumentException();
}
}
throw new IllegalArgumentException(
}
try {
// TODO: convert event into event name
throw new IllegalStateException(
}
// Quick hack until SJSXP fixes 6270116
if(!isZephyr)
h = new InterningXmlVisitor(h);
return h.getContext().getResult();
} catch (XMLStreamException e) {
throw handleStreamException(e);
}
}
}
// StAXStreamConnector wraps SAXException to XMLStreamException.
// XMLStreamException doesn't print its nested stack trace when it prints
// its stack trace, so if we wrap XMLStreamException in JAXBException,
// it becomes harder to find out the real problem.
// So we unwrap them here. But we don't want to unwrap too eagerly, because
// that could throw away some meaningful exception information.
if(ne instanceof JAXBException)
return (JAXBException)ne;
if(ne instanceof SAXException)
return new UnmarshalException(ne);
return new UnmarshalException(e);
}
return idResolver;
}
return super.getProperty(name);
}
return;
}
return;
}
return;
}
return;
}
}
}
return schema;
}
return attachmentUnmarshaller;
}
this.attachmentUnmarshaller = au;
}
/**
* @deprecated since 2.0
*/
public boolean isValidating() {
throw new UnsupportedOperationException();
}
/**
* @deprecated since 2.0
*/
throw new UnsupportedOperationException();
}
throw new IllegalArgumentException();
}
throw new IllegalArgumentException();
// so as not to create a new instance when this method is called
else
return null;
}
// opening up for public use
return super.createUnmarshalException(e);
}
/**
* Default error handling behavior for {@link Unmarshaller}.
*/
}
return is;
}
}
return externalListener;
}
}
return coordinator;
}
@SuppressWarnings("FinalizeDeclaration")
try {
} finally {
super.finalize();
}
}
/**
* Must be called from same thread which created the UnmarshallerImpl instance.
* @throws IOException
*/
}
}