001//
002// 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 
003// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
004// Any modifications to this file will be lost upon recompilation of the source schema. 
005// Generated on: 2012.10.03 at 04:27:47 AM CEST 
006//
007
008package org.jdtaus.mojo.resource.model.impl.runtime;
009
010import javax.xml.bind.DatatypeConverter;
011import javax.xml.bind.JAXBContext;
012import javax.xml.bind.JAXBException;
013import javax.xml.bind.Marshaller;
014import javax.xml.bind.PropertyException;
015import javax.xml.bind.Unmarshaller;
016import javax.xml.bind.Validator;
017
018import com.sun.xml.bind.Messages;
019import com.sun.xml.bind.DatatypeConverterImpl;
020
021/**
022 * This class provides the default implementation of JAXBContext.  It
023 * also creates the GrammarInfoFacade that unifies all of the grammar
024 * info from packages on the contextPath.
025 *
026 * @version $Revision: 1.3 $
027 */
028public class DefaultJAXBContextImpl extends JAXBContext {
029    
030    /**
031     * This object keeps information about the grammar.
032     * 
033     * When more than one package are specified,
034     * GrammarInfoFacade is used.
035     */
036    private GrammarInfo gi = null;
037
038    /**
039     * This is the constructor used by javax.xml.bind.FactoryFinder which
040     * bootstraps the RI.  It causes the construction of a JAXBContext that
041     * contains a GrammarInfoFacade which is the union of all the generated
042     * JAXBContextImpl objects on the contextPath.
043     */
044    public DefaultJAXBContextImpl( String contextPath, ClassLoader classLoader ) 
045        throws JAXBException {
046            
047        this( GrammarInfoFacade.createGrammarInfoFacade( contextPath, classLoader ) );
048
049        // initialize datatype converter with ours
050        DatatypeConverter.setDatatypeConverter(DatatypeConverterImpl.theInstance);
051    }
052    
053    /**
054     * This constructor is used by the default no-arg constructor in the
055     * generated JAXBContextImpl objects.  It is also used by the 
056     * bootstrapping constructor in this class.
057     */
058    public DefaultJAXBContextImpl( GrammarInfo gi ) {
059        this.gi = gi;
060    }
061        
062    public GrammarInfo getGrammarInfo() { 
063        return gi;
064    }
065    
066    
067    
068    /**
069     * Once we load a grammar, we will cache the value here.
070     */
071    private com.sun.msv.grammar.Grammar grammar = null;
072    
073    /**
074     * Loads a grammar object for the unmarshal-time validation.
075     * 
076     * <p>
077     * getGrammar is normally very expensive, so it's worth
078     * synchronizing to avoid unnecessary invocation.
079     */
080    public synchronized com.sun.msv.grammar.Grammar getGrammar() throws JAXBException {
081        if( grammar==null )
082            grammar = gi.getGrammar();
083        return grammar;
084    }
085    
086    
087    /**
088     * Create a <CODE>Marshaller</CODE> object that can be used to convert a
089     * java content-tree into XML data.
090     *
091     * @return a <CODE>Marshaller</CODE> object
092     * @throws JAXBException if an error was encountered while creating the
093     *                      <code>Marshaller</code> object
094     */
095    public Marshaller createMarshaller() throws JAXBException {
096            return new MarshallerImpl( this );
097    }
098       
099    /**
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}