01: package com.mvnforum.jaxb.util;
02:
03: import java.io.File;
04:
05: import javax.xml.bind.JAXBContext;
06: import javax.xml.bind.JAXBException;
07: import javax.xml.bind.Marshaller;
08: import javax.xml.bind.Unmarshaller;
09: import javax.xml.bind.Validator;
10:
11: import com.mvnforum.jaxb.db.Mvnforum;
12: import com.mvnforum.jaxb.db.ObjectFactory;
13:
14: public class XMLUtil {
15:
16: public static JAXBContext jaxbContext = null;
17: public static ObjectFactory objectFactory = null;
18: public static Marshaller marshaller = null;
19: public static Validator validator = null;
20: public static Unmarshaller unmarshaller = null;
21: public static Mvnforum mvnforum = null;
22:
23: static {
24: try {
25:
26: jaxbContext = JAXBContext
27: .newInstance("com.mvnforum.jaxb.db");
28: marshaller = jaxbContext.createMarshaller();
29: marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
30: new Boolean(true));
31: objectFactory = new ObjectFactory();
32: validator = jaxbContext.createValidator();
33: unmarshaller = jaxbContext.createUnmarshaller();
34:
35: } catch (JAXBException e) {
36: // TODO Auto-generated catch block
37: e.printStackTrace();
38: }
39: }
40:
41: public static Mvnforum getMvnforum() throws JAXBException {
42:
43: if (mvnforum == null) {
44:
45: mvnforum = (Mvnforum) unmarshaller.unmarshal(new File(
46: "xml/mvnforum.xml"));
47:
48: }
49: return mvnforum;
50: }
51:
52: public static JAXBContext getJaxbContext() {
53: return jaxbContext;
54: }
55:
56: public static Marshaller getMarshaller() {
57: return marshaller;
58: }
59:
60: public static ObjectFactory getObjectFactory() {
61: return objectFactory;
62: }
63:
64: public static Validator getValidator() {
65: return validator;
66: }
67:
68: public static Unmarshaller getUnmarshaller() {
69: return unmarshaller;
70: }
71:
72: public static void setUnmarshaller(Unmarshaller unmarshaller) {
73: XMLUtil.unmarshaller = unmarshaller;
74: }
75:
76: }
|