1 package net.sf.saxon.query; 2 3 import net.sf.saxon.Configuration; 4 import net.sf.saxon.event.Builder; 5 import net.sf.saxon.event.Stripper; 6 import net.sf.saxon.expr.StaticContext; 7 import net.sf.saxon.expr.VariableDeclaration; 8 import net.sf.saxon.expr.VariableReference; 9 import net.sf.saxon.expr.ExpressionLocation; 10 import net.sf.saxon.functions.ConstructorFunctionLibrary; 11 import net.sf.saxon.functions.FunctionLibrary; 12 import net.sf.saxon.functions.FunctionLibraryList; 13 import net.sf.saxon.functions.SystemFunctionLibrary; 14 import net.sf.saxon.instruct.*; 15 import net.sf.saxon.om.*; 16 import net.sf.saxon.sort.CodepointCollator; 17 import net.sf.saxon.trans.StaticError; 18 import net.sf.saxon.trans.XPathException; 19 import net.sf.saxon.type.AtomicType; 20 import net.sf.saxon.type.SchemaType; 21 import org.xml.sax.SAXParseException ; 22 23 import javax.xml.transform.Source ; 24 import javax.xml.transform.SourceLocator ; 25 import javax.xml.transform.TransformerException ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.io.Reader ; 29 import java.util.*; 30 31 55 56 public class StaticQueryContext implements StaticContext { 57 58 private Configuration config; 59 private NamePool namePool; 60 private String locationURI; 61 private String moduleNamespace; 62 private String baseURI; 63 private HashMap passiveNamespaces; 64 private HashSet explicitPrologNamespaces; 65 private Stack activeNamespaces; 66 private boolean inheritNamespaces = true; 67 private boolean preserveNamespaces = true; 68 private HashMap collations; 69 private HashMap variables; 70 private List variableList; private HashSet importedSchemata; 72 private String defaultCollationName; 73 private String defaultFunctionNamespace; 74 private short defaultElementNamespace; 75 private SlotManager stackFrameMap; private short moduleNamespaceURICode; 77 private int constructionMode; 78 private Executable executable; 79 private StaticQueryContext importer; 80 private FunctionLibraryList functionLibraryList; 81 private XQueryFunctionLibrary functions; 82 private Set importedModuleNamespaces; 83 84 private StaticQueryContext() { 85 } 86 87 92 93 public StaticQueryContext(Configuration config) { 94 this.config = config; 95 this.namePool = config.getNamePool(); 96 reset(); 97 } 98 99 104 105 public void reset() { 106 passiveNamespaces = new HashMap(10); 107 explicitPrologNamespaces = new HashSet(10); 108 activeNamespaces = new Stack(); 109 collations = new HashMap(5); 110 variables = new HashMap(40); 111 variableList = new ArrayList(40); 112 functions = new XQueryFunctionLibrary(config, true); 113 importedSchemata = new HashSet(5); 114 importedModuleNamespaces = new HashSet(5); 115 defaultFunctionNamespace = NamespaceConstant.FN; 116 defaultElementNamespace = NamespaceConstant.NULL_CODE; 117 moduleNamespace = null; 118 moduleNamespaceURICode = 0; 119 constructionMode = Validation.PRESERVE; 120 121 defaultCollationName = NamespaceConstant.CODEPOINT_COLLATION_URI; 125 declareCollation(defaultCollationName, CodepointCollator.getInstance()); 126 functionLibraryList = new FunctionLibraryList(); 127 functionLibraryList.addFunctionLibrary(new SystemFunctionLibrary(SystemFunctionLibrary.XPATH_ONLY)); 128 functionLibraryList.addFunctionLibrary(config.getVendorFunctionLibrary()); 129 functionLibraryList.addFunctionLibrary(new ConstructorFunctionLibrary(config)); 130 if (config.isAllowExternalFunctions()) { 131 functionLibraryList.addFunctionLibrary(config.getExtensionBinder()); 132 } 133 functionLibraryList.addFunctionLibrary(functions); 134 135 clearPassiveNamespaces(); 136 } 137 138 142 143 public StaticQueryContext getImporter() { 144 return importer; 145 } 146 147 150 151 public void addImportedNamespace(String uri) { 152 if (importedModuleNamespaces == null) { 153 importedModuleNamespaces = new HashSet(5); 154 } 155 importedModuleNamespaces.add(uri); 156 } 157 158 161 162 public boolean importsNamespace(String uri) { 163 return importedModuleNamespaces != null && 164 importedModuleNamespaces.contains(uri); 165 } 166 167 170 171 public Iterator iterateImportedNamespaces() { 172 if (importedModuleNamespaces == null) { 173 return Collections.EMPTY_LIST.iterator(); 174 } 175 return importedModuleNamespaces.iterator(); 176 } 177 178 186 187 public StaticQueryContext copy() { 188 StaticQueryContext n = new StaticQueryContext(); 189 n.config = config; 190 n.namePool = namePool; 191 n.passiveNamespaces = new HashMap(passiveNamespaces); 192 n.explicitPrologNamespaces = new HashSet(explicitPrologNamespaces); 193 n.activeNamespaces = new Stack(); 194 n.inheritNamespaces = inheritNamespaces; 195 n.preserveNamespaces = preserveNamespaces; 196 n.collations = new HashMap(collations); 197 n.variables = new HashMap(variables); 198 n.variableList = new ArrayList(variableList); 199 n.importedSchemata = new HashSet(importedSchemata); 200 n.defaultCollationName = defaultCollationName; 201 n.defaultFunctionNamespace = defaultFunctionNamespace; 202 n.defaultElementNamespace = defaultElementNamespace; 203 n.locationURI = locationURI; 204 n.baseURI = baseURI; 205 n.stackFrameMap = stackFrameMap; 206 n.moduleNamespace = moduleNamespace; 207 n.moduleNamespaceURICode = moduleNamespaceURICode; 208 n.constructionMode = constructionMode; 209 n.executable = executable; 210 n.importer = importer; 211 n.functionLibraryList = (FunctionLibraryList)functionLibraryList.copy(); 212 List list = n.functionLibraryList.getLibraryList(); 213 for (int i = 0; i < list.size(); i++) { 214 if (list.get(i) instanceof XQueryFunctionLibrary) { 215 n.functions = (XQueryFunctionLibrary)list.get(i); 216 break; 217 } 218 } 219 return n; 220 } 221 222 231 232 public void setConfiguration(Configuration config) { 233 if (this.config != config) { 234 throw new IllegalArgumentException ("Configuration cannot be changed dynamically"); 235 } 236 this.config = config; 237 } 238 239 244 245 public Configuration getConfiguration() { 246 return config; 247 } 248 249 264 265 public DocumentInfo buildDocument(Source source) throws XPathException { 266 Source s2 = config.getSourceResolver().resolveSource(source, config); 268 if (s2 != null) { 269 source = s2; 270 } 271 Stripper stripper = null; 272 if (config.isStripsAllWhiteSpace()) { 273 stripper = AllElementStripper.getInstance(); 274 stripper.setStripAll(); 275 } 276 try { 277 NodeInfo contextNode = Builder.build(source, stripper, config); 278 return contextNode.getDocumentRoot(); 279 } catch (XPathException err) { 280 Throwable cause = err.getException(); 281 if (cause != null && cause instanceof SAXParseException ) { 282 SAXParseException spe = (SAXParseException )cause; 287 cause = spe.getException(); 288 if (cause instanceof RuntimeException ) { 289 try { 290 config.getErrorListener().fatalError(err); 291 } catch (TransformerException e) { 292 } 294 } 295 } else { 296 while (err.getException() instanceof XPathException) { 297 err = (XPathException)err.getException(); 298 } 299 try { 300 config.getErrorListener().fatalError(err); 301 } catch (TransformerException e) { 302 } 304 } 305 throw err; 306 } 307 } 308 309 322 323 public XQueryExpression compileQuery(String query) throws XPathException { 324 QueryParser qp = new QueryParser(); 325 XQueryExpression queryExp = qp.makeXQueryExpression(query, copy(), config); 326 return queryExp; 327 } 328 329 342 343 public XQueryExpression compileQuery(Reader source) 344 throws XPathException, IOException { 345 char[] buffer = new char[4096]; 346 StringBuffer sb = new StringBuffer (4096); 347 while (true) { 348 int n = source.read(buffer); 349 if (n > 0) { 350 sb.append(buffer, 0, n); 351 } else { 352 break; 353 } 354 } 355 return compileQuery(sb.toString()); 356 } 357 358 379 380 public XQueryExpression compileQuery(InputStream source, String encoding) 381 throws XPathException, IOException { 382 String query = QueryReader.readInputStream(source, encoding); 383 return compileQuery(query); 384 } 385 386 393 394 public Executable getExecutable() { 395 return executable; 396 } 397 398 405 406 public void setExecutable(Executable executable) { 407 this.executable = executable; 408 } 409 410 418 419 public LocationMap getLocationMap() { 420 return executable.getLocationMap(); 421 } 422 423 435 436 public void declarePassiveNamespace(String prefix, String uri, boolean explicit) throws StaticError { 437 if (prefix == null) { 438 throw new NullPointerException ("Null prefix supplied to declarePassiveNamespace()"); 439 } 440 if (uri == null) { 441 throw new NullPointerException ("Null namespace URI supplied to declarePassiveNamespace()"); 442 } 443 if (explicit) { 444 if (explicitPrologNamespaces.contains(prefix)) { 445 StaticError err = new StaticError("Duplicate declaration of namespace prefix \"" + prefix + '"'); 446 err.setErrorCode("XQST0033"); 447 throw err; 448 } 449 explicitPrologNamespaces.add(prefix); 450 } 451 passiveNamespaces.put(prefix, uri); 452 namePool.allocateNamespaceCode(prefix, uri); 453 } 454 455 464 465 public void declareActiveNamespace(String prefix, String uri) { 466 if (prefix == null) { 467 throw new NullPointerException ("Null prefix supplied to declareActiveNamespace()"); 468 } 469 if (uri == null) { 470 throw new NullPointerException ("Null namespace URI supplied to declareActiveNamespace()"); 471 } 472 473 int nscode = namePool.allocateNamespaceCode(prefix, uri); 474 ActiveNamespace entry = new ActiveNamespace(); 475 entry.prefix = prefix; 476 entry.uri = uri; 477 entry.code = nscode; 478 activeNamespaces.push(entry); 479 480 if (prefix.equals("")) { 481 defaultElementNamespace = (short)(nscode & 0xffff); 482 } 483 484 } 485 486 495 496 public void undeclareNamespace() { 497 ActiveNamespace entry = (ActiveNamespace)activeNamespaces.pop(); 498 if (entry.prefix.equals("")) { 499 for (int i = activeNamespaces.size() - 1; i >= 0; i--) { 500 if (((ActiveNamespace)activeNamespaces.get(i)).prefix.equals("")) { 501 defaultElementNamespace = (short)(((ActiveNamespace)activeNamespaces.get(i)).code & 0xffff); 502 return; 503 } 504 } 505 String defaultNS = (String )passiveNamespaces.get(""); 506 if ("".equals(defaultNS)) { 507 defaultElementNamespace = NamespaceConstant.NULL_CODE; 508 } else { 509 defaultElementNamespace = getNamePool().getCodeForURI(defaultNS); 510 } 511 } 512 } 513 514 519 520 public void clearPassiveNamespaces() { 521 try { 522 if (passiveNamespaces != null) { 523 passiveNamespaces.clear(); 524 declarePassiveNamespace("xml", NamespaceConstant.XML, false); 525 declarePassiveNamespace("saxon", NamespaceConstant.SAXON, false); 526 declarePassiveNamespace("xs", NamespaceConstant.SCHEMA, false); 527 declarePassiveNamespace("fn", NamespaceConstant.FN, false); 528 declarePassiveNamespace("xdt", NamespaceConstant.XDT, false); 529 declarePassiveNamespace("xsi", NamespaceConstant.SCHEMA_INSTANCE, false); 530 declarePassiveNamespace("local", NamespaceConstant.LOCAL, false); 531 declarePassiveNamespace("", "", false); 532 } 533 } catch (StaticError staticError) { 534 throw new IllegalStateException ("Internal Failure initializing namespace declarations"); 536 } 537 } 538 539 550 551 public String getURIForPrefix(String prefix) throws XPathException { 552 String uri = checkURIForPrefix(prefix); 553 if (uri == null) { 554 throw new StaticError("Prefix " + prefix + " has not been declared"); 555 } 556 return uri; 557 } 558 559 570 571 public String checkURIForPrefix(String prefix) { 572 for (int i = activeNamespaces.size() - 1; i >= 0; i--) { 574 if (((ActiveNamespace)activeNamespaces.get(i)).prefix.equals(prefix)) { 575 return ((ActiveNamespace)activeNamespaces.get(i)).uri; 576 } 577 } 578 return (String )passiveNamespaces.get(prefix); 579 } 580 581 587 588 public int[] getActiveNamespaceCodes() { 589 int[] nscodes = new int[activeNamespaces.size()]; 590 int used = 0; 591 HashSet prefixes = new HashSet(10); 592 for (int n = activeNamespaces.size() - 1; n >= 0; n--) { 593 ActiveNamespace an = (ActiveNamespace)activeNamespaces.get(n); 594 if (!prefixes.contains(an.prefix)) { 595 prefixes.add(an.prefix); 596 nscodes[used++] = an.code; 597 } 598 } 599 if (used < nscodes.length) { 600 int[] nscodes2 = new int[used]; 601 System.arraycopy(nscodes, 0, nscodes2, 0, used); 602 nscodes = nscodes2; 603 } 604 return nscodes; 605 } 606 607 614 615 public NamespaceResolver getNamespaceResolver() { 616 int[] active = getActiveNamespaceCodes(); 617 int[] nscodes = new int[passiveNamespaces.size() + active.length]; 618 619 int used = 0; 620 for (Iterator iter = passiveNamespaces.keySet().iterator(); iter.hasNext();) { 621 String prefix = (String )iter.next(); 622 String uri = (String )passiveNamespaces.get(prefix); 623 nscodes[used++] = namePool.getNamespaceCode(prefix, uri); 624 ; 625 } 626 for (int a = 0; a < active.length; a++) { 627 nscodes[used++] = active[a]; 628 } 629 630 return new SavedNamespaceContext(nscodes, namePool); 631 } 632 633 639 640 public String getDefaultFunctionNamespace() { 641 return defaultFunctionNamespace; 642 } 643 644 650 651 public void setDefaultFunctionNamespace(String defaultFunctionNamespace) { 652 this.defaultFunctionNamespace = defaultFunctionNamespace; 653 } 654 655 660 661 public void setDefaultElementNamespace(String uri) throws StaticError { 662 int nscode = namePool.allocateNamespaceCode("", uri); 663 defaultElementNamespace = (short)(nscode & 0xffff); 664 declarePassiveNamespace("", uri, true); 665 } 666 667 672 673 public short getDefaultElementNamespace() { 674 return defaultElementNamespace; 675 } 676 677 682 683 public void setModuleNamespace(String uri) { 684 moduleNamespace = uri; 685 moduleNamespaceURICode = namePool.getCodeForURI(uri); 686 } 687 688 695 696 public String getModuleNamespace() { 697 return moduleNamespace; 698 } 699 700 707 708 public short getModuleNamespaceCode() { 709 return moduleNamespaceURICode; 710 } 711 712 715 716 public void setLocationURI(String uri) { 717 locationURI = uri; 718 } 719 720 723 724 public String getLocationURI() { 725 return locationURI; 726 } 727 728 734 735 public void setInheritNamespaces(boolean inherit) { 736 inheritNamespaces = inherit; 737 } 738 739 745 746 public boolean isInheritNamespaces() { 747 return inheritNamespaces; 748 } 749 750 756 757 public void setPreserveNamespaces(boolean inherit) { 758 preserveNamespaces = inherit; 759 } 760 761 767 768 public boolean isPreserveNamespaces() { 769 return preserveNamespaces; 770 } 771 772 782 783 public void declareCollation(String name, Comparator comparator) { 784 collations.put(name, comparator); 785 } 786 787 795 796 public void declareDefaultCollation(String name) throws XPathException { 797 Comparator c = getCollation(name); 798 if (c == null) { 799 throw new StaticError("Collation " + name + " is not recognized"); 800 } 801 defaultCollationName = name; 802 } 803 804 811 812 public Comparator getCollation(String name) { 813 Comparator c = (Comparator)collations.get(name); 814 if (c != null) { 815 return c; 816 } 817 return config.getCollationURIResolver().resolve(name, getBaseURI(), config); 818 } 820 821 828 829 public String getDefaultCollationName() { 830 if (defaultCollationName != null) { 831 return defaultCollationName; 832 } else { 833 return NamespaceConstant.CODEPOINT_COLLATION_URI; 834 } 835 } 836 837 844 845 public HashMap getAllCollations() { 846 return new HashMap(collations); 847 } 848 849 854 855 public SlotManager getGlobalStackFrameMap() { 856 return executable.getGlobalVariableMap(); 857 } 858 859 866 867 public void declareVariable(VariableDeclaration var) throws StaticError { 868 int key = var.getNameCode() & NamePool.FP_MASK; 869 Integer keyObj = new Integer (key); 870 if (variables.get(keyObj) != null) { 871 GlobalVariableDefinition old = (GlobalVariableDefinition)variables.get(keyObj); 872 if (old instanceof UndeclaredVariable) { 873 UndeclaredVariable u = (UndeclaredVariable)old; 878 if (((GlobalVariableDefinition)var).getSystemId().equals(u.getSystemId())) { 879 StaticError err = new StaticError("Forwards reference to global variable " + var.getVariableName()); 880 err.setErrorCode("XPST0008"); 881 throw err; 882 } 883 u.transferReferences(var); 884 variableList.remove(old); 885 } else if (old == var) { 886 } else { 888 StaticError err = new StaticError("Duplicate definition of global variable " 889 + var.getVariableName() 890 + " (see line " + old.getLineNumber() + " in module " + old.getSystemId() + ')'); 891 err.setErrorCode("XQST0049"); 892 if (var instanceof GlobalVariableDefinition) { 893 ExpressionLocation loc = new ExpressionLocation(); 894 loc.setLineNumber(((GlobalVariableDefinition)var).getLineNumber()); 895 loc.setSystemId(((GlobalVariableDefinition)var).getSystemId()); 896 err.setLocator(loc); 897 } 898 throw err; 899 } 900 } 901 variables.put(keyObj, var); 902 variableList.add(var); 903 } 907 908 913 914 public List fixupGlobalVariables(SlotManager globalVariableMap) throws StaticError { 915 List compiledVars = new ArrayList(20); 916 Iterator iter = variableList.iterator(); 917 while (iter.hasNext()) { 918 GlobalVariableDefinition var = (GlobalVariableDefinition)iter.next(); 919 if (var instanceof UndeclaredVariable) { 920 Iterator refs = var.iterateReferences(); 921 while (refs.hasNext()) { 922 VariableReference ref = (VariableReference)refs.next(); 923 StaticError err = new StaticError("Unresolved reference to variable " + var.getVariableName()); 924 err.setLocator(ref); 925 err.setErrorCode("XPST0008"); 926 throw err; 927 } 929 } else { 931 try { 932 int slot = globalVariableMap.allocateSlotNumber(var.getNameCode() & NamePool.FP_MASK); 933 GlobalVariable gv = var.compile(this, slot); 934 compiledVars.add(gv); 935 } catch (XPathException err) { 936 throw StaticError.makeStaticError(err); 937 } 938 } 939 } 940 return compiledVars; 941 } 942 943 public void typeCheckGlobalVariables(List compiledVars) throws StaticError { 944 try { 945 Iterator iter = compiledVars.iterator(); 946 Stack stack = new Stack(); 947 while (iter.hasNext()) { 948 GlobalVariable gv = (GlobalVariable)iter.next(); 949 gv.lookForCycles(stack); 950 GlobalVariableDefinition.typeCheck(this, gv); 951 } 952 } catch (XPathException e) { 953 throw StaticError.makeStaticError(e); 954 } 955 } 956 957 962 963 public void explainGlobalVariables() { 964 Iterator iter = variableList.iterator(); 965 while (iter.hasNext()) { 966 GlobalVariableDefinition var = (GlobalVariableDefinition)iter.next(); 967 var.explain(getNamePool()); 968 } 969 } 970 971 981 982 public Iterator getVariableDeclarations() { 983 return variableList.iterator(); 984 } 985 986 991 992 public SlotManager getStackFrameMap() { 993 if (stackFrameMap == null) { 994 stackFrameMap = getConfiguration().makeSlotManager(); 995 } 996 return stackFrameMap; 997 } 998 999 1004 1005 public NamePool getNamePool() { 1006 return namePool; 1007 } 1008 1009 1015 1016 public void issueWarning(String s, SourceLocator locator) { 1017 StaticError err = new StaticError(s); 1018 err.setLocator(locator); 1019 try { 1020 config.getErrorListener().warning(err); 1021 } catch (TransformerException e) { 1022 } 1024 } 1025 1026 1031 1032 public void setBaseURI(String baseURI) { 1033 this.baseURI = baseURI; 1034 } 1035 1036 1044 1045 public String getSystemId() { 1046 return baseURI; 1047 } 1048 1049 1059 1060 public String getBaseURI() { 1061 return baseURI; 1062 } 1063 1064 1071 1072 public int getLineNumber() { 1073 return -1; 1074 } 1075 1076 1077 1084 1085 public VariableDeclaration bindVariable(int fingerprint) throws StaticError { 1086 1087 VariableDeclaration var = (VariableDeclaration)variables.get(new Integer (fingerprint)); 1088 if (var == null) { 1089 UndeclaredVariable uvar = new UndeclaredVariable(); 1090 uvar.setSystemId(getLocationURI()); 1091 uvar.setLineNumber(getLineNumber()); 1092 uvar.setNameCode(fingerprint); 1093 uvar.setVariableName(getNamePool().getDisplayName(fingerprint)); 1094 declareVariable(uvar); 1095 return uvar; 1096 } 1097 return var; 1098 } 1099 1100 1114 1115 public void setFunctionLibraryList(FunctionLibraryList functionLibrary) { 1116 this.functionLibraryList = functionLibrary; 1117 } 1118 1119 1129 1130 public FunctionLibrary getFunctionLibrary() { 1131 return functionLibraryList; 1132 } 1133 1134 1139 1140 public void declareFunction(XQueryFunction function) throws StaticError { 1141 if (function.getNumberOfArguments() == 1) { 1142 SchemaType t = config.getSchemaType(function.getNameCode() & NamePool.FP_MASK); 1143 if (t != null && t instanceof AtomicType) { 1144 StaticError err = new StaticError("Function name " + function.getFunctionDisplayName(getNamePool()) + 1145 " clashes with the name of the constructor function for an atomic type"); 1146 err.setErrorCode("XQST0034"); 1147 throw err; 1148 } 1149 } 1150 functions.declareFunction(function); 1151 } 1152 1153 1163 1164 public void bindUnboundFunctionCalls() throws StaticError { 1165 functions.bindUnboundFunctionCalls(); 1166 } 1167 1168 1177 1178 public Iterator getFunctionDefinitions() { 1179 return functions.getFunctionDefinitions(); 1180 } 1181 1182 1190 1191 public void fixupGlobalFunctions() throws XPathException { 1192 functions.fixupGlobalFunctions(this); 1193 } 1194 1195 1200 1201 public void explainGlobalFunctions() throws XPathException { 1202 functions.explainGlobalFunctions(); 1203 } 1204 1205 1216 1217 public UserFunction getUserDefinedFunction(String uri, String localName, int arity) { 1218 return functions.getUserDefinedFunction(uri, localName, arity); 1219 } 1220 1221 1227 1228 public boolean isInBackwardsCompatibleMode() { 1229 return false; 1230 } 1231 1232 1243 1244 public void addImportedSchema(String targetNamespace) { 1245 if (importedSchemata == null) { 1246 importedSchemata = new HashSet(5); 1247 } 1248 importedSchemata.add(targetNamespace); 1249 } 1250 1251 1259 1260 public boolean isImportedSchema(String namespace) { 1261 if (importedSchemata == null) { 1262 return false; 1263 } 1264 return importedSchemata.contains(namespace); 1265 } 1266 1267 1275 1276 public boolean isAllowedBuiltInType(AtomicType type) { 1277 return true; 1278 } 1279 1280 1286 1287 public void setConstructionMode(int mode) { 1288 constructionMode = mode; 1289 } 1290 1291 1297 1298 public int getConstructionMode() { 1299 return constructionMode; 1300 } 1301 1302 1316 1317 public static StaticQueryContext makeStaticQueryContext( 1318 String baseURI, Executable executable, StaticQueryContext importer, 1319 String query, String namespaceURI) throws StaticError { 1320 Configuration config = executable.getConfiguration(); 1321 StaticQueryContext module = new StaticQueryContext(config); 1322 module.setLocationURI(baseURI); 1323 module.setBaseURI(baseURI); 1324 module.setModuleNamespace(namespaceURI); 1325 module.setExecutable(executable); 1326 module.importer = importer; 1327 executable.addQueryLibraryModule(module); 1328 QueryParser qp = new QueryParser(); 1329 qp.parseLibraryModule(query, module); 1330 if (module.getModuleNamespace() == null) { 1331 throw new StaticError("Imported module must be a library module"); 1332 } 1333 if (!module.getModuleNamespace().equals(namespaceURI)) { 1334 throw new StaticError("Imported module's namespace does not match requested namespace"); 1335 } 1336 1337 return module; 1338 } 1339 1340 1343 1344 private static class ActiveNamespace { 1345 public String prefix; 1346 public String uri; 1347 public int code; 1348 } 1349 1350} 1351 1352 | Popular Tags |