1 package com.sun.tools.xjc.runtime; 2 3 import javax.xml.bind.DatatypeConverter; 4 import javax.xml.bind.JAXBContext; 5 import javax.xml.bind.JAXBException; 6 import javax.xml.bind.Marshaller; 7 import javax.xml.bind.PropertyException; 8 import javax.xml.bind.Unmarshaller; 9 import javax.xml.bind.Validator; 10 11 import com.sun.xml.bind.Messages; 12 import com.sun.xml.bind.DatatypeConverterImpl; 13 14 21 public class DefaultJAXBContextImpl extends JAXBContext { 22 23 29 private GrammarInfo gi = null; 30 31 37 public DefaultJAXBContextImpl( String contextPath, ClassLoader classLoader ) 38 throws JAXBException { 39 40 this( GrammarInfoFacade.createGrammarInfoFacade( contextPath, classLoader ) ); 41 42 DatatypeConverter.setDatatypeConverter(DatatypeConverterImpl.theInstance); 44 } 45 46 51 public DefaultJAXBContextImpl( GrammarInfo gi ) { 52 this.gi = gi; 53 } 54 55 public GrammarInfo getGrammarInfo() { 56 return gi; 57 } 58 59 60 61 65 private com.sun.msv.grammar.Grammar grammar = null; 66 67 74 public synchronized com.sun.msv.grammar.Grammar getGrammar() throws JAXBException { 75 if( grammar==null ) 76 grammar = gi.getGrammar(); 77 return grammar; 78 } 79 81 82 90 public Marshaller createMarshaller() throws JAXBException { 91 if( MetaVariable.M ) { return new MarshallerImpl( this ); 93 } else { throw new UnsupportedOperationException ( 95 "When generating this code, the compiler option was specified not to generate the marshaller"); 96 } } 98 99 107 public Unmarshaller createUnmarshaller() throws JAXBException { 108 if( MetaVariable.U ) { return new UnmarshallerImpl( this, gi ); 110 } else { throw new UnsupportedOperationException ( 112 "When generating this code, the compiler option was specified not to generate the unmarshaller"); 113 } } 115 116 124 public Validator createValidator() throws JAXBException { 125 if( MetaVariable.V ) { return new ValidatorImpl( this ); 127 } else { throw new UnsupportedOperationException ( 129 "When generating this code, the compiler option was specified not to generate the validator"); 130 } } 132 133 134 135 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 165 public void setProperty( String name, Object value ) 166 throws PropertyException { 167 168 throw new PropertyException(name, value); 169 } 170 171 175 public Object getProperty( String name ) 176 throws PropertyException { 177 178 throw new PropertyException(name); 179 } 180 181 182 } 183 | Popular Tags |