KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > vo > jaxb > employee > impl > runtime > DefaultJAXBContextImpl


1 //
2
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.4-b18-fcs
3
// See <a HREF="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
4
// Any modifications to this file will be lost upon recompilation of the source schema.
5
// Generated on: 2006.10.05 at 10:03:40 CEST
6
//
7

8 package net.sf.dozer.util.mapping.vo.jaxb.employee.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
23  * also creates the GrammarInfoFacade that unifies all of the grammar
24  * info from packages on the contextPath.
25  *
26  * @version $Revision: 1.1 $
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,
34      * GrammarInfoFacade is used.
35      */

36     private GrammarInfo gi = null;
37
38     /**
39      * This is the constructor used by javax.xml.bind.FactoryFinder which
40      * bootstraps the RI. It causes the construction of a JAXBContext that
41      * contains a GrammarInfoFacade which is the union of all the generated
42      * JAXBContextImpl objects on the contextPath.
43      */

44     public DefaultJAXBContextImpl( String JavaDoc contextPath, ClassLoader JavaDoc classLoader )
45         throws JAXBException {
46             
47         this( GrammarInfoFacade.createGrammarInfoFacade( contextPath, classLoader ) );
48
49         // initialize datatype converter with ours
50
DatatypeConverter.setDatatypeConverter(DatatypeConverterImpl.theInstance);
51     }
52     
53     /**
54      * This constructor is used by the default no-arg constructor in the
55      * generated JAXBContextImpl objects. It is also used by the
56      * bootstrapping constructor in this class.
57      */

58     public DefaultJAXBContextImpl( GrammarInfo gi ) {
59         this.gi = gi;
60     }
61         
62     public GrammarInfo getGrammarInfo() {
63         return gi;
64     }
65     
66     
67     
68     /**
69      * Once we load a grammar, we will cache the value here.
70      */

71     private com.sun.msv.grammar.Grammar grammar = null;
72     
73     /**
74      * Loads a grammar object for the unmarshal-time validation.
75      */

76     public com.sun.msv.grammar.Grammar getGrammar() throws JAXBException {
77         if( grammar==null )
78             // since JAXBContext needs to be thread-safe,
79
// this check might allow more than one thread to
80
// load a grammar, but that's fine; it's just a loss of
81
// time, but by itself it doesn't cause any problem.
82
// by not synchronizing method, we can avoid its overhead.
83
grammar = gi.getGrammar();
84         return grammar;
85     }
86     
87     
88     /**
89      * Create a <CODE>Marshaller</CODE> object that can be used to convert a
90      * java content-tree into XML data.
91      *
92      * @return a <CODE>Marshaller</CODE> object
93      * @throws JAXBException if an error was encountered while creating the
94      * <code>Marshaller</code> object
95      */

96     public Marshaller createMarshaller() throws JAXBException {
97             return new MarshallerImpl( this );
98     }
99        
100     /**
101      * Create an <CODE>Unmarshaller</CODE> object that can be used to convert XML
102      * data into a java content-tree.
103      *
104      * @return an <CODE>Unmarshaller</CODE> object
105      * @throws JAXBException 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 if an error was encountered while creating the
118      * <code>Validator</code> object
119      */

120     public Validator createValidator() throws JAXBException {
121             return new ValidatorImpl( this );
122     }
123     
124
125     
126     /**
127      * Create an instance of the specified Java content interface.
128      *
129      * @param javaContentInterface the Class object
130      * @return an instance of the Java content interface
131      * @exception JAXBException
132      */

133     public Object JavaDoc newInstance( Class JavaDoc javaContentInterface )
134         throws JAXBException {
135
136         if( javaContentInterface == null ) {
137             throw new JAXBException( Messages.format( Messages.CI_NOT_NULL ) );
138         }
139
140         try {
141             Class JavaDoc c = gi.getDefaultImplementation( javaContentInterface );
142             if(c==null)
143                 throw new JAXBException(
144                     Messages.format( Messages.MISSING_INTERFACE, javaContentInterface ));
145             
146             return c.newInstance();
147         } catch( Exception JavaDoc e ) {
148             throw new JAXBException( e );
149         }
150     }
151     
152     /**
153      * There are no required properties, so simply throw an exception. Other
154      * providers may have support for properties on Validator, but the RI doesn't
155      */

156     public void setProperty( String JavaDoc name, Object JavaDoc value )
157         throws PropertyException {
158         
159         throw new PropertyException(name, value);
160     }
161     
162     /**
163      * There are no required properties, so simply throw an exception. Other
164      * providers may have support for properties on Validator, but the RI doesn't
165      */

166     public Object JavaDoc getProperty( String JavaDoc name )
167         throws PropertyException {
168             
169         throw new PropertyException(name);
170     }
171     
172     
173 }
174
Popular Tags