/** * Create the constructor function. * * @param targetType the type to which the function will convert its input * @param resolver namespace resolver for use if the target type is namespace-sensitive */ public ListConstructorFunction(ListType targetType, NamespaceResolver resolver, boolean allowEmpty) throws MissingComponentException { this.targetType = targetType; this.nsResolver = resolver; this.allowEmpty = allowEmpty; this.memberType = targetType.getItemType(); }
/** * Get the name of the function, or null if it is anonymous * * @return the function name, or null for an anonymous inline function */ public StructuredQName getFunctionName() { return targetType.getStructuredQName(); }
/** * Cast a string value to a list type * * @param value the input string value * @param targetType the target list type * @param nsResolver the namespace context, needed if the type is namespace-sensitive * @param rules the conversion rules * @return the sequence of atomic values that results from the conversion * @throws XPathException if the conversion fails */ public static AtomicSequence cast(CharSequence value, ListType targetType, final NamespaceResolver nsResolver, final ConversionRules rules) throws XPathException { ValidationFailure failure = targetType.validateContent(value, nsResolver, rules); if (failure != null) { throw failure.makeException(); } return targetType.getTypedValue(value, nsResolver, rules); }
/** * Invoke the function * * @param context the XPath dynamic evaluation context * @param args the actual arguments to be supplied * @return the result of invoking the function * @throws net.sf.saxon.trans.XPathException * if a dynamic error occurs within the function */ public BooleanValue call(XPathContext context, Sequence[] args) throws XPathException { SequenceIterator iter = args[0].iterate(); AtomicValue val = (AtomicValue) iter.next(); if (val == null) { return BooleanValue.get(allowEmpty); } if (iter.next() != null) { return BooleanValue.FALSE; } if (!(val instanceof StringValue) || val instanceof AnyURIValue) { return BooleanValue.FALSE; } ConversionRules rules = context.getConfiguration().getConversionRules(); CharSequence cs = val.getStringValueCS(); ValidationFailure failure = targetType.validateContent(cs, nsResolver, rules); return BooleanValue.get(failure == null); } }
return ((ListType)type).getBuiltInBaseType().getFingerprint() == StandardNames.XS_IDREFS;
/** * The toString() method for an expression attempts to give a representation of the expression * in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath. * In the case of XSLT instructions, the toString() method gives an abstracted view of the syntax */ public String toString() { return targetType.getEQName() + "(" + getBaseExpression().toString() + ")"; }
@Override public String toShortString() { return targetType.getDisplayName() + "(" + getBaseExpression().toShortString() + ")"; }
/** * Invoke the function * * @param context the XPath dynamic evaluation context * @param args the actual arguments to be supplied * @return the result of invoking the function * @throws net.sf.saxon.trans.XPathException * if a dynamic error occurs within the function */ public BooleanValue call(XPathContext context, Sequence[] args) throws XPathException { SequenceIterator iter = args[0].iterate(); AtomicValue val = (AtomicValue) iter.next(); if (val == null) { return BooleanValue.get(allowEmpty); } if (iter.next() != null) { return BooleanValue.FALSE; } if (!(val instanceof StringValue) || val instanceof AnyURIValue) { return BooleanValue.FALSE; } ConversionRules rules = context.getConfiguration().getConversionRules(); CharSequence cs = val.getStringValueCS(); ValidationFailure failure = targetType.validateContent(cs, nsResolver, rules); return BooleanValue.get(failure == null); } }
return ((ListType)type).getBuiltInBaseType().getFingerprint() == StandardNames.XS_IDREFS;
/** * Create the constructor function. * * @param targetType the type to which the function will convert its input * @param resolver namespace resolver for use if the target type is namespace-sensitive */ public ListConstructorFunction(ListType targetType, NamespaceResolver resolver, boolean allowEmpty) throws MissingComponentException { this.targetType = targetType; this.nsResolver = resolver; this.allowEmpty = allowEmpty; this.memberType = targetType.getItemType(); }
ValidationFailure failure = targetType.validateContent(cs, nsResolver, rules); if (failure != null) { throw failure.makeException(); return targetType.getTypedValue(cs, nsResolver, rules);
/** * Get the name of the function, or null if it is anonymous * * @return the function name, or null for an anonymous inline function */ public StructuredQName getFunctionName() { return targetType.getStructuredQName(); }
/** * Get the static type of the expression */ /*@NotNull*/ public ItemType getItemType() { try { if (targetType.getItemType() instanceof ItemType) { return (ItemType) targetType.getItemType(); } } catch (MissingComponentException e) { // } return BuiltInAtomicType.ANY_ATOMIC; }
ValidationFailure failure = targetType.validateContent(cs, nsResolver, rules); if (failure != null) { throw failure.makeException(); return targetType.getTypedValue(cs, nsResolver, rules);
out.emitAttribute("as", ((ListCastableFunction) target).getTargetType().getStructuredQName()); for (Operand o : operands()) { o.getChildExpression().export(out); out.emitAttribute("as", ((ListConstructorFunction) target).getTargetType().getStructuredQName()); for (Operand o : operands()) { o.getChildExpression().export(out);
return (AtomicType) type; } else if (type instanceof ListType) { SimpleType mem = ((ListType) type).getItemType(); if (mem.isAtomicType()) { return (AtomicType) mem; return (AtomicType) ctype; } else if (ctype instanceof ListType) { SimpleType mem = ((ListType) ctype).getItemType(); if (mem.isAtomicType()) { return (AtomicType) mem;
out.emitAttribute("as", ((ListCastableFunction) target).getTargetType().getStructuredQName()); for (Operand o : operands()) { o.getChildExpression().export(out); out.emitAttribute("as", ((ListConstructorFunction) target).getTargetType().getStructuredQName()); for (Operand o : operands()) { o.getChildExpression().export(out);
return (AtomicType) type; } else if (type instanceof ListType) { SimpleType mem = ((ListType) type).getItemType(); if (mem.isAtomicType()) { return (AtomicType) mem; return (AtomicType) ctype; } else if (ctype instanceof ListType) { SimpleType mem = ((ListType) ctype).getItemType(); if (mem.isAtomicType()) { return (AtomicType) mem;
/** * Get the item type of the atomic values that will be produced when an item * of this type is atomized (assuming that atomization succeeds) */ public AtomicType getAtomizedItemType() { SchemaType type = config.getSchemaType(requiredType); if (type.isAtomicType()) { return (AtomicType)type; } else if (type instanceof ListType) { SimpleType mem = ((ListType)type).getItemType(); if (mem.isAtomicType()) { return (AtomicType)mem; } } else if (type instanceof ComplexType && ((ComplexType)type).isSimpleContent()) { SimpleType ctype = ((ComplexType)type).getSimpleContentType(); if (ctype.isAtomicType()) { return (AtomicType)ctype; } else if (ctype instanceof ListType) { SimpleType mem = ((ListType)ctype).getItemType(); if (mem.isAtomicType()) { return (AtomicType)mem; } } } return BuiltInAtomicType.ANY_ATOMIC; }
/** * Get the item type of the atomic values that will be produced when an item * of this type is atomized (assuming that atomization succeeds) */ public AtomicType getAtomizedItemType() { SchemaType type = config.getSchemaType(requiredType); if (type.isAtomicType()) { return (AtomicType)type; } else if (type instanceof ListType) { SimpleType mem = ((ListType)type).getItemType(); if (mem.isAtomicType()) { return (AtomicType)mem; } } else if (type instanceof ComplexType && ((ComplexType)type).isSimpleContent()) { SimpleType ctype = ((ComplexType)type).getSimpleContentType(); if (ctype.isAtomicType()) { return (AtomicType)ctype; } else if (ctype instanceof ListType) { SimpleType mem = ((ListType)ctype).getItemType(); if (mem.isAtomicType()) { return (AtomicType)mem; } } } return BuiltInAtomicType.ANY_ATOMIC; }