KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > jaxb > util > XMLUtil


1 package com.mvnforum.jaxb.util;
2
3 import java.io.File JavaDoc;
4
5 import javax.xml.bind.JAXBContext;
6 import javax.xml.bind.JAXBException;
7 import javax.xml.bind.Marshaller;
8 import javax.xml.bind.Unmarshaller;
9 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             jaxbContext = JAXBContext.newInstance("com.mvnforum.jaxb.db");
26             marshaller = jaxbContext.createMarshaller();
27             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT ,
28                    new Boolean JavaDoc(true));
29             objectFactory = new ObjectFactory();
30             validator = jaxbContext.createValidator();
31             unmarshaller = jaxbContext.createUnmarshaller();
32         } catch (JAXBException e) {
33             // TODO Auto-generated catch block
34
e.printStackTrace();
35         }
36     }
37     
38     public static Mvnforum getMvnforum () throws JAXBException {
39         if (mvnforum == null)
40             mvnforum = (Mvnforum) unmarshaller.unmarshal(new File JavaDoc ("xml/mvnforum2mvnforum.xml"));
41         return mvnforum;
42     }
43
44     public static JAXBContext getJaxbContext() {
45         return jaxbContext;
46     }
47
48     public static Marshaller getMarshaller() {
49         return marshaller;
50     }
51
52     public static ObjectFactory getObjectFactory() {
53         return objectFactory;
54     }
55
56     public static Validator getValidator() {
57         return validator;
58     }
59
60     public static Unmarshaller getUnmarshaller() {
61         return unmarshaller;
62     }
63
64     public static void setUnmarshaller(Unmarshaller unmarshaller) {
65         XMLUtil.unmarshaller = unmarshaller;
66     }
67     
68     
69    
70 }
71
Popular Tags