public void checkArguments(StaticContext env) throws XPathException { if (checked) return; checked = true; super.checkArguments(env); Optimizer opt = env.getConfiguration().getOptimizer(); argument[1] = ExpressionTool.unsorted(opt, argument[1], false); if (argument[0] instanceof StringValue) { // common case, key name is supplied as a constant try { keyFingerprint = ((ExpressionContext) env) .getFingerprint(((StringValue) argument[0]).getStringValue(), false); } catch (XPathException e) { StaticError err = new StaticError( "Error in key name " + ((StringValue) argument[0]).getStringValue() + ": " + e.getMessage()); err.setLocator(this); err.setErrorCode("XTDE1260"); throw err; } if (keyFingerprint == -1) { StaticError err = new StaticError( "Key " + ((StringValue) argument[0]).getStringValue() + " has not been defined"); err.setLocator(this); err.setErrorCode("XTDE1260"); throw err; } } else { // we need to save the namespace context nsContext = env.getNamespaceResolver(); } }
protected static void checkContentSequence( StaticContext env, Expression content, int validation, SchemaType type) throws XPathException { Expression[] components; if (content instanceof Block) { components = ((Block) content).getChildren(); } else { components = new Expression[] {content}; } int elementCount = 0; boolean isXSLT = content.getHostLanguage() == Configuration.XSLT; TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); for (int i = 0; i < components.length; i++) { ItemType it = components[i].getItemType(th); if (it instanceof NodeTest) { int possibleNodeKinds = ((NodeTest) it).getNodeKindMask(); if (possibleNodeKinds == 1 << Type.ATTRIBUTE) { XPathException de = new XPathException("Cannot create an attribute node whose parent is a document node"); de.setErrorCode(isXSLT ? "XTDE0420" : "XPTY0004"); de.setLocator(components[i]); throw de; } else if (possibleNodeKinds == 1 << Type.NAMESPACE) { XPathException de = new XPathException("Cannot create a namespace node whose parent is a document node"); de.setErrorCode(isXSLT ? "XTDE0420" : "XQTY0024"); de.setLocator(components[i]); throw de; } if (possibleNodeKinds == 1 << Type.ELEMENT) { elementCount++; if (elementCount > 1 && (validation == Validation.STRICT || validation == Validation.LAX || type != null)) { XPathException de = new XPathException("A valid document must have only one child element"); if (isXSLT) { de.setErrorCode("XTTE1550"); } else { de.setErrorCode("XQDY0061"); } de.setLocator(components[i]); throw de; } if (validation == Validation.STRICT && components[i] instanceof FixedElement) { SchemaDeclaration decl = env.getConfiguration() .getElementDeclaration( ((FixedElement) components[i]).getNameCode(null) & NamePool.FP_MASK); if (decl != null) { ((FixedElement) components[i]) .getContentExpression() .checkPermittedContents(decl.getType(), env, true); } } } } } }