1 package org.openprovenance.model.printer;
2 import java.io.File;
3 import java.io.InputStream;
4 import java.io.IOException;
5 import javax.xml.bind.JAXBContext;
6 import javax.xml.bind.Unmarshaller;
7 import javax.xml.bind.JAXBException;
8 import javax.xml.bind.JAXBElement;
9 import org.w3c.dom.Element;
10 import org.xml.sax.SAXException;
11
12 import javax.xml.validation.SchemaFactory;
13 import javax.xml.validation.Schema;
14 import javax.xml.transform.stream.StreamSource;
15 import javax.xml.transform.Source;
16
17 import org.openprovenance.model.printer.OPMPrinterConfiguration;
18
19 /*** Deserialiser of OPM Graphs. */
20 public class OPMPrinterConfigDeserialiser {
21
22
23
24
25
26
27
28
29 static protected JAXBContext jc;
30
31 public OPMPrinterConfigDeserialiser () throws JAXBException {
32 if (jc==null)
33 jc = JAXBContext.newInstance( "org.openprovenance.model.printer" );
34 }
35
36 public OPMPrinterConfigDeserialiser (String packageList) throws JAXBException {
37 if (jc==null)
38 jc = JAXBContext.newInstance(packageList);
39 }
40
41
42 private static ThreadLocal<OPMPrinterConfigDeserialiser> threadDeserialiser=
43 new ThreadLocal<OPMPrinterConfigDeserialiser> () {
44 protected synchronized OPMPrinterConfigDeserialiser initialValue () {
45 try {
46 return new OPMPrinterConfigDeserialiser();
47 } catch (JAXBException jxb) {
48 throw new RuntimeException("OPMPrinterConfigDeserialiser: deserialiser init failure()");
49 }
50 }
51 };
52
53 public static OPMPrinterConfigDeserialiser getThreadOPMPrinterConfigDeserialiser() {
54 return threadDeserialiser.get();
55 }
56
57
58 public OPMPrinterConfiguration deserialiseOPMPrinterConfiguration (File serialised)
59 throws JAXBException {
60 Unmarshaller u=jc.createUnmarshaller();
61 Object root= u.unmarshal(serialised);
62 OPMPrinterConfiguration res=(OPMPrinterConfiguration)((JAXBElement<OPMPrinterConfiguration>) root).getValue();
63 return res;
64 }
65
66 public OPMPrinterConfiguration deserialiseOPMPrinterConfiguration (InputStream serialised)
67 throws JAXBException {
68 Unmarshaller u=jc.createUnmarshaller();
69 Object root= u.unmarshal(serialised);
70 OPMPrinterConfiguration res=(OPMPrinterConfiguration)((JAXBElement<OPMPrinterConfiguration>) root).getValue();
71 return res;
72 }
73
74 }