home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML in Action / Dynamicke-HTML-v-akci-covermount.bin / XML / PARSER / XMLINST.EXE / classes / com / ms / xml / parser / Context.java < prev    next >
Encoding:
Java Source  |  1997-11-12  |  2.6 KB  |  132 lines

  1. /*
  2.  * @(#)Context.java 1.0 6/3/97
  3.  * 
  4.  * Copyright (c) 1997 Microsoft, Corp. All Rights Reserved.
  5.  * 
  6.  */
  7.  
  8. package com.ms.xml.parser;
  9.  
  10. import java.util.Hashtable;
  11. import com.ms.xml.om.Element;
  12. import com.ms.xml.util.Atom;
  13. import com.ms.xml.util.Name;
  14.  
  15. /**
  16.  * The class defines the context for an element currently being parsed
  17.  *
  18.  * @version 1.0, 6/3/97
  19.  */
  20. class Context
  21. {
  22.     /**
  23.      * current element - which may be null
  24.      */
  25.     Element e;
  26.     
  27.     /**
  28.      * current tag name
  29.      */
  30.     Name tagName;
  31.  
  32.     /**
  33.      * current element type
  34.      */
  35.     int type;
  36.  
  37.     /**
  38.      * current element declaration
  39.      */
  40.     ElementDecl ed;    
  41.  
  42.     /**
  43.      * a linked Context for proper validation of entities
  44.      * (see comment in Parser.addNewElement).
  45.      */
  46.     Context parent;
  47.  
  48.     /**
  49.      * state used in DFA to validate content
  50.      */
  51.     int state;
  52.     
  53.     /**
  54.      * set if content model pattern matched
  55.      */   
  56.     boolean matched;
  57.  
  58.     /**
  59.      * whether to preserve white space
  60.      */
  61.     boolean preserveWS;
  62.     boolean lastWasWS;
  63.  
  64.     /**
  65.      *    name space
  66.      */
  67.     Atom nameSpace;
  68.  
  69.     /**
  70.      *    default name space 
  71.      */
  72.     Atom defaultNameSpace;
  73.  
  74.     /**
  75.      *    Name space storage, index from long name to short name
  76.      */
  77.     Hashtable spaceTable;
  78.  
  79.     Context(Element e, Name name, int type, boolean preserveWS, Atom nameSpace, Hashtable spaceTable)
  80.     {
  81.         this.e = e;
  82.         this.tagName = name;
  83.         this.type = type;
  84.         this.preserveWS = preserveWS;
  85.         this.nameSpace = nameSpace;
  86.         this.defaultNameSpace = nameSpace;
  87.         this.lastWasWS = false;
  88.         if (spaceTable != null)
  89.             this.spaceTable =(Hashtable)spaceTable.clone();
  90.     }
  91.  
  92.     void reset(Element e, Name name, int type, boolean preserveWS, Atom nameSpace, Hashtable spaceTable)
  93.     {
  94.         this.ed = null;    
  95.         this.tagName = name;
  96.         this.parent = null;
  97.         this.type = type;
  98.         this.state = 0;
  99.         this.e = e;
  100.         this.preserveWS = preserveWS;
  101.         this.nameSpace = nameSpace;
  102.         this.defaultNameSpace = nameSpace;
  103.         this.lastWasWS = false;
  104.         if (spaceTable != null)
  105.             this.spaceTable =(Hashtable)spaceTable.clone();
  106.         else
  107.             spaceTable = null;
  108.     }
  109.  
  110.     /**
  111.      *    add name space. short name is the key
  112.      */
  113.     final void addNameSpace(Atom n, Atom url)
  114.     {
  115.         if (spaceTable == null)
  116.         {
  117.             spaceTable = new Hashtable();
  118.         }
  119.         spaceTable.put(n, url);
  120.     }
  121.  
  122.     /**
  123.      * find name space, short name is the key
  124.      */
  125.     final Atom findNameSpace(Atom n)
  126.     {
  127.         if (n == null) return null;
  128.         return spaceTable == null ? null : (Atom)spaceTable.get(n);
  129.     }
  130.  
  131.  }
  132.