View Javadoc

1   //
2   // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.6-01/24/2006 06:15 PM(kohsuke)-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: 2012.10.03 at 04:27:47 AM CEST 
6   //
7   
8   package org.jdtaus.mojo.resource.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
23   * also creates the GrammarInfoFacade that unifies all of the grammar
24   * info from 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,
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 contextPath, ClassLoader 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       * <p>
77       * getGrammar is normally very expensive, so it's worth
78       * synchronizing to avoid unnecessary invocation.
79       */
80      public synchronized com.sun.msv.grammar.Grammar getGrammar() throws JAXBException {
81          if( grammar==null )
82              grammar = gi.getGrammar();
83          return grammar;
84      }
85      
86      
87      /**
88       * Create a <CODE>Marshaller</CODE> object that can be used to convert a
89       * java content-tree into XML data.
90       *
91       * @return a <CODE>Marshaller</CODE> object
92       * @throws JAXBException 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 XML
101      * data into a java content-tree.
102      *
103      * @return an <CODE>Unmarshaller</CODE> object
104      * @throws JAXBException if an error was encountered while creating the
105      *                      <code>Unmarshaller</code> object
106      */
107     public Unmarshaller createUnmarshaller() throws JAXBException {
108             return new UnmarshallerImpl( this, gi );
109     }    
110         
111     /**
112      * Create a <CODE>Validator</CODE> object that can be used to validate a
113      * java content-tree.
114      *
115      * @return an <CODE>Unmarshaller</CODE> object
116      * @throws JAXBException if an error was encountered while creating the
117      *                      <code>Validator</code> object
118      */
119     public Validator createValidator() throws JAXBException {
120             return new ValidatorImpl( this );
121     }
122     
123 
124     
125     /**
126      * Create an instance of the specified Java content interface.  
127      *
128      * @param javaContentInterface the Class object 
129      * @return an instance of the Java content interface
130      * @exception JAXBException
131      */
132     public Object newInstance( Class javaContentInterface ) 
133         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(
143                     Messages.format( 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 doesn't
154      */
155     public void setProperty( String name, Object value )
156         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 doesn't
164      */
165     public Object getProperty( String name )
166         throws PropertyException {
167             
168         throw new PropertyException(name);
169     }
170     
171     
172 }