Debian Codegraph @

net/sf/saxon/expr/ListCastableFunction.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.expr;
9
10 import net.sf.saxon.lib.ConversionRules;
11 import net.sf.saxon.om.NamespaceResolver;
12 import net.sf.saxon.om.Sequence;
13 import net.sf.saxon.om.SequenceIterator;
14 import net.sf.saxon.om.StructuredQName;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.type.*;
17 import net.sf.saxon.value.*;
18
19 /**
20 * A function item representing a castability test for a list type
21 */
22
23 public class ListCastableFunction extends ListConstructorFunction {
24
25 /**
26 * Create the constructor function.
27 *
28 * @param targetType the type to which the function will convert its input
29 * @param resolver namespace resolver for use if the target type is namespace-sensitive
30 */
31
32 public ListCastableFunction(ListType targetType, NamespaceResolver resolver, boolean allowEmpty) throws MissingComponentException {
33 super(targetType, resolver, allowEmpty);
34 }
35
36 /**
37 * Get the item type of the function item
38 *
39 * @return the function item's type
40 */
41 public FunctionItemType getFunctionItemType() {
42 return new SpecificFunctionType(
43 new SequenceType[]{SequenceType.ANY_SEQUENCE},
44 SequenceType.SINGLE_BOOLEAN);
45 }
46
47 /**
48 * Get the name of the function, or null if it is anonymous
49 *
50 * @return the function name, or null for an anonymous inline function
51 */
52 public StructuredQName getFunctionName() {
53 return null;
54 }
55
56 /**
57 * Invoke the function
58 *
59 * @param context the XPath dynamic evaluation context
60 * @param args the actual arguments to be supplied
61 * @return the result of invoking the function
62 * @throws net.sf.saxon.trans.XPathException
63 * if a dynamic error occurs within the function
64 */
65 public BooleanValue call(XPathContext context, Sequence[] args) throws XPathException {
66 SequenceIterator iter = args[0].iterate();
67 AtomicValue val = (AtomicValue) iter.next();
68 if (val == null) {
69 return BooleanValue.get(allowEmpty);
70 }
71 if (iter.next() != null) {
72 return BooleanValue.FALSE;
73 }
74 if (!(val instanceof StringValue) || val instanceof AnyURIValue) {
75 return BooleanValue.FALSE;
76 }
77
78 ConversionRules rules = context.getConfiguration().getConversionRules();
79 CharSequence cs = val.getStringValueCS();
80 ValidationFailure failure = targetType.validateContent(cs, nsResolver, rules);
81 return BooleanValue.get(failure == null);
82 }
83 }
84