1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import java.util.Hashtable ; 23 import java.util.StringTokenizer ; 24 import java.util.Vector ; 25 26 import org.apache.xalan.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 47 public DecimalFormatting getDecimalFormatting(QName name) { 48 if (_decimalFormats == null) return null; 49 return((DecimalFormatting)_decimalFormats.get(name)); 50 } 51 52 public void addDecimalFormatting(QName name, DecimalFormatting symbols) { 53 if (_decimalFormats == null) _decimalFormats = new Hashtable (); 54 _decimalFormats.put(name, symbols); 55 } 56 57 public Stylesheet addStylesheet(QName name, Stylesheet node) { 58 return (Stylesheet)_stylesheets.put(name, node); 59 } 60 61 public Stylesheet lookupStylesheet(QName name) { 62 return (Stylesheet)_stylesheets.get(name); 63 } 64 65 public Template addTemplate(Template template) { 66 final QName name = template.getName(); 67 if (_templates == null) _templates = new Hashtable (); 68 return (Template)_templates.put(name, template); 69 } 70 71 public Template lookupTemplate(QName name) { 72 if (_templates == null) return null; 73 return (Template)_templates.get(name); 74 } 75 76 public Variable addVariable(Variable variable) { 77 if (_variables == null) _variables = new Hashtable (); 78 final String name = variable.getName().getStringRep(); 79 return (Variable)_variables.put(name, variable); 80 } 81 82 public Param addParam(Param parameter) { 83 if (_variables == null) _variables = new Hashtable (); 84 final String name = parameter.getName().getStringRep(); 85 return (Param)_variables.put(name, parameter); 86 } 87 88 public Variable lookupVariable(QName qname) { 89 if (_variables == null) return null; 90 final String name = qname.getStringRep(); 91 final Object obj = _variables.get(name); 92 return obj instanceof Variable ? (Variable)obj : null; 93 } 94 95 public Param lookupParam(QName qname) { 96 if (_variables == null) return null; 97 final String name = qname.getStringRep(); 98 final Object obj = _variables.get(name); 99 return obj instanceof Param ? (Param)obj : null; 100 } 101 102 public SyntaxTreeNode lookupName(QName qname) { 103 if (_variables == null) return null; 104 final String name = qname.getStringRep(); 105 return (SyntaxTreeNode)_variables.get(name); 106 } 107 108 public AttributeSet addAttributeSet(AttributeSet atts) { 109 if (_attributeSets == null) _attributeSets = new Hashtable (); 110 return (AttributeSet)_attributeSets.put(atts.getName(), atts); 111 } 112 113 public AttributeSet lookupAttributeSet(QName name) { 114 if (_attributeSets == null) return null; 115 return (AttributeSet)_attributeSets.get(name); 116 } 117 118 123 public void addPrimop(String name, MethodType mtype) { 124 Vector methods = (Vector )_primops.get(name); 125 if (methods == null) { 126 _primops.put(name, methods = new Vector ()); 127 } 128 methods.addElement(mtype); 129 } 130 131 135 public Vector lookupPrimop(String name) { 136 return (Vector )_primops.get(name); 137 } 138 139 143 private int _nsCounter = 0; 144 145 public String generateNamespacePrefix() { 146 return(new String ("ns"+(_nsCounter++))); 147 } 148 149 152 private SyntaxTreeNode _current = null; 153 154 public void setCurrentNode(SyntaxTreeNode node) { 155 _current = node; 156 } 157 158 public String lookupNamespace(String prefix) { 159 if (_current == null) return(Constants.EMPTYSTRING); 160 return(_current.lookupNamespace(prefix)); 161 } 162 163 166 public void addPrefixAlias(String prefix, String alias) { 167 if (_aliases == null) _aliases = new Hashtable (); 168 _aliases.put(prefix,alias); 169 } 170 171 174 public String lookupPrefixAlias(String prefix) { 175 if (_aliases == null) return null; 176 return (String )_aliases.get(prefix); 177 } 178 179 183 public void excludeURI(String uri) { 184 if (uri == null) return; 186 187 if (_excludedURI == null) _excludedURI = new Hashtable (); 189 190 Integer refcnt = (Integer )_excludedURI.get(uri); 192 if (refcnt == null) 193 refcnt = new Integer (1); 194 else 195 refcnt = new Integer (refcnt.intValue() + 1); 196 _excludedURI.put(uri,refcnt); 197 } 198 199 203 public void excludeNamespaces(String prefixes) { 204 if (prefixes != null) { 205 StringTokenizer tokens = new StringTokenizer (prefixes); 206 while (tokens.hasMoreTokens()) { 207 final String prefix = tokens.nextToken(); 208 final String uri; 209 if (prefix.equals("#default")) 210 uri = lookupNamespace(Constants.EMPTYSTRING); 211 else 212 uri = lookupNamespace(prefix); 213 if (uri != null) excludeURI(uri); 214 } 215 } 216 } 217 218 221 public boolean isExcludedNamespace(String uri) { 222 if (uri != null && _excludedURI != null) { 223 final Integer refcnt = (Integer )_excludedURI.get(uri); 224 return (refcnt != null && refcnt.intValue() > 0); 225 } 226 return false; 227 } 228 229 232 public void unExcludeNamespaces(String prefixes) { 233 if (_excludedURI == null) return; 234 if (prefixes != null) { 235 StringTokenizer tokens = new StringTokenizer (prefixes); 236 while (tokens.hasMoreTokens()) { 237 final String prefix = tokens.nextToken(); 238 final String uri; 239 if (prefix.equals("#default")) 240 uri = lookupNamespace(Constants.EMPTYSTRING); 241 else 242 uri = lookupNamespace(prefix); 243 Integer refcnt = (Integer )_excludedURI.get(uri); 244 if (refcnt != null) 245 _excludedURI.put(uri, new Integer (refcnt.intValue() - 1)); 246 } 247 } 248 } 249 250 } 251 252 | Popular Tags |