1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.xml;
17
18 import javax.xml.bind.JAXBContext;
19 import javax.xml.bind.JAXBException;
20 import javax.xml.bind.util.JAXBResult;
21 import javax.xml.transform.Result;
22
23
24
25
26 abstract public class JaxbResultHolder<T> implements ResultHolder<T> {
27 private final JAXBContext jaxbContext;
28
29 private JAXBResult result;
30
31
32
33
34
35 public JaxbResultHolder(Class<T> clazz) {
36 try {
37 jaxbContext = JAXBContext.newInstance(clazz);
38 } catch (JAXBException e) {
39 throw new RuntimeException(e);
40 }
41 }
42
43 @Override
44 public T getResult() {
45 try {
46 return (T) result.getResult();
47 } catch (JAXBException e) {
48 throw new RuntimeException(e);
49 }
50 }
51
52 @Override
53 public Result createResult() {
54 try {
55 result = new JAXBResult(jaxbContext.createUnmarshaller());
56 } catch (JAXBException e) {
57 throw new RuntimeException(e);
58 }
59 return result;
60 }
61 }