1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import java.util.Hashtable ; 23 import java.util.StringTokenizer ; 24 import java.util.Vector ; 25 26 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType; 27 28 33 final class SymbolTable { 34 35 private final Hashtable _stylesheets = new Hashtable (); 37 private final Hashtable _primops = new Hashtable (); 38 39 private Hashtable _variables = null; 41 private Hashtable _templates = null; 42 private Hashtable _attributeSets = null; 43 private Hashtable _aliases = null; 44 private Hashtable _excludedURI = null; 45 private Hashtable _decimalFormats = null; 46 private Hashtable _keys = null; 47 48 public Key getKey(QName name) { 49 if (_keys == null) return null; 50 return (Key) _keys.get(name); 51 } 52 53 public void addKey(QName name, Key key) { 54 if (_keys == null) _keys = new Hashtable (); 55 _keys.put(name, key); 56 } 57 58 public DecimalFormatting getDecimalFormatting(QName name) { 59 if (_decimalFormats == null) return null; 60 return((DecimalFormatting)_decimalFormats.get(name)); 61 } 62 63 public void addDecimalFormatting(QName name, DecimalFormatting symbols) { 64 if (_decimalFormats == null) _decimalFormats = new Hashtable (); 65 _decimalFormats.put(name, symbols); 66 } 67 68 public Stylesheet addStylesheet(QName name, Stylesheet node) { 69 return (Stylesheet)_stylesheets.put(name, node); 70 } 71 72 public Stylesheet lookupStylesheet(QName name) { 73 return (Stylesheet)_stylesheets.get(name); 74 } 75 76 public Template addTemplate(Template template) { 77 final QName name = template.getName(); 78 if (_templates == null) _templates = new Hashtable (); 79 return (Template)_templates.put(name, template); 80 } 81 82 public Template lookupTemplate(QName name) { 83 if (_templates == null) return null; 84 return (Template)_templates.get(name); 85 } 86 87 public Variable addVariable(Variable variable) { 88 if (_variables == null) _variables = new Hashtable (); 89 final String name = variable.getName().getStringRep(); 90 return (Variable)_variables.put(name, variable); 91 } 92 93 public Param addParam(Param parameter) { 94 if (_variables == null) _variables = new Hashtable (); 95 final String name = parameter.getName().getStringRep(); 96 return (Param)_variables.put(name, parameter); 97 } 98 99 public Variable lookupVariable(QName qname) { 100 if (_variables == null) return null; 101 final String name = qname.getStringRep(); 102 final Object obj = _variables.get(name); 103 return obj instanceof Variable ? (Variable)obj : null; 104 } 105 106 public Param lookupParam(QName qname) { 107 if (_variables == null) return null; 108 final String name = qname.getStringRep(); 109 final Object obj = _variables.get(name); 110 return obj instanceof Param ? (Param)obj : null; 111 } 112 113 public SyntaxTreeNode lookupName(QName qname) { 114 if (_variables == null) return null; 115 final String name = qname.getStringRep(); 116 return (SyntaxTreeNode)_variables.get(name); 117 } 118 119 public AttributeSet addAttributeSet(AttributeSet atts) { 120 if (_attributeSets == null) _attributeSets = new Hashtable (); 121 return (AttributeSet)_attributeSets.put(atts.getName(), atts); 122 } 123 124 public AttributeSet lookupAttributeSet(QName name) { 125 if (_attributeSets == null) return null; 126 return (AttributeSet)_attributeSets.get(name); 127 } 128 129 134 public void addPrimop(String name, MethodType mtype) { 135 Vector methods = (Vector )_primops.get(name); 136 if (methods == null) { 137 _primops.put(name, methods = new Vector ()); 138 } 139 methods.addElement(mtype); 140 } 141 142 146 public Vector lookupPrimop(String name) { 147 return (Vector )_primops.get(name); 148 } 149 150 154 private int _nsCounter = 0; 155 156 public String generateNamespacePrefix() { 157 return(new String ("ns"+(_nsCounter++))); 158 } 159 160 163 private SyntaxTreeNode _current = null; 164 165 public void setCurrentNode(SyntaxTreeNode node) { 166 _current = node; 167 } 168 169 public String lookupNamespace(String prefix) { 170 if (_current == null) return(Constants.EMPTYSTRING); 171 return(_current.lookupNamespace(prefix)); 172 } 173 174 177 public void addPrefixAlias(String prefix, String alias) { 178 if (_aliases == null) _aliases = new Hashtable (); 179 _aliases.put(prefix,alias); 180 } 181 182 185 public String lookupPrefixAlias(String prefix) { 186 if (_aliases == null) return null; 187 return (String )_aliases.get(prefix); 188 } 189 190 194 public void excludeURI(String uri) { 195 if (uri == null) return; 197 198 if (_excludedURI == null) _excludedURI = new Hashtable (); 200 201 Integer refcnt = (Integer )_excludedURI.get(uri); 203 if (refcnt == null) 204 refcnt = new Integer (1); 205 else 206 refcnt = new Integer (refcnt.intValue() + 1); 207 _excludedURI.put(uri,refcnt); 208 } 209 210 214 public void excludeNamespaces(String prefixes) { 215 if (prefixes != null) { 216 StringTokenizer tokens = new StringTokenizer (prefixes); 217 while (tokens.hasMoreTokens()) { 218 final String prefix = tokens.nextToken(); 219 final String uri; 220 if (prefix.equals("#default")) 221 uri = lookupNamespace(Constants.EMPTYSTRING); 222 else 223 uri = lookupNamespace(prefix); 224 if (uri != null) excludeURI(uri); 225 } 226 } 227 } 228 229 232 public boolean isExcludedNamespace(String uri) { 233 if (uri != null && _excludedURI != null) { 234 final Integer refcnt = (Integer )_excludedURI.get(uri); 235 return (refcnt != null && refcnt.intValue() > 0); 236 } 237 return false; 238 } 239 240 243 public void unExcludeNamespaces(String prefixes) { 244 if (_excludedURI == null) return; 245 if (prefixes != null) { 246 StringTokenizer tokens = new StringTokenizer (prefixes); 247 while (tokens.hasMoreTokens()) { 248 final String prefix = tokens.nextToken(); 249 final String uri; 250 if (prefix.equals("#default")) 251 uri = lookupNamespace(Constants.EMPTYSTRING); 252 else 253 uri = lookupNamespace(prefix); 254 Integer refcnt = (Integer )_excludedURI.get(uri); 255 if (refcnt != null) 256 _excludedURI.put(uri, new Integer (refcnt.intValue() - 1)); 257 } 258 } 259 } 260 261 } 262 263 | Popular Tags |