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: AbstractGrammarInfoImpl.java,v 1.5 2003/05/14 18:36:17 lschwenk Exp $
015     */
016    package astronomy.data.spectra.impl.runtime;
017    
018    import java.io.InputStream;
019    import java.io.ObjectInputStream;
020    
021    import javax.xml.bind.JAXBException;
022    
023    import com.sun.msv.grammar.Grammar;
024    import com.sun.xml.bind.GrammarImpl;
025    import com.sun.xml.bind.Messages;
026    
027    /**
028     * Keeps the information about the grammar as a whole.
029     * 
030     * Implementation of this interface is provided by the generated code.
031     *
032     * @author
033     *  <a href="mailto:kohsuke.kawaguchi@sun.com>Kohsuke KAWAGUCHI</a>
034     */
035    public abstract class AbstractGrammarInfoImpl implements GrammarInfo
036    {
037        /**
038         * Creates an unmarshaller that can unmarshal a given element.
039         * 
040         * @param namespaceUri
041         *      The string needs to be interned by the caller
042         *      for a performance reason.
043         * @param localName
044         *      The string needs to be interned by the caller
045         *      for a performance reason.
046         * 
047         * @return
048         *      null if the given name pair is not recognized.
049         */
050        public abstract UnmarshallingEventHandler createUnmarshaller(
051            String namespaceUri, String localName, UnmarshallingContext context );
052        
053        /**
054         * Return the probe points for this GrammarInfo, which are used to detect 
055         * {namespaceURI,localName} collisions across the GrammarInfo's on the
056         * schemaPath.  This is a slightly more complex implementation than a simple
057         * hashmap, but it is more flexible in supporting additional schema langs.
058         */
059        public abstract String[] getProbePoints();
060        
061        /**
062         * Returns true if the invocation of the createUnmarshaller method
063         * will return a non-null value for the given name pair.
064         * 
065         * @param namespaceUri
066         *      The string needs to be interned by the caller
067         *      for a performance reason.
068         * @param localName
069         *      The string needs to be interned by the caller
070         *      for a performance reason.
071         */
072        public abstract boolean recognize( String nsUri, String localName );
073        
074        /**
075         * Gets the default implementation for the given public content
076         * interface. 
077         *
078         * @param javaContentInterface
079         *      the Class object of the public interface.
080         * 
081         * @return null
082         *      If the interface is not found.
083         */
084        public abstract Class getDefaultImplementation( Class javaContentInterface );
085        
086        /**
087         * Gets the MSV AGM which can be used to validate XML during
088         * marshalling/unmarshalling.
089         */
090        public Grammar getGrammar() throws JAXBException {
091            try {
092                InputStream is = this.getClass().getResourceAsStream("bgm.ser");
093                
094                if( is==null )
095                    // unable to find bgm.ser
096                    throw new JAXBException(
097                        Messages.format( Messages.NO_BGM,
098                                         this.getClass().getName().replace('.','/') ) );
099                        
100                
101                // deserialize the bgm
102                ObjectInputStream ois = new ObjectInputStream( is );
103                GrammarImpl g = (GrammarImpl)ois.readObject();
104                ois.close();
105                
106                g.connect(new Grammar[]{g});    // connect to itself
107                
108                return g;
109            } catch( Exception e ) {
110                throw new JAXBException( 
111                    Messages.format( Messages.UNABLE_TO_READ_BGM ), 
112                    e );
113            }
114        }
115    }