File: AbstractMarshaller.java

package info (click to toggle)
libspring-java 3.0.6.RELEASE-6+deb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 50,476 kB
  • ctags: 58,535
  • sloc: java: 325,411; xml: 67,956; sql: 176; makefile: 40; ruby: 33; sh: 6
file content (566 lines) | stat: -rw-r--r-- 23,855 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
/*
 * Copyright 2002-2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.oxm.support;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Node;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.XMLReaderFactory;

import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.UnmarshallingFailureException;
import org.springframework.oxm.XmlMappingException;
import org.springframework.util.Assert;
import org.springframework.util.xml.StaxUtils;

/**
 * Abstract implementation of the <code>Marshaller</code> and <code>Unmarshaller</code> interface.
 * This implementation inspects the given <code>Source</code> or <code>Result</code>, and defers
 * further handling to overridable template methods.
 *
 * @author Arjen Poutsma
 * @author Juergen Hoeller
 * @since 3.0
 */
public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {

	/** Logger available to subclasses. */
	protected final Log logger = LogFactory.getLog(getClass());

	private DocumentBuilderFactory documentBuilderFactory;

	private final Object documentBuilderFactoryMonitor = new Object();

	private boolean processExternalEntities = false;


	/**
	 * Indicates whether external XML entities are processed when unmarshalling.
	 * <p>Default is {@code false}, meaning that external entities are not resolved.
	 * Note that processing of external entities will only be enabled/disabled when the
	 * {@code Source} passed to {@link #unmarshal(Source)} is a {@link SAXSource} or
	 * {@link StreamSource}. It has no effect for {@link DOMSource} or {@link StAXSource}
	 * instances.
	 */
	public void setProcessExternalEntities(boolean processExternalEntities) {
		this.processExternalEntities = processExternalEntities;
	}

	/**
	 * @return the configured value for whether XML external entities are allowed.
	 */
	public boolean isProcessExternalEntities() {
		return this.processExternalEntities;
	}

	/**
	 * @return the default encoding to use for marshalling or unmarshalling from
	 * 	a byte stream, or {@code null}.
	 */
	abstract protected String getDefaultEncoding();


	/**
	 * Marshals the object graph with the given root into the provided <code>javax.xml.transform.Result</code>.
	 * <p>This implementation inspects the given result, and calls <code>marshalDomResult</code>,
	 * <code>marshalSaxResult</code>, or <code>marshalStreamResult</code>.
	 * @param graph the root of the object graph to marshal
	 * @param result the result to marshal to
	 * @throws IOException if an I/O exception occurs
	 * @throws XmlMappingException if the given object cannot be marshalled to the result
	 * @throws IllegalArgumentException if <code>result</code> if neither a <code>DOMResult</code>,
	 * a <code>SAXResult</code>, nor a <code>StreamResult</code>
	 * @see #marshalDomResult(Object, javax.xml.transform.dom.DOMResult)
	 * @see #marshalSaxResult(Object, javax.xml.transform.sax.SAXResult)
	 * @see #marshalStreamResult(Object, javax.xml.transform.stream.StreamResult)
	 */
	public final void marshal(Object graph, Result result) throws IOException, XmlMappingException {
		if (result instanceof DOMResult) {
			marshalDomResult(graph, (DOMResult) result);
		}
		else if (StaxUtils.isStaxResult(result)) {
			marshalStaxResult(graph, result);
		}
		else if (result instanceof SAXResult) {
			marshalSaxResult(graph, (SAXResult) result);
		}
		else if (result instanceof StreamResult) {
			marshalStreamResult(graph, (StreamResult) result);
		}
		else {
			throw new IllegalArgumentException("Unknown Result type: " + result.getClass());
		}
	}

	/**
	 * Unmarshals the given provided <code>javax.xml.transform.Source</code> into an object graph.
	 * <p>This implementation inspects the given result, and calls <code>unmarshalDomSource</code>,
	 * <code>unmarshalSaxSource</code>, or <code>unmarshalStreamSource</code>.
	 * @param source the source to marshal from
	 * @return the object graph
	 * @throws IOException if an I/O Exception occurs
	 * @throws XmlMappingException if the given source cannot be mapped to an object
	 * @throws IllegalArgumentException if <code>source</code> is neither a <code>DOMSource</code>,
	 * a <code>SAXSource</code>, nor a <code>StreamSource</code>
	 * @see #unmarshalDomSource(javax.xml.transform.dom.DOMSource)
	 * @see #unmarshalSaxSource(javax.xml.transform.sax.SAXSource)
	 * @see #unmarshalStreamSource(javax.xml.transform.stream.StreamSource)
	 */
	public final Object unmarshal(Source source) throws IOException, XmlMappingException {
		if (source instanceof DOMSource) {
			return unmarshalDomSource((DOMSource) source);
		}
		else if (StaxUtils.isStaxSource(source)) {
			return unmarshalStaxSource(source);
		}
		else if (source instanceof SAXSource) {
			return unmarshalSaxSource((SAXSource) source);
		}
		else if (source instanceof StreamSource) {
			return unmarshalStreamSourceNoExternalEntitities((StreamSource) source);
		}
		else {
			throw new IllegalArgumentException("Unknown Source type: " + source.getClass());
		}
	}

	/**
	 * Create a <code>DocumentBuilder</code> that this marshaller will use for creating
	 * DOM documents when passed an empty <code>DOMSource</code>.
	 * <p>Can be overridden in subclasses, adding further initialization of the builder.
	 * @param factory the <code>DocumentBuilderFactory</code> that the DocumentBuilder should be created with
	 * @return the <code>DocumentBuilder</code>
	 * @throws ParserConfigurationException if thrown by JAXP methods
	 */
	protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory)
			throws ParserConfigurationException {

		return factory.newDocumentBuilder();
	}

	/**
	 * Create a <code>DocumentBuilder</code> that this marshaller will use for creating
	 * DOM documents when passed an empty <code>DOMSource</code>.
	 * <p>The resulting <code>DocumentBuilderFactory</code> is cached, so this method
	 * will only be called once.
	 * @return the DocumentBuilderFactory
	 * @throws ParserConfigurationException if thrown by JAXP methods
	 */
	protected DocumentBuilderFactory createDocumentBuilderFactory() throws ParserConfigurationException {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		factory.setValidating(false);
		factory.setNamespaceAware(true);
		return factory;
	}

	/**
	 * Create a <code>XMLReader</code> that this marshaller will when passed an empty <code>SAXSource</code>.
	 * @return the XMLReader
	 * @throws SAXException if thrown by JAXP methods
	 */
	protected XMLReader createXmlReader() throws SAXException {
		XMLReader xmlReader = XMLReaderFactory.createXMLReader();
		xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", isProcessExternalEntities());
		return xmlReader;
	}


	// Marshalling

	/**
	 * Template method for handling <code>DOMResult</code>s.
	 * <p>This implementation delegates to <code>marshalDomNode</code>.
	 * @param graph	the root of the object graph to marshal
	 * @param domResult the <code>DOMResult</code>
	 * @throws XmlMappingException if the given object cannot be marshalled to the result
	 * @throws IllegalArgumentException if the <code>domResult</code> is empty
	 * @see #marshalDomNode(Object, org.w3c.dom.Node)
	 */
	protected void marshalDomResult(Object graph, DOMResult domResult) throws XmlMappingException {
		if (domResult.getNode() == null) {
			try {
				synchronized (this.documentBuilderFactoryMonitor) {
					if (this.documentBuilderFactory == null) {
						this.documentBuilderFactory = createDocumentBuilderFactory();
					}
				}
				DocumentBuilder documentBuilder = createDocumentBuilder(this.documentBuilderFactory);
				domResult.setNode(documentBuilder.newDocument());
			}
			catch (ParserConfigurationException ex) {
				throw new UnmarshallingFailureException(
						"Could not create document placeholder for DOMResult: " + ex.getMessage(), ex);
			}
		}
		marshalDomNode(graph, domResult.getNode());
	}

	/**
	 * Template method for handling <code>StaxResult</code>s.
	 * <p>This implementation delegates to <code>marshalXMLSteamWriter</code> or
	 * <code>marshalXMLEventConsumer</code>, depending on what is contained in the
	 * <code>StaxResult</code>.
	 * @param graph	the root of the object graph to marshal
	 * @param staxResult a Spring {@link org.springframework.util.xml.StaxSource} or JAXP 1.4 {@link StAXSource}
	 * @throws XmlMappingException if the given object cannot be marshalled to the result
	 * @throws IllegalArgumentException if the <code>domResult</code> is empty
	 * @see #marshalDomNode(Object,org.w3c.dom.Node)
	 */
	protected void marshalStaxResult(Object graph, Result staxResult) throws XmlMappingException {
		XMLStreamWriter streamWriter = StaxUtils.getXMLStreamWriter(staxResult);
		if (streamWriter != null) {
			marshalXmlStreamWriter(graph, streamWriter);
		}
		else {
			XMLEventWriter eventWriter = StaxUtils.getXMLEventWriter(staxResult);
			if (eventWriter != null) {
				marshalXmlEventWriter(graph, eventWriter);
			}
			else {
				throw new IllegalArgumentException("StaxResult contains neither XMLStreamWriter nor XMLEventConsumer");
			}
		}
	}

	/**
	 * Template method for handling <code>SAXResult</code>s.
	 * <p>This implementation delegates to <code>marshalSaxHandlers</code>.
	 * @param graph	the root of the object graph to marshal
	 * @param saxResult the <code>SAXResult</code>
	 * @throws XmlMappingException if the given object cannot be marshalled to the result
	 * @see #marshalSaxHandlers(Object, org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler)
	 */
	protected void marshalSaxResult(Object graph, SAXResult saxResult) throws XmlMappingException {
		ContentHandler contentHandler = saxResult.getHandler();
		Assert.notNull(contentHandler, "ContentHandler not set on SAXResult");
		LexicalHandler lexicalHandler = saxResult.getLexicalHandler();
		marshalSaxHandlers(graph, contentHandler, lexicalHandler);
	}

	/**
	 * Template method for handling <code>StreamResult</code>s.
	 * <p>This implementation delegates to <code>marshalOutputStream</code> or <code>marshalWriter</code>,
	 * depending on what is contained in the <code>StreamResult</code>
	 * @param graph the root of the object graph to marshal
	 * @param streamResult the <code>StreamResult</code>
	 * @throws IOException if an I/O Exception occurs
	 * @throws XmlMappingException if the given object cannot be marshalled to the result
	 * @throws IllegalArgumentException if <code>streamResult</code> does neither
	 * contain an <code>OutputStream</code> nor a <code>Writer</code>
	 */
	protected void marshalStreamResult(Object graph, StreamResult streamResult)
			throws XmlMappingException, IOException {

		if (streamResult.getOutputStream() != null) {
			marshalOutputStream(graph, streamResult.getOutputStream());
		}
		else if (streamResult.getWriter() != null) {
			marshalWriter(graph, streamResult.getWriter());
		}
		else {
			throw new IllegalArgumentException("StreamResult contains neither OutputStream nor Writer");
		}
	}


	// Unmarshalling

	/**
	 * Template method for handling <code>DOMSource</code>s.
	 * <p>This implementation delegates to <code>unmarshalDomNode</code>.
	 * If the given source is empty, an empty source <code>Document</code>
	 * will be created as a placeholder.
	 * @param domSource the <code>DOMSource</code>
	 * @return the object graph
	 * @throws XmlMappingException if the given source cannot be mapped to an object
	 * @throws IllegalArgumentException if the <code>domSource</code> is empty
	 * @see #unmarshalDomNode(org.w3c.dom.Node)
	 */
	protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException {
		if (domSource.getNode() == null) {
			try {
				synchronized (this.documentBuilderFactoryMonitor) {
					if (this.documentBuilderFactory == null) {
						this.documentBuilderFactory = createDocumentBuilderFactory();
					}
				}
				DocumentBuilder documentBuilder = createDocumentBuilder(this.documentBuilderFactory);
				domSource.setNode(documentBuilder.newDocument());
			}
			catch (ParserConfigurationException ex) {
				throw new UnmarshallingFailureException(
						"Could not create document placeholder for DOMSource: " + ex.getMessage(), ex);
			}
		}
		return unmarshalDomNode(domSource.getNode());
	}

	/**
	 * Template method for handling <code>StaxSource</code>s.
	 * <p>This implementation delegates to <code>unmarshalXmlStreamReader</code> or
	 * <code>unmarshalXmlEventReader</code>.
	 * @param staxSource the <code>StaxSource</code>
	 * @return the object graph
	 * @throws XmlMappingException if the given source cannot be mapped to an object
	 */
	protected Object unmarshalStaxSource(Source staxSource) throws XmlMappingException {
		XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource);
		if (streamReader != null) {
			return unmarshalXmlStreamReader(streamReader);
		}
		else {
			XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource);
			if (eventReader != null) {
				return unmarshalXmlEventReader(eventReader);
			}
			else {
				throw new IllegalArgumentException("StaxSource contains neither XMLStreamReader nor XMLEventReader");
			}
		}
	}

	/**
	 * Template method for handling <code>SAXSource</code>s.
	 * <p>This implementation delegates to <code>unmarshalSaxReader</code>.
	 * @param saxSource the <code>SAXSource</code>
	 * @return the object graph
	 * @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 with protection against
	 * the XML External Entity (XXE) processing vulnerability taking into account
	 * the value of the {@link #setProcessExternalEntities(boolean)} property.
	 * <p>
	 * The default implementation wraps the StreamSource as a SAXSource and delegates
	 * to {@link #unmarshalSaxSource(javax.xml.transform.sax.SAXSource)}.
	 *
	 * @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
	 *
	 * @see <a href="https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing">XML_External_Entity_(XXE)_Processing</a>
	 */
	protected Object unmarshalStreamSourceNoExternalEntitities(StreamSource streamSource) throws XmlMappingException, IOException {
		InputSource inputSource;
		if (streamSource.getInputStream() != null) {
			inputSource = new InputSource(streamSource.getInputStream());
			inputSource.setEncoding(getDefaultEncoding());
		}
		else if (streamSource.getReader() != null) {
			inputSource = new InputSource(streamSource.getReader());
		}
		else {
			inputSource = new InputSource(streamSource.getSystemId());
		}
		return unmarshalSaxSource(new SAXSource(inputSource));
	}

	/**
	 * Template method for handling <code>StreamSource</code>s.
	 * <p>This implementation defers to <code>unmarshalInputStream</code> or <code>unmarshalReader</code>.
	 * <p>As of 3.2.8 and 4.0.2 this method is no longer invoked from
	 * {@link #unmarshal(javax.xml.transform.Source)}. The method invoked instead is
	 * {@link #unmarshalStreamSourceNoExternalEntitities(javax.xml.transform.stream.StreamSource)}.
	 *
	 * @param streamSource the <code>StreamSource</code>
	 * @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) {
			return unmarshalInputStream(streamSource.getInputStream());
		}
		else if (streamSource.getReader() != null) {
			return unmarshalReader(streamSource.getReader());
		}
		else {
			throw new IllegalArgumentException("StreamSource contains neither InputStream nor Reader");
		}
	}


	// Abstract template methods

	/**
	 * Abstract template method for marshalling the given object graph to a DOM <code>Node</code>.
	 * <p>In practice, node is be a <code>Document</code> node, a <code>DocumentFragment</code> node,
	 * or a <code>Element</code> node. In other words, a node that accepts children.
	 * @param graph the root of the object graph to marshal
	 * @param node the DOM node that will contain the result tree
	 * @throws XmlMappingException if the given object cannot be marshalled to the DOM node
	 * @see org.w3c.dom.Document
	 * @see org.w3c.dom.DocumentFragment
	 * @see org.w3c.dom.Element
	 */
	protected abstract void marshalDomNode(Object graph, Node node)
			throws XmlMappingException;

	/**
	 * Abstract template method for marshalling the given object to a StAX <code>XMLEventWriter</code>.
	 * @param graph	the root of the object graph to marshal
	 * @param eventWriter the <code>XMLEventWriter</code> to write to
	 * @throws XmlMappingException if the given object cannot be marshalled to the DOM node
	 */
	protected abstract void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter)
			throws XmlMappingException;

	/**
	 * Abstract template method for marshalling the given object to a StAX <code>XMLStreamWriter</code>.
	 * @param graph the root of the object graph to marshal
	 * @param streamWriter the <code>XMLStreamWriter</code> to write to
	 * @throws XmlMappingException if the given object cannot be marshalled to the DOM node
	 */
	protected abstract void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter)
			throws XmlMappingException;

	/**
	 * Abstract template method for marshalling the given object graph to a <code>OutputStream</code>.
	 * @param graph the root of the object graph to marshal
	 * @param outputStream the <code>OutputStream</code> to write to
	 * @throws XmlMappingException if the given object cannot be marshalled to the writer
	 * @throws IOException if an I/O exception occurs
	 */
	protected abstract void marshalOutputStream(Object graph, OutputStream outputStream)
			throws XmlMappingException, IOException;

	/**
	 * Abstract template method for marshalling the given object graph to a SAX <code>ContentHandler</code>.
	 * @param graph the root of the object graph to marshal
	 * @param contentHandler the SAX <code>ContentHandler</code>
	 * @param lexicalHandler the SAX2 <code>LexicalHandler</code>. Can be <code>null</code>.
	 * @throws XmlMappingException if the given object cannot be marshalled to the handlers
	 */
	protected abstract void marshalSaxHandlers(
			Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
			throws XmlMappingException;

	/**
	 * Abstract template method for marshalling the given object graph to a <code>Writer</code>.
	 * @param graph the root of the object graph to marshal
	 * @param writer the <code>Writer</code> to write to
	 * @throws XmlMappingException if the given object cannot be marshalled to the writer
	 * @throws IOException if an I/O exception occurs
	 */
	protected abstract void marshalWriter(Object graph, Writer writer)
			throws XmlMappingException, IOException;

	/**
	 * Abstract template method for unmarshalling from a given DOM <code>Node</code>.
	 * @param node the DOM node that contains the objects to be unmarshalled
	 * @return the object graph
	 * @throws XmlMappingException if the given DOM node cannot be mapped to an object
	 */
	protected abstract Object unmarshalDomNode(Node node) throws XmlMappingException;

	/**
	 * Abstract template method for unmarshalling from a given Stax <code>XMLEventReader</code>.
	 * @param eventReader the <code>XMLEventReader</code> to read from
	 * @return the object graph
	 * @throws XmlMappingException if the given event reader cannot be converted to an object
	 */
	protected abstract Object unmarshalXmlEventReader(XMLEventReader eventReader)
			throws XmlMappingException;

	/**
	 * Abstract template method for unmarshalling from a given Stax <code>XMLStreamReader</code>.
	 * @param streamReader the <code>XMLStreamReader</code> to read from
	 * @return the object graph
	 * @throws XmlMappingException if the given stream reader cannot be converted to an object
	 */
	protected abstract Object unmarshalXmlStreamReader(XMLStreamReader streamReader)
			throws XmlMappingException;

	/**
	 * Abstract template method for unmarshalling from a given <code>InputStream</code>.
	 * @param inputStream the <code>InputStreamStream</code> to read from
	 * @return the object graph
	 * @throws XmlMappingException if the given stream cannot be converted to an object
	 * @throws IOException if an I/O exception occurs
	 */
	protected abstract Object unmarshalInputStream(InputStream inputStream)
			throws XmlMappingException, IOException;

	/**
	 * Abstract template method for unmarshalling from a given <code>Reader</code>.
	 * @param reader the <code>Reader</code> to read from
	 * @return the object graph
	 * @throws XmlMappingException if the given reader cannot be converted to an object
	 * @throws IOException if an I/O exception occurs
	 */
	protected abstract Object unmarshalReader(Reader reader)
			throws XmlMappingException, IOException;

	/**
	 * Abstract template method for unmarshalling using a given SAX <code>XMLReader</code>
	 * and <code>InputSource</code>.
	 * @param xmlReader the SAX <code>XMLReader</code> to parse with
	 * @param inputSource the input source to parse from
	 * @return the object graph
	 * @throws XmlMappingException if the given reader and input source cannot be converted to an object
	 * @throws IOException if an I/O exception occurs
	 */
	protected abstract Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
			throws XmlMappingException, IOException;

}