1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/unmarshaller/UnmarshallerImpl.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,619 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.bind.v2.runtime.unmarshaller; 1.30 + 1.31 +import java.io.IOException; 1.32 +import java.io.InputStream; 1.33 + 1.34 +import javax.xml.bind.JAXBContext; 1.35 +import javax.xml.bind.JAXBElement; 1.36 +import javax.xml.bind.JAXBException; 1.37 +import javax.xml.bind.PropertyException; 1.38 +import javax.xml.bind.UnmarshalException; 1.39 +import javax.xml.bind.Unmarshaller; 1.40 +import javax.xml.bind.UnmarshallerHandler; 1.41 +import javax.xml.bind.ValidationEvent; 1.42 +import javax.xml.bind.ValidationEventHandler; 1.43 +import javax.xml.bind.annotation.adapters.XmlAdapter; 1.44 +import javax.xml.bind.attachment.AttachmentUnmarshaller; 1.45 +import javax.xml.bind.helpers.AbstractUnmarshallerImpl; 1.46 +import javax.xml.stream.XMLEventReader; 1.47 +import javax.xml.stream.XMLStreamConstants; 1.48 +import javax.xml.stream.XMLStreamException; 1.49 +import javax.xml.stream.XMLStreamReader; 1.50 +import javax.xml.stream.events.XMLEvent; 1.51 +import javax.xml.transform.Source; 1.52 +import javax.xml.transform.dom.DOMSource; 1.53 +import javax.xml.transform.sax.SAXSource; 1.54 +import javax.xml.transform.stream.StreamSource; 1.55 +import javax.xml.validation.Schema; 1.56 + 1.57 +import com.sun.xml.internal.bind.IDResolver; 1.58 +import com.sun.xml.internal.bind.api.ClassResolver; 1.59 +import com.sun.xml.internal.bind.unmarshaller.DOMScanner; 1.60 +import com.sun.xml.internal.bind.unmarshaller.InfosetScanner; 1.61 +import com.sun.xml.internal.bind.unmarshaller.Messages; 1.62 +import com.sun.xml.internal.bind.v2.ClassFactory; 1.63 +import com.sun.xml.internal.bind.v2.runtime.AssociationMap; 1.64 +import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl; 1.65 +import com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo; 1.66 +import com.sun.xml.internal.bind.v2.util.XmlFactory; 1.67 + 1.68 +import java.io.Closeable; 1.69 +import javax.xml.parsers.ParserConfigurationException; 1.70 +import javax.xml.parsers.SAXParserFactory; 1.71 +import org.w3c.dom.Document; 1.72 +import org.w3c.dom.Element; 1.73 +import org.w3c.dom.Node; 1.74 +import org.xml.sax.InputSource; 1.75 +import org.xml.sax.SAXException; 1.76 +import org.xml.sax.XMLReader; 1.77 +import org.xml.sax.helpers.DefaultHandler; 1.78 + 1.79 +/** 1.80 + * Default Unmarshaller implementation. 1.81 + * 1.82 + * <p> 1.83 + * This class can be extended by the generated code to provide 1.84 + * type-safe unmarshall methods. 1.85 + * 1.86 + * @author 1.87 + * <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a> 1.88 + */ 1.89 + public final class UnmarshallerImpl extends AbstractUnmarshallerImpl implements ValidationEventHandler, Closeable 1.90 +{ 1.91 + /** Owning {@link JAXBContext} */ 1.92 + protected final JAXBContextImpl context; 1.93 + 1.94 + /** 1.95 + * schema which will be used to validate during calls to unmarshal 1.96 + */ 1.97 + private Schema schema; 1.98 + 1.99 + public final UnmarshallingContext coordinator; 1.100 + 1.101 + /** Unmarshaller.Listener */ 1.102 + private Listener externalListener; 1.103 + 1.104 + /** 1.105 + * The attachment unmarshaller used to support MTOM and swaRef. 1.106 + */ 1.107 + private AttachmentUnmarshaller attachmentUnmarshaller; 1.108 + private IDResolver idResolver = new DefaultIDResolver(); 1.109 + 1.110 + public UnmarshallerImpl( JAXBContextImpl context, AssociationMap assoc ) { 1.111 + this.context = context; 1.112 + this.coordinator = new UnmarshallingContext( this, assoc ); 1.113 + 1.114 + try { 1.115 + setEventHandler(this); 1.116 + } catch (JAXBException e) { 1.117 + throw new AssertionError(e); // impossible 1.118 + } 1.119 + } 1.120 + 1.121 + public UnmarshallerHandler getUnmarshallerHandler() { 1.122 + return getUnmarshallerHandler(true,null); 1.123 + } 1.124 + 1.125 + private XMLReader reader = null; 1.126 + 1.127 + /** 1.128 + * Obtains a configured XMLReader. 1.129 + * 1.130 + * This method is used when the client-specified 1.131 + * {@link SAXSource} object doesn't have XMLReader. 1.132 + * 1.133 + * {@link Unmarshaller} is not re-entrant, so we will 1.134 + * only use one instance of XMLReader. 1.135 + * 1.136 + * Overriden in order to fix potential security issue. 1.137 + */ 1.138 + @Override 1.139 + protected XMLReader getXMLReader() throws JAXBException { 1.140 + if (reader == null) { 1.141 + try { 1.142 + SAXParserFactory parserFactory = XmlFactory.createParserFactory(context.disableSecurityProcessing); 1.143 + // there is no point in asking a validation because 1.144 + // there is no guarantee that the document will come with 1.145 + // a proper schemaLocation. 1.146 + parserFactory.setValidating(false); 1.147 + reader = parserFactory.newSAXParser().getXMLReader(); 1.148 + } catch (ParserConfigurationException e) { 1.149 + throw new JAXBException(e); 1.150 + } catch (SAXException e) { 1.151 + throw new JAXBException(e); 1.152 + } 1.153 + } 1.154 + return reader; 1.155 + } 1.156 + 1.157 + private SAXConnector getUnmarshallerHandler( boolean intern, JaxBeanInfo expectedType ) { 1.158 + XmlVisitor h = createUnmarshallerHandler(null, false, expectedType); 1.159 + if (intern) { 1.160 + h = new InterningXmlVisitor(h); 1.161 + } 1.162 + return new SAXConnector(h,null); 1.163 + } 1.164 + 1.165 + /** 1.166 + * Creates and configures a new unmarshalling pipe line. 1.167 + * Depending on the setting, we put a validator as a filter. 1.168 + * 1.169 + * @return 1.170 + * A component that implements both {@link UnmarshallerHandler} 1.171 + * and {@link ValidationEventHandler}. All the parsing errors 1.172 + * should be reported to this error handler for the unmarshalling 1.173 + * process to work correctly. 1.174 + * 1.175 + * Also, returned handler expects all the XML names to be interned. 1.176 + * 1.177 + */ 1.178 + public final XmlVisitor createUnmarshallerHandler(InfosetScanner scanner, boolean inplace, JaxBeanInfo expectedType ) { 1.179 + 1.180 + coordinator.reset(scanner,inplace,expectedType,idResolver); 1.181 + XmlVisitor unmarshaller = coordinator; 1.182 + 1.183 + // delegate to JAXP 1.3 for validation if the client provided a schema 1.184 + if (schema != null) { 1.185 + unmarshaller = new ValidatingUnmarshaller(schema,unmarshaller); 1.186 + } 1.187 + 1.188 + if(attachmentUnmarshaller!=null && attachmentUnmarshaller.isXOPPackage()) { 1.189 + unmarshaller = new MTOMDecorator(this,unmarshaller,attachmentUnmarshaller); 1.190 + } 1.191 + 1.192 + return unmarshaller; 1.193 + } 1.194 + 1.195 + private static final DefaultHandler dummyHandler = new DefaultHandler(); 1.196 + 1.197 + public static boolean needsInterning( XMLReader reader ) { 1.198 + // attempt to set it to true, which could fail 1.199 + try { 1.200 + reader.setFeature("http://xml.org/sax/features/string-interning",true); 1.201 + } catch (SAXException e) { 1.202 + // if it fails that's fine. we'll work around on our side 1.203 + } 1.204 + 1.205 + try { 1.206 + if (reader.getFeature("http://xml.org/sax/features/string-interning")) { 1.207 + return false; // no need for intern 1.208 + } 1.209 + } catch (SAXException e) { 1.210 + // unrecognized/unsupported 1.211 + } 1.212 + // otherwise we need intern 1.213 + return true; 1.214 + } 1.215 + 1.216 + protected Object unmarshal( XMLReader reader, InputSource source ) throws JAXBException { 1.217 + return unmarshal0(reader,source,null); 1.218 + } 1.219 + 1.220 + protected <T> JAXBElement<T> unmarshal( XMLReader reader, InputSource source, Class<T> expectedType ) throws JAXBException { 1.221 + if(expectedType==null) { 1.222 + throw new IllegalArgumentException(); 1.223 + } 1.224 + return (JAXBElement)unmarshal0(reader,source,getBeanInfo(expectedType)); 1.225 + } 1.226 + 1.227 + private Object unmarshal0( XMLReader reader, InputSource source, JaxBeanInfo expectedType ) throws JAXBException { 1.228 + 1.229 + SAXConnector connector = getUnmarshallerHandler(needsInterning(reader),expectedType); 1.230 + 1.231 + reader.setContentHandler(connector); 1.232 + // saxErrorHandler will be set by the getUnmarshallerHandler method. 1.233 + // configure XMLReader so that the error will be sent to it. 1.234 + // This is essential for the UnmarshallerHandler to be able to abort 1.235 + // unmarshalling when an error is found. 1.236 + // 1.237 + // Note that when this XMLReader is provided by the client code, 1.238 + // it might be already configured to call a client error handler. 1.239 + // This will clobber such handler, if any. 1.240 + // 1.241 + // Ryan noted that we might want to report errors to such a client 1.242 + // error handler as well. 1.243 + reader.setErrorHandler(coordinator); 1.244 + 1.245 + try { 1.246 + reader.parse(source); 1.247 + } catch( IOException e ) { 1.248 + coordinator.clearStates(); 1.249 + throw new UnmarshalException(e); 1.250 + } catch( SAXException e ) { 1.251 + coordinator.clearStates(); 1.252 + throw createUnmarshalException(e); 1.253 + } 1.254 + 1.255 + Object result = connector.getResult(); 1.256 + 1.257 + // avoid keeping unnecessary references too long to let the GC 1.258 + // reclaim more memory. 1.259 + // setting null upsets some parsers, so use a dummy instance instead. 1.260 + reader.setContentHandler(dummyHandler); 1.261 + reader.setErrorHandler(dummyHandler); 1.262 + 1.263 + return result; 1.264 + } 1.265 + 1.266 + @Override 1.267 + public <T> JAXBElement<T> unmarshal( Source source, Class<T> expectedType ) throws JAXBException { 1.268 + if (source instanceof SAXSource) { 1.269 + SAXSource ss = (SAXSource) source; 1.270 + 1.271 + XMLReader locReader = ss.getXMLReader(); 1.272 + if (locReader == null) { 1.273 + locReader = getXMLReader(); 1.274 + } 1.275 + 1.276 + return unmarshal(locReader, ss.getInputSource(), expectedType); 1.277 + } 1.278 + if (source instanceof StreamSource) { 1.279 + return unmarshal(getXMLReader(), streamSourceToInputSource((StreamSource) source), expectedType); 1.280 + } 1.281 + if (source instanceof DOMSource) { 1.282 + return unmarshal(((DOMSource) source).getNode(), expectedType); 1.283 + } 1.284 + 1.285 + // we don't handle other types of Source 1.286 + throw new IllegalArgumentException(); 1.287 + } 1.288 + 1.289 + public Object unmarshal0( Source source, JaxBeanInfo expectedType ) throws JAXBException { 1.290 + if (source instanceof SAXSource) { 1.291 + SAXSource ss = (SAXSource) source; 1.292 + 1.293 + XMLReader locReader = ss.getXMLReader(); 1.294 + if (locReader == null) { 1.295 + locReader = getXMLReader(); 1.296 + } 1.297 + 1.298 + return unmarshal0(locReader, ss.getInputSource(), expectedType); 1.299 + } 1.300 + if (source instanceof StreamSource) { 1.301 + return unmarshal0(getXMLReader(), streamSourceToInputSource((StreamSource) source), expectedType); 1.302 + } 1.303 + if (source instanceof DOMSource) { 1.304 + return unmarshal0(((DOMSource) source).getNode(), expectedType); 1.305 + } 1.306 + 1.307 + // we don't handle other types of Source 1.308 + throw new IllegalArgumentException(); 1.309 + } 1.310 + 1.311 + 1.312 + @Override 1.313 + public final ValidationEventHandler getEventHandler() { 1.314 + try { 1.315 + return super.getEventHandler(); 1.316 + } catch (JAXBException e) { 1.317 + // impossible 1.318 + throw new AssertionError(); 1.319 + } 1.320 + } 1.321 + 1.322 + /** 1.323 + * Returns true if an event handler is installed. 1.324 + * <p> 1.325 + * The default handler ignores any errors, and for that this method returns false. 1.326 + */ 1.327 + public final boolean hasEventHandler() { 1.328 + return getEventHandler()!=this; 1.329 + } 1.330 + 1.331 + @Override 1.332 + public <T> JAXBElement<T> unmarshal(Node node, Class<T> expectedType) throws JAXBException { 1.333 + if (expectedType == null) { 1.334 + throw new IllegalArgumentException(); 1.335 + } 1.336 + return (JAXBElement)unmarshal0(node,getBeanInfo(expectedType)); 1.337 + } 1.338 + 1.339 + public final Object unmarshal( Node node ) throws JAXBException { 1.340 + return unmarshal0(node,null); 1.341 + } 1.342 + 1.343 + // just to make the the test harness happy by making this method accessible 1.344 + @Deprecated 1.345 + public final Object unmarshal( SAXSource source ) throws JAXBException { 1.346 + return super.unmarshal(source); 1.347 + } 1.348 + 1.349 + public final Object unmarshal0( Node node, JaxBeanInfo expectedType ) throws JAXBException { 1.350 + try { 1.351 + final DOMScanner scanner = new DOMScanner(); 1.352 + 1.353 + InterningXmlVisitor handler = new InterningXmlVisitor(createUnmarshallerHandler(null,false,expectedType)); 1.354 + scanner.setContentHandler(new SAXConnector(handler,scanner)); 1.355 + 1.356 + if(node.getNodeType() == Node.ELEMENT_NODE) { 1.357 + scanner.scan((Element)node); 1.358 + } else if(node.getNodeType() == Node.DOCUMENT_NODE) { 1.359 + scanner.scan((Document)node); 1.360 + } else { 1.361 + throw new IllegalArgumentException("Unexpected node type: "+node); 1.362 + } 1.363 + 1.364 + Object retVal = handler.getContext().getResult(); 1.365 + handler.getContext().clearResult(); 1.366 + return retVal; 1.367 + } catch( SAXException e ) { 1.368 + throw createUnmarshalException(e); 1.369 + } 1.370 + } 1.371 + 1.372 + @Override 1.373 + public Object unmarshal(XMLStreamReader reader) throws JAXBException { 1.374 + return unmarshal0(reader,null); 1.375 + } 1.376 + 1.377 + @Override 1.378 + public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException { 1.379 + if (expectedType==null) { 1.380 + throw new IllegalArgumentException(); 1.381 + } 1.382 + return (JAXBElement)unmarshal0(reader,getBeanInfo(expectedType)); 1.383 + } 1.384 + 1.385 + public Object unmarshal0(XMLStreamReader reader, JaxBeanInfo expectedType) throws JAXBException { 1.386 + if (reader == null) { 1.387 + throw new IllegalArgumentException( 1.388 + Messages.format(Messages.NULL_READER)); 1.389 + } 1.390 + 1.391 + int eventType = reader.getEventType(); 1.392 + if (eventType != XMLStreamConstants.START_ELEMENT 1.393 + && eventType != XMLStreamConstants.START_DOCUMENT) { 1.394 + // TODO: convert eventType into event name 1.395 + throw new IllegalStateException( 1.396 + Messages.format(Messages.ILLEGAL_READER_STATE,eventType)); 1.397 + } 1.398 + 1.399 + XmlVisitor h = createUnmarshallerHandler(null,false,expectedType); 1.400 + StAXConnector connector=StAXStreamConnector.create(reader,h); 1.401 + 1.402 + try { 1.403 + connector.bridge(); 1.404 + } catch (XMLStreamException e) { 1.405 + throw handleStreamException(e); 1.406 + } 1.407 + 1.408 + Object retVal = h.getContext().getResult(); 1.409 + h.getContext().clearResult(); 1.410 + return retVal; 1.411 + } 1.412 + 1.413 + @Override 1.414 + public <T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> expectedType) throws JAXBException { 1.415 + if(expectedType==null) { 1.416 + throw new IllegalArgumentException(); 1.417 + } 1.418 + return (JAXBElement)unmarshal0(reader,getBeanInfo(expectedType)); 1.419 + } 1.420 + 1.421 + @Override 1.422 + public Object unmarshal(XMLEventReader reader) throws JAXBException { 1.423 + return unmarshal0(reader,null); 1.424 + } 1.425 + 1.426 + private Object unmarshal0(XMLEventReader reader,JaxBeanInfo expectedType) throws JAXBException { 1.427 + if (reader == null) { 1.428 + throw new IllegalArgumentException( 1.429 + Messages.format(Messages.NULL_READER)); 1.430 + } 1.431 + 1.432 + try { 1.433 + XMLEvent event = reader.peek(); 1.434 + 1.435 + if (!event.isStartElement() && !event.isStartDocument()) { 1.436 + // TODO: convert event into event name 1.437 + throw new IllegalStateException( 1.438 + Messages.format( 1.439 + Messages.ILLEGAL_READER_STATE,event.getEventType())); 1.440 + } 1.441 + 1.442 + // Quick hack until SJSXP fixes 6270116 1.443 + boolean isZephyr = reader.getClass().getName().equals("com.sun.xml.internal.stream.XMLReaderImpl"); 1.444 + XmlVisitor h = createUnmarshallerHandler(null,false,expectedType); 1.445 + if(!isZephyr) { 1.446 + h = new InterningXmlVisitor(h); 1.447 + } 1.448 + new StAXEventConnector(reader,h).bridge(); 1.449 + return h.getContext().getResult(); 1.450 + } catch (XMLStreamException e) { 1.451 + throw handleStreamException(e); 1.452 + } 1.453 + } 1.454 + 1.455 + public Object unmarshal0( InputStream input, JaxBeanInfo expectedType ) throws JAXBException { 1.456 + return unmarshal0(getXMLReader(),new InputSource(input),expectedType); 1.457 + } 1.458 + 1.459 + private static JAXBException handleStreamException(XMLStreamException e) { 1.460 + // StAXStreamConnector wraps SAXException to XMLStreamException. 1.461 + // XMLStreamException doesn't print its nested stack trace when it prints 1.462 + // its stack trace, so if we wrap XMLStreamException in JAXBException, 1.463 + // it becomes harder to find out the real problem. 1.464 + // So we unwrap them here. But we don't want to unwrap too eagerly, because 1.465 + // that could throw away some meaningful exception information. 1.466 + Throwable ne = e.getNestedException(); 1.467 + if(ne instanceof JAXBException) { 1.468 + return (JAXBException)ne; 1.469 + } 1.470 + if(ne instanceof SAXException) { 1.471 + return new UnmarshalException(ne); 1.472 + } 1.473 + return new UnmarshalException(e); 1.474 + } 1.475 + 1.476 + @Override 1.477 + public Object getProperty(String name) throws PropertyException { 1.478 + if(name.equals(IDResolver.class.getName())) { 1.479 + return idResolver; 1.480 + } 1.481 + return super.getProperty(name); 1.482 + } 1.483 + 1.484 + @Override 1.485 + public void setProperty(String name, Object value) throws PropertyException { 1.486 + if(name.equals(FACTORY)) { 1.487 + coordinator.setFactories(value); 1.488 + return; 1.489 + } 1.490 + if(name.equals(IDResolver.class.getName())) { 1.491 + idResolver = (IDResolver)value; 1.492 + return; 1.493 + } 1.494 + if(name.equals(ClassResolver.class.getName())) { 1.495 + coordinator.classResolver = (ClassResolver)value; 1.496 + return; 1.497 + } 1.498 + if(name.equals(ClassLoader.class.getName())) { 1.499 + coordinator.classLoader = (ClassLoader)value; 1.500 + return; 1.501 + } 1.502 + super.setProperty(name, value); 1.503 + } 1.504 + 1.505 + public static final String FACTORY = "com.sun.xml.internal.bind.ObjectFactory"; 1.506 + 1.507 + @Override 1.508 + public void setSchema(Schema schema) { 1.509 + this.schema = schema; 1.510 + } 1.511 + 1.512 + @Override 1.513 + public Schema getSchema() { 1.514 + return schema; 1.515 + } 1.516 + 1.517 + @Override 1.518 + public AttachmentUnmarshaller getAttachmentUnmarshaller() { 1.519 + return attachmentUnmarshaller; 1.520 + } 1.521 + 1.522 + @Override 1.523 + public void setAttachmentUnmarshaller(AttachmentUnmarshaller au) { 1.524 + this.attachmentUnmarshaller = au; 1.525 + } 1.526 + 1.527 + /** 1.528 + * @deprecated since 2.0 1.529 + */ 1.530 + @Override 1.531 + public boolean isValidating() { 1.532 + throw new UnsupportedOperationException(); 1.533 + } 1.534 + 1.535 + /** 1.536 + * @deprecated since 2.0 1.537 + */ 1.538 + @Override 1.539 + public void setValidating(boolean validating) { 1.540 + throw new UnsupportedOperationException(); 1.541 + } 1.542 + 1.543 + @Override 1.544 + public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter) { 1.545 + if (type==null) { 1.546 + throw new IllegalArgumentException(); 1.547 + } 1.548 + coordinator.putAdapter(type,adapter); 1.549 + } 1.550 + 1.551 + @Override 1.552 + public <A extends XmlAdapter> A getAdapter(Class<A> type) { 1.553 + if(type==null) { 1.554 + throw new IllegalArgumentException(); 1.555 + } 1.556 + if(coordinator.containsAdapter(type)) { 1.557 + return coordinator.getAdapter(type); 1.558 + } else { 1.559 + return null; 1.560 + } 1.561 + } 1.562 + 1.563 + // opening up for public use 1.564 + @Override 1.565 + public UnmarshalException createUnmarshalException( SAXException e ) { 1.566 + return super.createUnmarshalException(e); 1.567 + } 1.568 + 1.569 + 1.570 + /** 1.571 + * Default error handling behavior for {@link Unmarshaller}. 1.572 + */ 1.573 + public boolean handleEvent(ValidationEvent event) { 1.574 + return event.getSeverity()!=ValidationEvent.FATAL_ERROR; 1.575 + } 1.576 + 1.577 + private static InputSource streamSourceToInputSource( StreamSource ss ) { 1.578 + InputSource is = new InputSource(); 1.579 + is.setSystemId( ss.getSystemId() ); 1.580 + is.setByteStream( ss.getInputStream() ); 1.581 + is.setCharacterStream( ss.getReader() ); 1.582 + 1.583 + return is; 1.584 + } 1.585 + 1.586 + public <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz) throws JAXBException { 1.587 + return context.getBeanInfo(clazz,true); 1.588 + } 1.589 + 1.590 + @Override 1.591 + public Listener getListener() { 1.592 + return externalListener; 1.593 + } 1.594 + 1.595 + @Override 1.596 + public void setListener(Listener listener) { 1.597 + externalListener = listener; 1.598 + } 1.599 + 1.600 + public UnmarshallingContext getContext() { 1.601 + return coordinator; 1.602 + } 1.603 + 1.604 + @Override 1.605 + @SuppressWarnings("FinalizeDeclaration") 1.606 + protected void finalize() throws Throwable { 1.607 + try { 1.608 + ClassFactory.cleanCache(); 1.609 + } finally { 1.610 + super.finalize(); 1.611 + } 1.612 + } 1.613 + 1.614 + /** 1.615 + * Must be called from same thread which created the UnmarshallerImpl instance. 1.616 + * @throws IOException 1.617 + */ 1.618 + public void close() throws IOException { 1.619 + ClassFactory.cleanCache(); 1.620 + } 1.621 + 1.622 +}