Code example for SAXSource

Methods: getInputSourcegetXMLReadersetInputSourcesetXMLReader

0
	 * @throws XmlMappingException if the given source cannot be mapped to an object 
	 * @throws IOException if an I/O Exception occurs 
	 * @see #unmarshalSaxReader(org.xml.sax.XMLReader, org.xml.sax.InputSource) 
	 */ 
	protected Object unmarshalSaxSource(SAXSource saxSource) throws XmlMappingException, IOException {
		if (saxSource.getXMLReader() == null) {
			try { 
				saxSource.setXMLReader(createXmlReader());
			} 
			catch (SAXException ex) {
				throw new UnmarshallingFailureException("Could not create XMLReader for SAXSource", ex);
			} 
		} 
		if (saxSource.getInputSource() == null) {
			saxSource.setInputSource(new InputSource());
		} 
		return unmarshalSaxReader(saxSource.getXMLReader(), saxSource.getInputSource());
	} 
 
	/** 
	 * Template method for handling {@code StreamSource}s. 
	 * <p>This implementation delegates to {@code unmarshalInputStream} or {@code unmarshalReader}. 
	 * @param streamSource the {@code StreamSource} 
	 * @return the object graph 
	 * @throws IOException if an I/O exception occurs 
	 * @throws XmlMappingException if the given source cannot be mapped to an object 
	 */ 
	protected Object unmarshalStreamSource(StreamSource streamSource) throws XmlMappingException, IOException {
		if (streamSource.getInputStream() != null) {
			if (isProcessExternalEntities()) {
				return unmarshalInputStream(streamSource.getInputStream());
			} 
			else { 
				InputSource inputSource = new InputSource(streamSource.getInputStream());
				inputSource.setEncoding(getDefaultEncoding());
				return unmarshalSaxSource(new SAXSource(inputSource));
			} 
		} 
		else if (streamSource.getReader() != null) {
			if (isProcessExternalEntities()) {
				return unmarshalReader(streamSource.getReader());
			} 
			else { 
				return unmarshalSaxSource(new SAXSource(new InputSource(streamSource.getReader())));
			} 
		} 
		else { 
			return unmarshalSaxSource(new SAXSource(new InputSource(streamSource.getSystemId())));
		}