1
2
3
4
5
6
7
8 package de.nierbeck.timeTrack.model.impl.runtime;
9
10 import javax.xml.bind.DatatypeConverter;
11 import javax.xml.bind.JAXBContext;
12 import javax.xml.bind.JAXBException;
13 import javax.xml.bind.Marshaller;
14 import javax.xml.bind.PropertyException;
15 import javax.xml.bind.Unmarshaller;
16 import javax.xml.bind.Validator;
17
18 import com.sun.xml.bind.Messages;
19 import com.sun.xml.bind.DatatypeConverterImpl;
20
21 /***
22 * This class provides the default implementation of JAXBContext. It also
23 * creates the GrammarInfoFacade that unifies all of the grammar info from
24 * packages on the contextPath.
25 *
26 * @version $Revision: 1.3 $
27 */
28 public class DefaultJAXBContextImpl extends JAXBContext {
29
30 /***
31 * This object keeps information about the grammar.
32 *
33 * When more than one package are specified, GrammarInfoFacade is used.
34 */
35 private GrammarInfo gi = null;
36
37 /***
38 * This is the constructor used by javax.xml.bind.FactoryFinder which
39 * bootstraps the RI. It causes the construction of a JAXBContext that
40 * contains a GrammarInfoFacade which is the union of all the generated
41 * JAXBContextImpl objects on the contextPath.
42 */
43 public DefaultJAXBContextImpl(String contextPath, ClassLoader classLoader)
44 throws JAXBException {
45
46 this(GrammarInfoFacade
47 .createGrammarInfoFacade(contextPath, classLoader));
48
49
50 DatatypeConverter
51 .setDatatypeConverter(DatatypeConverterImpl.theInstance);
52 }
53
54 /***
55 * This constructor is used by the default no-arg constructor in the
56 * generated JAXBContextImpl objects. It is also used by the bootstrapping
57 * constructor in this class.
58 */
59 public DefaultJAXBContextImpl(GrammarInfo gi) {
60 this.gi = gi;
61 }
62
63 public GrammarInfo getGrammarInfo() {
64 return gi;
65 }
66
67 /***
68 * Once we load a grammar, we will cache the value here.
69 */
70 private com.sun.msv.grammar.Grammar grammar = null;
71
72 /***
73 * Loads a grammar object for the unmarshal-time validation.
74 */
75 public com.sun.msv.grammar.Grammar getGrammar() throws JAXBException {
76 if (grammar == null)
77
78
79
80
81
82 grammar = gi.getGrammar();
83 return grammar;
84 }
85
86 /***
87 * Create a <CODE>Marshaller</CODE> object that can be used to convert a
88 * java content-tree into XML data.
89 *
90 * @return a <CODE>Marshaller</CODE> object
91 * @throws JAXBException
92 * if an error was encountered while creating the
93 * <code>Marshaller</code> object
94 */
95 public Marshaller createMarshaller() throws JAXBException {
96 return new MarshallerImpl(this);
97 }
98
99 /***
100 * Create an <CODE>Unmarshaller</CODE> object that can be used to convert
101 * XML data into a java content-tree.
102 *
103 * @return an <CODE>Unmarshaller</CODE> object
104 * @throws JAXBException
105 * if an error was encountered while creating the
106 * <code>Unmarshaller</code> object
107 */
108 public Unmarshaller createUnmarshaller() throws JAXBException {
109 return new UnmarshallerImpl(this, gi);
110 }
111
112 /***
113 * Create a <CODE>Validator</CODE> object that can be used to validate a
114 * java content-tree.
115 *
116 * @return an <CODE>Unmarshaller</CODE> object
117 * @throws JAXBException
118 * if an error was encountered while creating the
119 * <code>Validator</code> object
120 */
121 public Validator createValidator() throws JAXBException {
122 return new ValidatorImpl(this);
123 }
124
125 /***
126 * Create an instance of the specified Java content interface.
127 *
128 * @param javaContentInterface
129 * the Class object
130 * @return an instance of the Java content interface
131 * @exception JAXBException
132 */
133 public Object newInstance(Class javaContentInterface) throws JAXBException {
134
135 if (javaContentInterface == null) {
136 throw new JAXBException(Messages.format(Messages.CI_NOT_NULL));
137 }
138
139 try {
140 Class c = gi.getDefaultImplementation(javaContentInterface);
141 if (c == null)
142 throw new JAXBException(Messages.format(
143 Messages.MISSING_INTERFACE, javaContentInterface));
144
145 return c.newInstance();
146 } catch (Exception e) {
147 throw new JAXBException(e);
148 }
149 }
150
151 /***
152 * There are no required properties, so simply throw an exception. Other
153 * providers may have support for properties on Validator, but the RI
154 * doesn't
155 */
156 public void setProperty(String name, Object value) throws PropertyException {
157
158 throw new PropertyException(name, value);
159 }
160
161 /***
162 * There are no required properties, so simply throw an exception. Other
163 * providers may have support for properties on Validator, but the RI
164 * doesn't
165 */
166 public Object getProperty(String name) throws PropertyException {
167
168 throw new PropertyException(name);
169 }
170
171 }