All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.msv.reader.trex.RootState Maven / Gradle / Ivy

There is a newer version: 2.2.5.1
Show newest version
/*
 * @(#)$Id: RootState.java,v 1.17 2003/06/09 20:37:29 kk122374 Exp $
 *
 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * This software is the proprietary information of Sun Microsystems, Inc.  
 * Use is subject to license terms.
 * 
 */
package com.sun.msv.reader.trex;

import com.sun.msv.grammar.Expression;
import com.sun.msv.reader.State;
import com.sun.msv.util.StartTagInfo;

/**
 * invokes State object that parses the document element.
 * 
 * This class is used to parse the first grammar.
 * 
 * @author Kohsuke KAWAGUCHI
 */
public class RootState extends RootIncludedPatternState {
    
    public RootState() { super(null); }

    protected State createChildState( StartTagInfo tag ) {
        // grammar has to be treated separately so as not to
        // create unnecessary TREXGrammar object.
        if(tag.localName.equals("grammar"))
            return new GrammarState();
        
        State s = super.createChildState(tag);
        if(s!=null) {
            // other pattern element is specified.
            // create wrapper grammar
            final TREXBaseReader reader = (TREXBaseReader)this.reader;
            reader.grammar = reader.sfactory.createGrammar( reader.pool, null );
            simple = true;
        }
        
        return s;
    }
    
    /**
     * a flag that indicates 'grammar' element was not used.
     * In that case, this object is responsible to set start pattern.
     */
    private boolean simple = false;
        
    // GrammarState implements ExpressionState,
    // so RootState has to implement ExpressionOwner.
    public void onEndChild(Expression exp) {
        super.onEndChild(exp);

        final TREXBaseReader reader = (TREXBaseReader)this.reader;

        if( simple )
            // set the top-level expression if that is necessary.
            reader.grammar.exp = exp;
        
        // perform final wrap-up.
        reader.wrapUp();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy