super.checkArguments(visitor); if (operation == EVALUATE || operation == EXPRESSION) { NamespaceResolver nsContext = env.getNamespaceResolver(); staticContext = new IndependentContext(env.getConfiguration()); staticContext.setBaseURI(env.getBaseURI()); staticContext.setImportedSchemaNamespaces(env.getImportedSchemaNamespaces()); staticContext.setDefaultFunctionNamespace(env.getDefaultFunctionNamespace()); staticContext.setDefaultElementNamespace(env.getDefaultElementNamespace()); details.setSystemId(env.getLocationMap().getSystemId(this.locationId)); details.setLineNumber(env.getLocationMap().getLineNumber(this.locationId)); } else if (operation == EVALUATE_NODE) { staticContext = new IndependentContext(env.getConfiguration());
public RetainedStaticContext(StaticContext sc) { this.config = sc.getConfiguration(); this.packageData = sc.getPackageData(); if (sc.getStaticBaseURI() != null) { staticBaseUriString = sc.getStaticBaseURI(); try { this.staticBaseUri = ExpressionTool.getBaseURI(sc, null, true); } catch (XPathException e) { staticBaseUri = null; } } this.defaultCollationName = sc.getDefaultCollationName(); this.decimalFormatManager = sc.getDecimalFormatManager(); this.defaultElementNamespace = sc.getDefaultElementNamespace(); defaultFunctionNamespace = sc.getDefaultFunctionNamespace(); backwardsCompatibility = sc.isInBackwardsCompatibleMode(); if (Version.platform.JAXPStaticContextCheck(this, sc)) { //updated in method } else { this.namespaces = new HashMap<>(4); NamespaceResolver resolver = sc.getNamespaceResolver(); for (Iterator<String> it = resolver.iteratePrefixes(); it.hasNext(); ) { String prefix = it.next(); if (!prefix.equals("xml")) { namespaces.put(prefix, resolver.getURIForPrefix(prefix, true)); } } } }
sb.append("Cannot find a ").append(arguments.length).append( "-argument function named ").append(functionName.getEQName()).append("()"); Configuration config = env.getConfiguration(); for (String reason : reasons) { sb.append(". ").append(reason); if (i != arguments.length) { SymbolicName.F sn = new SymbolicName.F(functionName, i); if (env.getFunctionLibrary().isAvailable(sn)) { existsWithDifferentArity = true; break; sb.append(". External function calls have been disabled"); if (env.isInBackwardsCompatibleMode()) {
private void checkContextItemType(Item contextItem) throws XPathException { if (contextItem != null) { ItemType type = env.getRequiredContextItemType(); TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); if (!type.matches(contextItem, th)) { throw new XPathException("Supplied context item does not match required context item type " + type); } } }
public void checkArguments(ExpressionVisitor visitor) throws XPathException { // the second time checkArguments is called, it's a global check so the static context is inaccurate if (checked) { return; } checked = true; super.checkArguments(visitor); if (!(argument[0] instanceof Literal && (argument.length==1 || argument[1] instanceof Literal))) { // we need to save the namespace context nsContext = visitor.getStaticContext().getNamespaceResolver(); // for type-available, we need to save the set of imported namespaces if (operation == TYPE_AVAILABLE) { importedSchemaNamespaces = visitor.getStaticContext().getImportedSchemaNamespaces(); } } }
long arity = -1; if (argument.length == 2) { arity = ((NumericValue)argument[1].evaluateItem(env.makeEarlyEvaluationContext())).longValue(); String uri; if (prefix.length() == 0) { uri = env.getDefaultFunctionNamespace(); } else { uri = env.getURIForPrefix(prefix); b = env.getFunctionLibrary().isAvailable(functionName, (int)arity); } catch (QNameException e) { XPathException err = new XPathException(e.getMessage()); String uri; if (prefix.length() == 0) { uri = env.getDefaultElementNamespace(); } else { uri = env.getURIForPrefix(prefix); b = env.isAllowedBuiltInType((BuiltInAtomicType)type); } else { b = (type != null && env.isImportedSchema(uri));
uri = env.getDefaultFunctionNamespace(); } else { try { uri = env.getURIForPrefix(parts[0]); } catch (XPathException err) { grumble(err.getMessage()); if (uri.equals(NamespaceConstant.SCHEMA)) { ItemType t = Type.getBuiltInItemType(uri, parts[1]); if (t instanceof BuiltInAtomicType && !env.isAllowedBuiltInType((BuiltInAtomicType)t)) { grumble("The type " + fname + " is not recognized by a Basic XSLT Processor. ", "XPST0080"); fcall = env.getFunctionLibrary().bind(functionName, arguments, env); } catch (XPathException err) { if (err.getErrorCodeLocalPart() == null) { String msg = "Cannot find a matching " + arguments.length + "-argument function named " + functionName.getClarkName() + "()"; if (!env.getConfiguration().isAllowExternalFunctions()) { msg += ". Note: external function calls have been disabled"; if (env.isInBackwardsCompatibleMode()) { ((AtomicType)fcall.getItemType(env.getConfiguration().getTypeHierarchy())).isNamespaceSensitive() && arguments[0] instanceof StringLiteral) { try { AtomicValue av = CastExpression.castStringToQName(((StringLiteral)arguments[0]).getStringValue(), (AtomicType)fcall.getItemType(env.getConfiguration().getTypeHierarchy()), env);
String uri; if (parts[0].length() == 0) { uri = env.getDefaultElementNamespace(); } else { try { uri = env.getURIForPrefix(parts[0]); } catch (XPathException err) { grumble(err.getMessage(), err.getErrorCodeLocalPart()); if (!env.isAllowedBuiltInType((BuiltInAtomicType)t)) { grumble("The type " + qname + " is not recognized by a Basic XSLT Processor. ", "XPST0080"); try { String className = parts[1].replace('-', '$'); theClass = env.getConfiguration().getClass(className, false, null); } catch (XPathException err) { grumble("Unknown Java class " + parts[1], "XPST0051"); return new ExternalObjectType(theClass, env.getConfiguration()); } else if (uri.equals(NamespaceConstant.DOT_NET_TYPE)) { return (AtomicType)Configuration.getPlatform().getExternalObjectType(env.getConfiguration(), uri, parts[1]); } else { if (env.isImportedSchema(uri)) { int fp = env.getNamePool().getFingerprint(uri, parts[1]); if (fp == -1) { grumble("Unknown type " + qname, "XPST0051"); SchemaType st = env.getConfiguration().getSchemaType(fp); if (st == null) {
return STRING; qNameParser.setDefaultNamespace(env.getDefaultElementNamespace()); StructuredQName sq = null; try { return (AtomicType) Version.platform.getExternalObjectType(env.getConfiguration(), uri, local); SchemaType st = env.getConfiguration().getSchemaType(new StructuredQName("", uri, local)); if (st == null) { if (allowXPath30Syntax) { if (!env.isImportedSchema(uri)) { grumble("Simple type " + qname + " exists, but its target namespace has not been imported in the static context"); if (!env.isImportedSchema(uri)) { grumble("Atomic type " + qname + " exists, but its target namespace has not been imported in the static context");
/** * Make a NameTest, using the static context for namespace resolution * * @param nodeType the type of node required (identified by a constant in * class Type) * @param qname the lexical QName of the required node; alternatively, * a QName in Clark notation ({uri}local) * @param useDefault true if the default namespace should be used when * the QName is unprefixed * @return a NameTest, representing a pattern that tests for a node of a * given node kind and a given name * @throws XPathException if the QName is invalid */ /*@NotNull*/ public NameTest makeNameTest(short nodeType, /*@NotNull*/ String qname, boolean useDefault) throws XPathException { NamePool pool = env.getConfiguration().getNamePool(); StructuredQName q = makeStructuredQName(qname, useDefault ? env.getDefaultElementNamespace() : ""); assert q != null; int fp = pool.allocateFingerprint(q.getURI(), q.getLocalPart()); return new NameTest(nodeType, fp, pool); }
/** * If tracing, add a clause to a FLWOR expression that can be used to monitor requests for * tuples to be processed * * @param target the clause whose evaluation is to be traced (or otherwise monitored) * @param env the static context of the containing FLWOR expression * @return the new clause to do the tracing; or null if no tracing is required at this point */ public Clause injectClause(Clause target, StaticContext env) { return new TraceClause(target, env.getNamespaceResolver()); } }
qp.setDefaultNamespace(env.getDefaultFunctionNamespace()); qp.setErrorOnBadSyntax("XTDE1400"); qp.setErrorOnUnresolvedPrefix("XTDE1400"); int maxArity = 20; if (getArity() == 2) { minArity = (int) ((NumericValue) arguments[1].evaluateItem(env.makeEarlyEvaluationContext())).longValue(); maxArity = minArity; if (env.getFunctionLibrary().isAvailable(sn)) { b = true; break;
/** * Type-check the expression * @return the checked expression */ public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { operand0 = visitor.typeCheck(operand0, contextItemType); operand1 = visitor.typeCheck(operand1, contextItemType); StaticContext env = visitor.getStaticContext(); StringCollator comp = env.getCollation(env.getDefaultCollationName()); if (comp==null) { comp = CodepointCollator.getInstance(); } XPathContext context = env.makeEarlyEvaluationContext(); comparer = new GenericAtomicComparer(comp, context); // evaluate the expression now if both arguments are constant if ((operand0 instanceof Literal) && (operand1 instanceof Literal)) { return Literal.makeLiteral((AtomicValue)evaluateItem(context)); } return this; }
/** * Check that the higher-order-function feature is licensed * * @throws LicenseException if the feature is not licensed */ public void checkHofFeature() { env.getConfiguration().checkLicensedFeature(Configuration.LicenseFeature.PROFESSIONAL_EDITION, "higher-order functions", -1); }
/** * If tracing, wrap an expression in a trace instruction * @param startOffset the position of the expression in the soruce * @param exp the expression to be wrapped * @param construct integer constant identifying the kind of construct * @param qName the name of the construct (if applicable) * @return the expression that does the tracing */ protected Expression makeTracer(int startOffset, Expression exp, int construct, StructuredQName qName) { if (isCompileWithTracing()) { TraceExpression trace = new TraceExpression(exp); long lc = t.getLineAndColumn(startOffset); trace.setLineNumber((int)(lc>>32)); trace.setColumnNumber((int)(lc&0x7fffffff)); trace.setSystemId(env.getSystemId()); trace.setNamespaceResolver(env.getNamespaceResolver()); trace.setConstructType(construct); trace.setObjectName(qName); //trace.setObjectNameCode(objectNameCode); return trace; } else { return exp; } }
/** * Issue a warning message * * @param message the message * @param locator the query/stylesheet location associated with the message */ public void issueWarning(String message, Location locator) { if (!isSuppressWarnings()) { staticContext.issueWarning(message, locator); } }
/** * Perform static type checking on an argument to a function call, and add * type conversion logic where necessary. * @param arg argument number, zero-based * @param visitor an expression visitor */ private void checkArgument(int arg, ExpressionVisitor visitor) throws XPathException { RoleLocator role = new RoleLocator(RoleLocator.FUNCTION, getFunctionName(), arg); //role.setSourceLocator(this); role.setErrorCode(getErrorCodeForTypeErrors()); argument[arg] = TypeChecker.staticTypeCheck( argument[arg], getRequiredType(arg), visitor.getStaticContext().isInBackwardsCompatibleMode(), role, visitor); }
} else { warning("No processing instruction name will ever contain a colon"); nameCode = env.getNamePool().allocate("prefix", "http://saxon.sf.net/ nonexistent namespace", "___invalid-name"); nameCode = env.getNamePool().allocate("prefix", "http://saxon.sf.net/ nonexistent namespace", "___invalid-name"); expect(Token.RPAR); nextToken(); return new NameTest(Type.PROCESSING_INSTRUCTION, nameCode, env.getNamePool()); suri = env.getNamePool().getURI(nameCode); env.getConfiguration().getAttributeDeclaration(nameCode & 0xfffff); if (!env.isImportedSchema(suri)) { grumble("No schema has been imported for namespace '" + suri + '\'', "XPST0008"); } else { schemaType = attributeDecl.getType(); nameTest = new NameTest(Type.ATTRIBUTE, nameCode, env.getNamePool()); nameTest = new NameTest(Type.ATTRIBUTE, nameCode, env.getNamePool()); return nameTest; if (!env.isImportedSchema(suri)) { grumble("No schema has been imported for namespace '" + suri + '\'', "XPST0008"); env.getConfiguration().getElementDeclaration(nameCode & 0xfffff); if (elementDecl == null) { grumble("There is no declaration for element <" + nodeName + "> in an imported schema", "XPST0008");
private Expression makeUnaryExpression(int operator, Expression operand) { if (Literal.isAtomic(operand)) { // very early evaluation of expressions like "-1", so they are treated as numeric literals AtomicValue val = (AtomicValue) ((Literal) operand).getValue(); if (val instanceof NumericValue) { if (env.isInBackwardsCompatibleMode()) { val = new DoubleValue(((NumericValue) val).getDoubleValue()); } AtomicValue value = operator == Token.NEGATE ? ((NumericValue) val).negate() : (NumericValue) val; return Literal.makeLiteral(value); } } return env.getConfiguration().getTypeChecker(env.isInBackwardsCompatibleMode()).makeArithmeticExpression( Literal.makeLiteral(Int64Value.ZERO), operator, operand); }
/** * Output a warning message * * @param message the text of the message */ protected void warning(String message) { if (!env.getConfiguration().getBooleanProperty(Feature.SUPPRESS_XPATH_WARNINGS)) { String s = t.recentText(-1); String prefix = (message.startsWith("...") ? "near" : "in") + ' ' + Err.wrap(s) + ":\n "; env.issueWarning(prefix + message, makeLocation()); } }