/** * Get the type annotation of an attribute node. * * @param nr the node number of the attribute * @return the fingerprint of the type annotation, or Type.UNTYPED_ATOMIC if there is no annotation */ int getAttributeAnnotation(int nr) { if (attType == null) { return StandardNames.XS_UNTYPED_ATOMIC; } else { return attType[nr].getFingerprint(); } }
/** * Set the schema type to be used for validation * @param type the type to be used for validation. (For a document constructor, this is the required * type of the document element) */ public void setSchemaType(SchemaType type) { schemaType = type; namespaceSensitiveType = (type instanceof SimpleType) && ((SimpleType)type).isNamespaceSensitive(); }
/** * Get the item type of the function item * * @return the function item's type */ public FunctionItemType getFunctionItemType() { AtomicType resultType = BuiltInAtomicType.ANY_ATOMIC; if (memberType.isAtomicType()) { resultType = (AtomicType) memberType; } SequenceType argType = allowEmpty ? SequenceType.OPTIONAL_ATOMIC : SequenceType.SINGLE_ATOMIC; return new SpecificFunctionType( new SequenceType[]{argType}, SequenceType.makeSequenceType(resultType, StaticProperty.ALLOWS_ZERO_OR_MORE)); }
/** * Check whether the content of an attribute is namespace-sensitive * * * @param type the type annotation of the node * @param nodeNr the the node number of the elemente * @throws XPathException if an error occurs */ private void checkNotNamespaceSensitiveAttribute(SimpleType type, int nodeNr) throws XPathException { if (type.isNamespaceSensitive()) { if (type.isAtomicType()) { throw new CopyNamespaceSensitiveException( "Cannot copy QName or NOTATION values without copying namespaces"); } else { // For a union or list type, we need to check whether the actual value is namespace-sensitive AtomicSequence value = tree.getTypedValueOfAttribute(null, nodeNr); for (AtomicValue val : value) { if (val.getPrimitiveType().isNamespaceSensitive()) { throw new CopyNamespaceSensitiveException( "Cannot copy QName or NOTATION values without copying namespaces"); } } } } }
if (Literal.isAtomic(select) && schemaType != null && !schemaType.isNamespaceSensitive()) { CharSequence value = ((Literal)select).getValue().getStringValueCS(); ValidationFailure err = schemaType.validateContent( value, DummyNamespaceResolver.getInstance(), config.getNameChecker()); if (err != null) { XPathException se = new XPathException("Attribute value " + Err.wrap(value, Err.VALUE) + " does not the match the required type " + schemaType.getDescription() + ". " + err.getMessage()); se.setErrorCode("XTTE1540");
public Item evaluateItem(XPathContext context) throws XPathException { Orphan o = (Orphan)super.evaluateItem(context); if (schemaType != null) { ValidationFailure err = schemaType.validateContent( o.getStringValueCS(), DummyNamespaceResolver.getInstance(), context.getConfiguration().getNameChecker()); if (err != null) { throw new ValidationException("Attribute value " + Err.wrap(o.getStringValueCS(), Err.VALUE) + " does not the match the required type " + schemaType.getDescription() + ". " + err.getMessage()); o.setTypeAnnotation(schemaType.getFingerprint()); if (schemaType.isNamespaceSensitive()) { throw new XPathException("Cannot validate a parentless attribute whose content is namespace-sensitive");
stype = ((ComplexType) parentType).getSimpleContentType(); if (stype != null && !stype.isNamespaceSensitive()) { ValidationFailure err = stype.validateContent( getStringValueCS(), null, env.getConfiguration().getConversionRules()); if (err != null) {
ValidationFailure err = schemaType.validateContent( value, DummyNamespaceResolver.getInstance(), context.getConfiguration().getNameChecker()); if (err != null) { "Attribute value " + Err.wrap(value, Err.VALUE) + " does not match the required type " + schemaType.getDescription() + ". " + err.getMessage()); ve.setErrorCode("XTTE1540");
switch (operator) { case Token.CASTABLE_AS: if (type.isUnionType()) { NamespaceResolver resolver = env.getNamespaceResolver(); UnionCastableFunction ucf = new UnionCastableFunction((UnionType) type, resolver, allowEmpty); return new StaticFunctionCall(ucf, new Expression[]{lhs}); } else if (type.isListType()) { NamespaceResolver resolver = env.getNamespaceResolver(); ListCastableFunction lcf = new ListCastableFunction((ListType) type, resolver, allowEmpty); if (type.isUnionType()) { NamespaceResolver resolver = env.getNamespaceResolver(); UnionConstructorFunction ucf = new UnionConstructorFunction((UnionType) type, resolver, allowEmpty); return new StaticFunctionCall(ucf, new Expression[]{lhs}); } else if (type.isListType()) { NamespaceResolver resolver = env.getNamespaceResolver(); ListConstructorFunction lcf = new ListConstructorFunction((ListType) type, resolver, allowEmpty); throw new XPathException("Cannot cast to xs:anySimpleType", "XPST0080"); } else { throw new XPathException("Cannot cast to " + type.getDescription(), "XPST0051");
final boolean nsSensitive = ((SimpleType) requiredItemType).isNamespaceSensitive(); ItemMappingFunction<Item<?>, Item<?>> converter; if (nsSensitive) { } else if (((SimpleType) requiredItemType).isUnionType()) { final ConversionRules rules = config.getConversionRules(); converter = item -> { if (item instanceof UntypedAtomicValue) { try { return ((SimpleType) requiredItemType).getTypedValue( item.getStringValueCS(), null, rules).head(); } catch (ValidationException ve) {
/** * Diagnostic print of expression structure. The abstract expression tree * is written to the supplied output destination. */ public void explain(ExpressionPresenter out) { out.startElement("directAttribute"); out.emitAttribute("name", out.getNamePool().getDisplayName(nameCode)); out.emitAttribute("validation", Validation.toString(validationAction)); if (schemaType != null) { out.emitAttribute("type", schemaType.getDescription()); } getSelect().explain(out); out.endElement(); }
if (val == null) break; count++; ValidationFailure v = base.validateContent(val.getStringValue(), nsResolver, nameChecker); if (v != null) { return v;
if (contentType.isAtomicType()) { return isSubType((AtomicType)contentType, BuiltInAtomicType.IDREF); } else if (contentType instanceof ListType) { return contentType.getBuiltInBaseType().getFingerprint() == StandardNames.XS_IDREFS;
if (type.isAtomicType()) { if (((AtomicType) type).isAbstract()) { reasons.add("Abstract type used in constructor function: {" + uri + '}' + localName); } else if (type.isUnionType()) { NamespaceResolver resolver = env.getNamespaceResolver(); UnionConstructorFunction ucf = new UnionConstructorFunction((UnionType) type, resolver, true); return null; } else if (((SimpleType) st).isUnionType() && env.getXPathVersion() >= 30) { NamespaceResolver resolver = env.getNamespaceResolver(); UnionConstructorFunction ucf = new UnionConstructorFunction((UnionType) st, resolver, true);
} else if ((nameCode & NamePool.FP_MASK) == StandardNames.XML_ID) { isID = true; } else if (type.isIdType()) { isID = true; } else if (type == BuiltInAtomicType.IDREF || type == BuiltInListType.IDREFS) { isIDREF = true; } else if (type.isIdRefType()) { AtomicSequence as = type.getTypedValue(attValue, null, getConfiguration().getConversionRules()); for (AtomicValue v : as) { if (v.getItemType().isIdRefType()) {
/** * Diagnostic print of expression structure. The abstract expression tree * is written to the supplied output destination. */ public void export(ExpressionPresenter out) throws XPathException { out.startElement("att", this); out.emitAttribute("name", nodeName.getDisplayName()); if (!nodeName.getStructuredQName().hasURI("")) { out.emitAttribute("nsuri", nodeName.getStructuredQName().getURI()); } if (getValidationAction() != Validation.SKIP && getValidationAction() != Validation.BY_TYPE) { out.emitAttribute("validation", Validation.toString(getValidationAction())); } if (getSchemaType() != null) { out.emitAttribute("type", getSchemaType().getStructuredQName()); } String flags = ""; if (isLocal()) { flags += "l"; } if (!flags.isEmpty()) { out.emitAttribute("flags", flags); } getSelect().export(out); out.endElement(); }
/** * Convert a string to the target type of this converter. * * @param input the string to be converted * @return either an {@link net.sf.saxon.value.AtomicValue} of the appropriate type for this converter (if conversion * succeeded), or a {@link net.sf.saxon.type.ValidationFailure} if conversion failed. */ @Override public ConversionResult convertString( CharSequence input) { try { return targetType.getTypedValue(input, null, rules).head(); } catch (ValidationException err) { return err.getValidationFailure(); } } }
att = new TinyAttributeImpl(this, nodeNr); AtomicSequence value = type.atomize(att); if (allowTypedValueCache) { if (attTypedValue == null) {
if (Literal.isAtomic(select) && schemaType != null && !schemaType.isNamespaceSensitive()) { CharSequence value = ((Literal)select).getValue().getStringValueCS(); ValidationFailure err = schemaType.validateContent( value, DummyNamespaceResolver.getInstance(), config.getNameChecker()); if (err != null) { XPathException se = new XPathException("Attribute value " + Err.wrap(value, Err.VALUE) + " does not the match the required type " + schemaType.getDescription() + ". " + err.getMessage()); se.setErrorCode("XTTE1540");
public Item evaluateItem(XPathContext context) throws XPathException { Orphan o = (Orphan)super.evaluateItem(context); if (schemaType != null) { ValidationFailure err = schemaType.validateContent( o.getStringValueCS(), DummyNamespaceResolver.getInstance(), context.getConfiguration().getNameChecker()); if (err != null) { throw new ValidationException("Attribute value " + Err.wrap(o.getStringValueCS(), Err.VALUE) + " does not the match the required type " + schemaType.getDescription() + ". " + err.getMessage()); o.setTypeAnnotation(schemaType.getFingerprint()); if (schemaType.isNamespaceSensitive()) { throw new XPathException("Cannot validate a parentless attribute whose content is namespace-sensitive");