1 package com.icl.saxon.expr; 2 import com.icl.saxon.*; 3 import com.icl.saxon.om.*; 4 import com.icl.saxon.pattern.NameTest; 5 import com.icl.saxon.pattern.NamespaceTest; 6 7 import java.util.Hashtable ; 8 9 13 14 public class StandaloneContext implements StaticContext { 15 16 private NamePool namePool; 17 private Hashtable namespaces = new Hashtable (); 18 19 22 23 public StandaloneContext() { 24 this(NamePool.getDefaultNamePool()); 25 } 26 27 30 31 public StandaloneContext(NamePool pool) { 32 namePool = pool; 33 declareNamespace("xml", Namespace.XML); 34 declareNamespace("xsl", Namespace.XSLT); 35 declareNamespace("saxon", Namespace.SAXON); 36 declareNamespace("", ""); 37 } 38 39 42 43 public void declareNamespace(String prefix, String uri) { 44 namespaces.put(prefix, uri); 45 namePool.allocateNamespaceCode(prefix, uri); 46 } 47 48 49 52 53 public StaticContext makeRuntimeContext(NamePool pool) { 54 return null; 55 } 56 57 61 62 public String getSystemId() { 63 return ""; 64 } 65 66 72 73 public String getBaseURI() { 74 return ""; 75 } 76 77 81 82 public int getLineNumber() { 83 return -1; 84 } 85 86 91 92 public String getURIForPrefix(String prefix) throws XPathException { 93 String uri = (String )namespaces.get(prefix); 94 if (uri==null) { 95 throw new XPathException("Prefix " + prefix + " has not been declared"); 96 } 97 return uri; 98 } 99 100 107 108 public final int makeNameCode(String qname, boolean useDefault) throws XPathException { 109 String prefix = Name.getPrefix(qname); 110 String localName = Name.getLocalName(qname); 111 String uri; 112 if (prefix.equals("") && useDefault) { 113 uri = ""; 114 } else { 115 uri = getURIForPrefix(prefix); 116 } 117 return namePool.allocate(prefix, uri, localName); 118 } 119 120 128 129 public final int getFingerprint(String qname, boolean useDefault) throws XPathException { 130 String prefix = Name.getPrefix(qname); 131 String localName = Name.getLocalName(qname); 132 String uri; 133 if (prefix.equals("") && useDefault) { 134 uri = ""; 135 } else { 136 uri = getURIForPrefix(prefix); 137 } 138 return namePool.getFingerprint(uri, localName); 139 140 } 141 142 145 146 public NameTest makeNameTest(short nodeType, String qname, boolean useDefault) 147 throws XPathException { 148 return new NameTest(nodeType, makeNameCode(qname, useDefault)); 149 } 150 151 154 155 public NamespaceTest makeNamespaceTest(short nodeType, String prefix) 156 throws XPathException { 157 return new NamespaceTest(namePool, nodeType, getURICodeForPrefix(prefix)); 158 } 159 160 168 169 private short getURICodeForPrefix(String prefix) throws XPathException { 170 String uri = getURIForPrefix(prefix); 171 return namePool.getCodeForURI(uri); 172 } 173 174 177 178 public Binding bindVariable(int fingerprint) throws XPathException { 179 throw new XPathException("Variables are not allowed in a standalone expression"); 180 } 181 182 185 186 public boolean isExtensionNamespace(short uriCode) { 187 return false; 188 } 189 190 193 194 public boolean forwardsCompatibleModeIsEnabled() { 195 return false; 196 } 197 198 203 204 public Function getStyleSheetFunction(int fingerprint) throws XPathException { 205 return null; 206 } 207 208 215 216 public Class getExternalJavaClass(String uri) { 217 return null; 218 } 219 220 223 224 public boolean isElementAvailable(String qname) throws XPathException { 225 return false; 226 } 227 228 231 232 public boolean isFunctionAvailable(String qname) throws XPathException { 233 234 String prefix = Name.getPrefix(qname); 235 if (prefix.equals("")) { 236 return ExpressionParser.makeSystemFunction(qname)!=null; 237 } 238 239 return false; 241 247 } 248 249 252 253 public boolean allowsKeyFunction() { 254 return false; 255 } 256 257 260 261 public String getVersion() { 262 return "1.1"; 263 } 264 265 } 266 267 | Popular Tags |