Debian Codegraph @

net/sf/saxon/functions/Nilled_1.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.functions;
9
10 import net.sf.saxon.expr.Callable;
11 import net.sf.saxon.expr.XPathContext;
12 import net.sf.saxon.om.NodeInfo;
13 import net.sf.saxon.om.One;
14 import net.sf.saxon.om.Sequence;
15 import net.sf.saxon.om.ZeroOrOne;
16 import net.sf.saxon.trans.XPathException;
17 import net.sf.saxon.type.Type;
18 import net.sf.saxon.value.BooleanValue;
19
20 /**
21 * This class supports the nilled() function
22 */
23
24 public class Nilled_1 extends SystemFunction implements Callable {
25
26
27 /**
28 * Determine whether a node has the nilled property
29 *
30 * @param node the node in question (if null, the function returns null)
31 * @return the value of the nilled accessor. Returns null for any node other than an
32 * element node. For an element node, returns true if the element has been validated and
33 * has an xsi:nil attribute whose value is true.
34 */
35
36 /*@Nullable*/
37 public static BooleanValue getNilledProperty(NodeInfo node) {
38 if (node == null || node.getNodeKind() != Type.ELEMENT) {
39 return null;
40 }
41 return BooleanValue.get(node.isNilled());
42 }
43
44 /**
45 * Determine whether a node is nilled. Returns true if the value
46 * of the nilled property is true; false if the value is false or absent
47 * @param node the node to be tested
48 * @return true if the node is nilled
49 */
50
51 public static boolean isNilled(NodeInfo node) {
52 BooleanValue b = getNilledProperty(node);
53 return b != null && b.getBooleanValue();
54 }
55
56 /**
57 * Evaluate the expression
58 *
59 * @param context the dynamic evaluation context
60 * @param arguments the values of the arguments, supplied as SequenceIterators
61 * @return the result of the evaluation, in the form of a SequenceIterator
62 * @throws net.sf.saxon.trans.XPathException
63 * if a dynamic error occurs during the evaluation of the expression
64 */
65 public ZeroOrOne<BooleanValue> call(XPathContext context, Sequence[] arguments) throws XPathException {
66
67 NodeInfo node = (NodeInfo)arguments[0].head();
68 if (node == null || node.getNodeKind() != Type.ELEMENT) {
69 return ZeroOrOne.empty();
70 }
71 return One.bool(isNilled(node));
72 }
73 }