public static SAXParserProvider getInstance() { final SecurityManager sm = System.getSecurityManager(); ClassLoader tccl = null; if (sm == null) { tccl = Thread.currentThread().getContextClassLoader(); } else { try { tccl = AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>() { public ClassLoader run() throws Exception { return Thread.currentThread().getContextClassLoader(); } }); } catch (PrivilegedActionException e) { throw new SecurityException(e); } } SAXParserProvider spp; spp = saxParserProviders.get(tccl); if (spp == null) { spp = new SAXParserProvider(); SAXParserProvider s = saxParserProviders.putIfAbsent(tccl, spp); if (s != null) spp = s; } return spp; }
SAXParser sp = SAXParserProvider.getInstance().getParser(disableExternalEntities, enableSecureProcessingFeature, disableDTDs); XMLReader xmlReader = sp.getXMLReader(); final SAXSource saxSource = new SAXSource(xmlReader, source);
public <T> JAXBElement<T> unmarshal(Source source, Class<T> declaredType) throws JAXBException { if(source instanceof SAXSource) { try { SAXParser sp = SAXParserProvider.getInstance().getParser(disableExternalEntities, enableSecureProcessingFeature, disableDTDs); XMLReader xmlReader = sp.getXMLReader(); ((SAXSource) source).setXMLReader(xmlReader); return delegate.unmarshal(source, declaredType); } catch (SAXException e) { throw new JAXBException(e); } catch (ParserConfigurationException e) { throw new JAXBException(e); } } throw new UnsupportedOperationException(Messages.MESSAGES.unexpectedUse("Source, Class<T>")); }
public Object unmarshal(Source source) throws JAXBException { if(source instanceof SAXSource) { try { SAXParser sp = SAXParserProvider.getInstance().getParser(disableExternalEntities, enableSecureProcessingFeature, disableDTDs); XMLReader xmlReader = sp.getXMLReader(); ((SAXSource) source).setXMLReader(xmlReader); return delegate.unmarshal(source); } catch (SAXException e) { throw new JAXBException(e); } catch (ParserConfigurationException e) { throw new JAXBException(e); } } throw new UnsupportedOperationException(Messages.MESSAGES.unexpectedUse("Source, Class<T>")); }