001 // 002 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.1-05/30/2003 05:06 AM(java_re)-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: 2004.10.11 at 12:13:34 EDT 006 // 007 008 /* 009 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 010 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 011 */ 012 013 /* 014 * @(#)$Id: DefaultJAXBContextImpl.java,v 1.8 2003/05/14 18:36:17 lschwenk Exp $ 015 */ 016 package astronomy.data.spectra.impl.runtime; 017 018 import javax.xml.bind.DatatypeConverter; 019 import javax.xml.bind.JAXBContext; 020 import javax.xml.bind.JAXBException; 021 import javax.xml.bind.Marshaller; 022 import javax.xml.bind.PropertyException; 023 import javax.xml.bind.Unmarshaller; 024 import javax.xml.bind.Validator; 025 026 import com.sun.msv.grammar.Grammar; 027 import com.sun.xml.bind.Messages; 028 import com.sun.xml.bind.DatatypeConverterImpl; 029 030 /** 031 * This class provides the default implementation of JAXBContext. It 032 * also creates the GrammarInfoFacade that unifies all of the grammar 033 * info from packages on the contextPath. 034 * 035 * @version $Revision: 1.8 $ 036 */ 037 public class DefaultJAXBContextImpl extends JAXBContext { 038 039 /** 040 * This object keeps information about the grammar. 041 * 042 * When more than one package are specified, 043 * GrammarInfoFacade is used. 044 */ 045 private GrammarInfo gi = null; 046 047 /** 048 * Once we load a grammar, we will cache the value here. 049 */ 050 private Grammar grammar = null; 051 052 /** 053 * This is the constructor used by javax.xml.bind.FactoryFinder which 054 * bootstraps the RI. It causes the construction of a JAXBContext that 055 * contains a GrammarInfoFacade which is the union of all the generated 056 * JAXBContextImpl objects on the contextPath. 057 */ 058 public DefaultJAXBContextImpl( String contextPath, ClassLoader classLoader ) 059 throws JAXBException { 060 061 this( GrammarInfoFacade.createGrammarInfoFacade( contextPath, classLoader ) ); 062 063 // initialize datatype converter with ours 064 DatatypeConverter.setDatatypeConverter(DatatypeConverterImpl.theInstance); 065 } 066 067 /** 068 * This constructor is used by the default no-arg constructor in the 069 * generated JAXBContextImpl objects. It is also used by the 070 * bootstrapping constructor in this class. 071 */ 072 public DefaultJAXBContextImpl( GrammarInfo gi ) { 073 this.gi = gi; 074 } 075 076 public GrammarInfo getGrammarInfo() { 077 return gi; 078 } 079 080 /** 081 * Loads a grammar object for the unmarshal-time validation. 082 */ 083 public Grammar getGrammar() throws JAXBException { 084 if( grammar==null ) 085 // since JAXBContext needs to be thread-safe, 086 // this check might allow more than one thread to 087 // load a grammar, but that's fine; it's just a loss of 088 // time, but by itself it doesn't cause any problem. 089 // by not synchronizing method, we can avoid its overhead. 090 grammar = gi.getGrammar(); 091 return grammar; 092 } 093 094 095 /** 096 * Create a <CODE>Marshaller</CODE> object that can be used to convert a 097 * java content-tree into XML data. 098 * 099 * @return a <CODE>Marshaller</CODE> object 100 * @throws JAXBException if an error was encountered while creating the 101 * <code>Marshaller</code> object 102 */ 103 public Marshaller createMarshaller() throws JAXBException { 104 return new MarshallerImpl(); 105 } 106 107 /** 108 * Create an <CODE>Unmarshaller</CODE> object that can be used to convert XML 109 * data into a java content-tree. 110 * 111 * @return an <CODE>Unmarshaller</CODE> object 112 * @throws JAXBException if an error was encountered while creating the 113 * <code>Unmarshaller</code> object 114 */ 115 public Unmarshaller createUnmarshaller() throws JAXBException { 116 // TODO: revisit TypeRegistry. 117 // we don't need to create TypeRegistry everytime we create unmarshaller. 118 return new UnmarshallerImpl( this, gi ); 119 } 120 121 /** 122 * Create a <CODE>Validator</CODE> object that can be used to validate a 123 * java content-tree. 124 * 125 * @return an <CODE>Unmarshaller</CODE> object 126 * @throws JAXBException if an error was encountered while creating the 127 * <code>Validator</code> object 128 */ 129 public Validator createValidator() throws JAXBException { 130 return new ValidatorImpl(); 131 } 132 133 134 135 /** 136 * Create an instance of the specified Java content interface. 137 * 138 * @param javaContentInterface the Class object 139 * @return an instance of the Java content interface 140 * @exception JAXBException 141 */ 142 public Object newInstance( Class javaContentInterface ) 143 throws JAXBException { 144 145 if( javaContentInterface == null ) { 146 throw new JAXBException( Messages.format( Messages.CI_NOT_NULL ) ); 147 } 148 149 try { 150 Class c = gi.getDefaultImplementation( javaContentInterface ); 151 if(c==null) 152 throw new JAXBException( 153 Messages.format( Messages.MISSING_INTERFACE, javaContentInterface )); 154 155 return c.newInstance(); 156 } catch( Exception e ) { 157 throw new JAXBException( e ); 158 } 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 void setProperty( String name, Object value ) 166 throws PropertyException { 167 168 throw new PropertyException(name, value); 169 } 170 171 /** 172 * There are no required properties, so simply throw an exception. Other 173 * providers may have support for properties on Validator, but the RI doesn't 174 */ 175 public Object getProperty( String name ) 176 throws PropertyException { 177 178 throw new PropertyException(name); 179 } 180 181 182 }