⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smlnodeparsehandler.java

📁 Java游戏高级编程!!很不错的!!!Java游戏高级编程!!很不错的
💻 JAVA
字号:
     package com.croftsoft.core.text.sml;

     import java.util.*;

     /*********************************************************************
     * Constructs SmlNodes from parsed SML tokens.
     *
     * <p>
     * Java 1.1 compatible.
     * </p>
     *
     * @version
     *   2001-07-26
     * @since
     *   2001-05-10
     * @author
     *   <a href="http://www.alumni.caltech.edu/~croft/">David W. Croft</a>
     *********************************************************************/

     public final class  SmlNodeParseHandler
       implements SmlParseHandler
     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////
     {

     private boolean  allowMixedChildren;

     private SmlNode  smlNode;

     private Vector   stackVector;

     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////

     public  SmlNodeParseHandler ( boolean  allowMixedChildren )
     //////////////////////////////////////////////////////////////////////
     {
       this.allowMixedChildren = allowMixedChildren;

       stackVector = new Vector ( );
     }

     public  SmlNodeParseHandler ( )
     //////////////////////////////////////////////////////////////////////
     {
       this ( false );
     }

     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////

     public SmlNode  getSmlNode ( ) { return smlNode; }

     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////

     public void  handleCData ( String  cData )
     //////////////////////////////////////////////////////////////////////
     {
// System.out.println ( "handleCData(" + cData + ")" );

       if ( smlNode != null )
       {
         if ( allowMixedChildren
           || !smlNode.hasChild ( ) )
         {
           smlNode.add ( cData );
         }
       }
     }

     public void  handleElementOpen ( String  elementName )
     //////////////////////////////////////////////////////////////////////
     {
// System.out.println ( "handleElementOpen(" + elementName + ")" );

       SmlNode  smlNode = new SmlNode ( elementName );

       if ( this.smlNode != null )
       {
         if ( allowMixedChildren )
         {
           this.smlNode.add ( smlNode );
         }
         else
         {
           Object  firstChild = this.smlNode.getChild ( 0 );

           if ( firstChild instanceof String )
           {
             this.smlNode.getChildren ( ) [ 0 ] = smlNode;
           }
           else
           {
             this.smlNode.add ( smlNode );
           }
         }

         stackVector.addElement ( this.smlNode ); // stack push
       }
  
       this.smlNode = smlNode;
     }

     public void  handleElementClose ( String  elementName )
     //////////////////////////////////////////////////////////////////////
     {
// System.out.println ( "handleElementClose(" + elementName + ")" );

       int  index = stackVector.size ( ) - 1;

       if ( index > -1 )
       {
         this.smlNode = ( SmlNode ) stackVector.elementAt ( index );

         stackVector.removeElementAt ( index ); // stack pop
       }
     }

     public void  handleParseError ( )
     //////////////////////////////////////////////////////////////////////
     {
// System.out.println ( "handleParseError()" );

       throw new RuntimeException ( "bad SML stream" );
     }

     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////
     }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -