main.bindUnboundVariables(); env.bindUnboundVariables(); List<GlobalVariable> varDefinitions = main.fixupGlobalVariables(main.getGlobalStackFrameMap() /*, contextItemVar */); main.bindUnboundFunctionCalls(); env.bindUnboundFunctionCalls(); main.checkForCircularities(varDefinitions, main.getGlobalFunctionLibrary()); main.fixupGlobalFunctions(); main.typeCheckGlobalVariables(varDefinitions); main.optimizeGlobalFunctions();
XQueryExpression saxonQuery = xquery.getUnderlyingCompiledQuery(); queryModule = saxonQuery.getStaticContext(); Iterator<?> moduleIter = queryModule.getExecutable().getQueryLibraryModules(); ArrayList<ModuleImport> importedModules = new ArrayList<ModuleImport>(); while (moduleIter.hasNext()) { QueryModule importedModule = (QueryModule) moduleIter.next(); String moduleNamespace = importedModule.getModuleNamespace(); String prefix = getPrefixForNamespace(moduleNamespace); if (!StringUtils.isBlank(prefix)) { importedModules.add(new ModuleImport(prefix, moduleNamespace, importedModule.getSystemId())); FunctionDefinition[] functionDefinitions = getFunctionDefinitions(); AbstractExpression body = exprFor (saxonQuery.getExpression()); String defaultCollation = queryModule.getDefaultCollationName(); if (defaultCollation.equals (CODEPOINT_COLLATION)) { defaultCollation = null; Boolean isPreserveNamespaces = (Boolean) config.getConfigurationProperty(FeatureKeys.XQUERY_PRESERVE_NAMESPACES); Boolean isInheritNamespaces = (Boolean) config.getConfigurationProperty(FeatureKeys.XQUERY_INHERIT_NAMESPACES); if (queryModule.isPreserveNamespaces() == isPreserveNamespaces && queryModule.isInheritNamespaces() == isInheritNamespaces) { isPreserveNamespaces = queryModule.isPreserveNamespaces(); isInheritNamespaces = queryModule.isInheritNamespaces(); queryModule.getDefaultElementNamespace(), queryModule.getDefaultFunctionNamespace(), defaultCollation,
public Collection<String> prepareXQuery(String query, XQStaticContext ctx) throws XQException { setStaticContext(sqc, ctx); try { final XQueryExpression exp = sqc.compileQuery(query); if (logger.isTraceEnabled()) { logger.trace("prepareXQuery; query: \n{}", explainQuery(exp)); } Set<String> result = new HashSet<>(); Iterator<GlobalVariable> itr = exp.getMainModule().getModuleVariables(); while (itr.hasNext()) { result.add(itr.next().getVariableQName().getClarkName()); } return result; } catch (XPathException ex) { logger.error("prepareXQuery.error: ", ex); throw new XQException(ex.getMessage()); } }
String uri = getNamePool().getURI(fingerprint); if (!uri.equals(NamespaceConstant.SCHEMA) && !uri.equals(NamespaceConstant.ANONYMOUS) && !uri.equals(NamespaceConstant.JAVA_TYPE) && !isImportedSchema(uri)) { String msg = "Schema component " + getNamePool().getDisplayName(fingerprint) + " used in "; if (declaration instanceof GlobalVariableDefinition) { msg += "declaration of imported variable " + String module = getModuleNamespace(); if (module == null) { msg += "the main query module";
String query, String namespaceURI) throws XPathException { Configuration config = executable.getConfiguration(); QueryModule module = new QueryModule(config, importer); try { module.setLocationURI(new URI(baseURI)); } catch (URISyntaxException e) { throw new XPathException("Invalid location URI " + baseURI, e); module.setBaseURI(baseURI); module.setExecutable(executable); module.setModuleNamespace(namespaceURI); "XQ", importer.isUpdating(), 31); if (importer.getCodeInjector() != null) { qp.setCodeInjector(importer.getCodeInjector()); } else if (config.isCompileWithTracing()) { qp.setCodeInjector(new TraceCodeInjector()); QNameParser qnp = new QNameParser(module.getLiveNamespaceResolver()); qnp.setAcceptEQName(importer.getXPathVersion() >= 30); qnp.setUnescaper(new XQueryParser.Unescaper(config.getValidCharacterChecker())); qp.setQNameParser(qnp); String namespace = module.getModuleNamespace(); if (namespace == null) { XPathException err = new XPathException("Imported module must be a library module");
/** * Reset function libraries * * @param sqc The static query context set up by the caller */ private void initializeFunctionLibraries(/*@Nullable*/ StaticQueryContext sqc) { Configuration config = getConfiguration(); if (isTopLevelModule()) { globalFunctionLibrary = new XQueryFunctionLibrary(config); } functionLibraryList = new FunctionLibraryList(); functionLibraryList.addFunctionLibrary(getBuiltInFunctionSet()); functionLibraryList.addFunctionLibrary(config.getBuiltInExtensionLibraryList()); functionLibraryList.addFunctionLibrary(new ConstructorFunctionLibrary(config)); localFunctionLibraryNr = functionLibraryList.addFunctionLibrary( new XQueryFunctionLibrary(config)); importedFunctionLibraryNr = functionLibraryList.addFunctionLibrary( new ImportedFunctionLibrary(this, getTopLevelModule().getGlobalFunctionLibrary())); if (sqc != null && sqc.getExtensionFunctionLibrary() != null) { functionLibraryList.addFunctionLibrary(sqc.getExtensionFunctionLibrary()); } functionLibraryList.addFunctionLibrary(config.getIntegratedFunctionLibrary()); config.addExtensionBinders(functionLibraryList); unboundFunctionLibraryNr = functionLibraryList.addFunctionLibrary( new UnboundFunctionLibrary()); }
QueryModule next = (QueryModule)referees.get(i + 1); if (i == s) { message += "Module " + getSystemId() + " references module " + next.getSystemId(); } else { message += ", which references module " + next.getSystemId(); err.setIsStaticError(true); ExpressionLocation loc = new ExpressionLocation(); loc.setSystemId(getSystemId()); loc.setLineNumber(lineNumber); err.setLocator(loc); } else { referees.push(this); Iterator viter = getModuleVariables(); while (viter.hasNext()) { GlobalVariableDefinition gv = (GlobalVariableDefinition)viter.next(); if (b instanceof GlobalVariable) { String uri = ((GlobalVariable)b).getSystemId(); if (!uri.equals(getSystemId())) { QueryModule sqc = executable.getQueryModuleWithSystemId(uri, topModule); sqc.lookForModuleCycles(referees, ((GlobalVariable)b).getLineNumber()); UserFunction f = (UserFunction)list.get(i); String uri = f.getSystemId(); if (!uri.equals(getSystemId())) { QueryModule sqc = executable.getQueryModuleWithSystemId(uri, topModule); sqc.lookForModuleCycles(referees, f.getLineNumber());
String query, String namespaceURI, boolean allowCycles) throws XPathException { Configuration config = executable.getConfiguration(); QueryModule module = new QueryModule(config, importer); try { module.setLocationURI(new URI(baseURI)); } catch (URISyntaxException e) { throw new XPathException("Invalid location URI " + baseURI, e); module.setBaseURI(baseURI); module.setExecutable(executable); module.setModuleNamespace(namespaceURI); QueryParser qp = config.newQueryParser(importer.isUpdating()); qp.setCompileWithTracing(config.isCompileWithTracing()); qp.setDisableCycleChecks(allowCycles); qp.parseLibraryModule(query, module); if (module.getModuleNamespace() == null) { XPathException err = new XPathException("Imported module must be a library module"); err.setErrorCode("XQST0059"); throw err; if (!module.getModuleNamespace().equals(namespaceURI)) { XPathException err = new XPathException("Imported module's namespace does not match requested namespace"); err.setErrorCode("XQST0059");
if (var == null) { String uri = qName.getURI(); if ((uri.equals("") && isMainModule()) || uri.equals(moduleNamespace) || importsNamespace(uri)) { QueryModule main = getTopLevelModule(); var = main.libraryVariables.get(qName); if (var == null) { uvar.setPackageData(main.getPackageData()); uvar.setVariableQName(qName); GlobalVariableReference ref = new GlobalVariableReference(qName); if (var.isPrivate() && (var.getSystemId() == null || !var.getSystemId().equals(getSystemId()))) { String message = "Variable $" + qName.getDisplayName() + " is private"; if (var.getSystemId() == null) {
QueryModule importedModule = (QueryModule)existingModules.get(m); if (!importedModule.getLocationURI().equals(((QueryModule)env).getLocationURI())) { ((QueryModule)env).getModuleNamespace() != null && !((QueryModule)env).getModuleNamespace().equals(importedModule.getModuleNamespace()) && importedModule.importsNamespaceIndirectly(((QueryModule)env).getModuleNamespace())) { grumble("A cycle exists among the module imports, involving namespaces " + ((QueryModule)env).getModuleNamespace() + " and " + importedModule.getModuleNamespace()); if (mImport.locationURIs.get(h).equals(importedModule.getLocationURI())) { mImport.locationURIs.remove(h); ModuleURIResolver resolver = ((QueryModule)env).getUserQueryContext().getModuleURIResolver(); if (existingModules != null && m < hints.length) { for (int e=0; e<existingModules.size(); e++) { if (((QueryModule)existingModules.get(e)).getLocationURI().equals(mImport.locationURIs.get(m))) { loaded = true; break; throw new XPathException("Failure while closing file for imported query module"); QueryModule.makeQueryModule( baseURI, executable, (QueryModule)env, queryText, mImport.namespaceURI, disableCycleChecks);
query = normalizeLineEndings11(query); Executable exec = mainModule.getExecutable(); if (exec == null) { exec = new Executable(config); exec.setHostLanguage(Configuration.XQUERY); exec.setTopLevelPackage(mainModule.getPackageData()); setExecutable(exec); requirement.addRequiredItemType(mainModule.getRequiredContextItemType()); } else if (mainModule.getRequiredContextItemType() != null && mainModule.getRequiredContextItemType() != AnyItemType.getInstance()) { GlobalContextRequirement req = new GlobalContextRequirement(); req.setExternal(true); req.addRequiredItemType(mainModule.getRequiredContextItemType()); exec.setGlobalContextRequirement(req); setCodeInjector(mainModule.getCodeInjector()); lib.addFunctionLibrary(mainModule.getBuiltInFunctionSet()); lib.addFunctionLibrary(config.getBuiltInExtensionLibraryList()); lib.addFunctionLibrary(new ConstructorFunctionLibrary(config)); lib.addFunctionLibrary(config.getIntegratedFunctionLibrary()); lib.addFunctionLibrary(mainModule.getGlobalFunctionLibrary()); config.addExtensionBinders(lib); lib.addFunctionLibrary(userlib);
((QueryModule) env).addImportedNamespace(mImport.namespaceURI); nextToken(); if (isKeyword("at")) { if (mImport.namespaceURI.equals(thisModule.getModuleNamespace()) && mImport.namespaceURI.equals(thisModule.checkURIForPrefix(prefix))) { thisModule.declarePrologNamespace(prefix, mImport.namespaceURI);
Executable exec = mainModule.getExecutable(); Configuration config = mainModule.getConfiguration(); stackFrameMap = config.makeSlotManager(); executable = exec; this.mainModule = mainModule; exp.setRetainedStaticContext(mainModule.makeRetainedStaticContext()); try { ExpressionVisitor visitor = ExpressionVisitor.make(mainModule); exp = exp.simplify(); exp.checkForUpdatingSubexpressions(); ContextItemStaticInfo cit = config.makeContextItemStaticInfo(mainModule.getUserQueryContext().getRequiredContextItemType(), true); Expression e2 = exp.typeCheck(visitor, cit); if (e2 != exp) { mainModule.reportStaticError(err); throw err;
query = normalizeLineEndings11(query); Executable exec = staticContext.getExecutable(); if (exec == null) { exec = new Executable(config); exec.setHostLanguage(Configuration.XQUERY); staticContext.setExecutable(exec); exp.setContainer(new TemporaryContainer(staticContext.getLocationMap(), loc)); while (miter.hasNext()) { QueryModule module = (QueryModule)miter.next(); module.lookForModuleCycles(new Stack(), 1);
String moduleURI = ((QueryModule)env).getModuleNamespace(); if (moduleURI != null && !moduleURI.equals(uri)) { grumble("A variable declared in a library module must be in the module namespace", "XQST0048"); if (qenv.getModuleNamespace() != null && !uri.equals(qenv.getModuleNamespace())) { grumble("Variable " + Err.wrap(varName, Err.VARIABLE) + " is not defined in the module namespace"); qenv.declareVariable(var); } catch (XPathException e) { grumble(e.getMessage(), e.getErrorCodeLocalPart());
String moduleURI = ((QueryModule)env).getModuleNamespace(); if (moduleURI != null && !moduleURI.equals(uri)) { grumble("A function in a library module must be in the module namespace", "XQST0048"); qenv.declareFunction(func); } catch (XPathException e) { grumble(e.getMessage(), e.getErrorCodeLocalPart());
if (var == null) { String uri = qName.getURI(); if (importsNamespace(uri)) { QueryModule main = getTopLevelModule(); var = main.libraryVariables.get(qName); err.setIsStaticError(true); throw err; } else if (var.isPrivate() && !var.getSystemId().equals(getSystemId())) { XPathException err = new XPathException("Cannot reference a private variable in a different module"); err.setErrorCode("XPST0008");
collationName = NamespaceConstant.CODEPOINT_COLLATION_URI; ((QueryModule)env).setDefaultCollationName(collationName); if (!imp.namespaceURI.equals(((QueryModule)env).getModuleNamespace())) { QueryModule parent = (QueryModule)env; if (!parent.mayImportModule(imp.namespaceURI)) { XPathException err = new XPathException( "A module cannot import itself directly or indirectly, unless all modules in the cycle are in the same namespace");
throws XPathException { this.env = env; nameChecker = env.getConfiguration().getNameChecker(); executable = env.getExecutable(); t = new Tokenizer(); try {
/** * Return the system identifier for the current document event. * <p>The return value is the system identifier of the document * entity or of the external parsed entity in which the markup that * triggered the event appears.</p> * <p>If the system identifier is a URL, the parser must resolve it * fully before passing it to the application.</p> * * @return A string containing the system identifier, or null * if none is available. * @see #getPublicId */ /*@Nullable*/ public String getSystemId() { return mainModule.getSystemId(); }