*/
private ItemType computeFixedElementItemType(FixedElement instr, StaticContext env,
int validation, SchemaType schemaType,
int nameCode, Expression content) throws XPathException {
final Configuration config = env.getConfiguration();
ItemType itemType;
if (schemaType == null) {
if (validation == Validation.STRICT) {
SchemaDeclaration decl = config.getElementDeclaration(nameCode & 0xfffff);
if (decl == null) {
XPathException err = new XPathException("There is no global element declaration for " +
env.getNamePool().getDisplayName(nameCode) +
", so strict validation will fail");
err.setErrorCode(instr.isXSLT() ? "XTTE1512" : "XQDY0027");
err.setIsTypeError(true);
err.setLocator(instr);
throw err;
}
if (decl.isAbstract()) {
XPathException err = new XPathException("The element declaration for " +
env.getNamePool().getDisplayName(nameCode) +
" is abstract, so strict validation will fail");
err.setErrorCode(instr.isXSLT() ? "XTTE1512" : "XQDY0027");
err.setIsTypeError(true);
err.setLocator(instr);
throw err;
}
schemaType = decl.getType();
instr.setSchemaType(schemaType);
// TODO: this causes validation against the type, rather than the declaration:
// are identity constraints being tested on the top-level element?
itemType = new CombinedNodeTest(
new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
Token.INTERSECT,
new ContentTypeTest(Type.ELEMENT, schemaType, config));
try {
schemaType.analyzeContentExpression(content, Type.ELEMENT, env);
} catch (XPathException e) {
e.setErrorCode(instr.isXSLT() ? "XTTE1510" : "XQDY0027");
e.setLocator(instr);
throw e;
}
SchemaType xsiType = instr.getXSIType(env);
if (xsiType != null) {
xsiType.analyzeContentExpression(content, Type.ELEMENT, env);
try {
config.checkTypeDerivationIsOK(xsiType, schemaType, 0);
} catch (SchemaException e) {
ValidationException ve = new ValidationException("The specified xsi:type " + xsiType.getDescription() +
" is not validly derived from the required type " + schemaType.getDescription());
ve.setConstraintReference(1, "cvc-elt", "4.3");
ve.setErrorCode(instr.isXSLT() ? "XTTE1515" : "XQDY0027");
ve.setLocator((Locator)instr);
throw ve;
}
}
} else if (validation == Validation.LAX) {
SchemaDeclaration decl = config.getElementDeclaration(nameCode & 0xfffff);
if (decl == null) {
env.issueWarning("There is no global element declaration for " +
env.getNamePool().getDisplayName(nameCode), instr);
itemType = new NameTest(Type.ELEMENT, nameCode, env.getNamePool());
} else {