KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > functions > Nilled


1 package net.sf.saxon.functions;
2 import net.sf.saxon.expr.XPathContext;
3 import net.sf.saxon.om.Item;
4 import net.sf.saxon.om.NodeInfo;
5 import net.sf.saxon.style.StandardNames;
6 import net.sf.saxon.trans.XPathException;
7 import net.sf.saxon.type.Type;
8 import net.sf.saxon.value.BooleanValue;
9
10 /**
11 * This class supports the nilled() function
12 */

13
14 public class Nilled extends SystemFunction {
15
16     /**
17     * Evaluate the function
18     */

19
20     public Item evaluateItem(XPathContext c) throws XPathException {
21         NodeInfo node = (NodeInfo)argument[0].evaluateItem(c);
22         return getNilledProperty(node);
23     }
24
25     /**
26      * Determine whether a node has the nilled property
27      * @param node the node in question (if null, the function returns null)
28      * @return the value of the nilled accessor. Returns null for any node other than an
29      * element node. For an element node, returns true if the element has been validated and
30      * has an xsi:nil attribute whose value is true.
31      */

32
33     public static BooleanValue getNilledProperty(NodeInfo node) {
34         if (node==null || node.getNodeKind() != Type.ELEMENT) {
35             return null;
36         }
37         if (node.getTypeAnnotation() == -1) {
38             return BooleanValue.FALSE;
39         }
40         String JavaDoc val = node.getAttributeValue(StandardNames.XSI_NIL);
41         if (val == null) {
42             return BooleanValue.FALSE;
43         }
44         if (val.trim().equals("1") || val.trim().equals("true")) {
45             return BooleanValue.TRUE;
46         }
47         return BooleanValue.FALSE;
48     }
49
50     /**
51      * Determine whether a node is nilled. Returns true if the value
52      * of the nilled property is true; false if the value is false or absent
53      */

54
55     public static boolean isNilled(NodeInfo node) {
56         BooleanValue b = getNilledProperty(node);
57         if (b == null) {
58             return false;
59         } else {
60             return b.getBooleanValue();
61         }
62     }
63 }
64
65 //
66
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
67
// you may not use this file except in compliance with the License. You may obtain a copy of the
68
// License at http://www.mozilla.org/MPL/
69
//
70
// Software distributed under the License is distributed on an "AS IS" basis,
71
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
72
// See the License for the specific language governing rights and limitations under the License.
73
//
74
// The Original Code is: all this file.
75
//
76
// The Initial Developer of the Original Code is Michael H. Kay.
77
//
78
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
79
//
80
// Contributor(s): none.
81
//
82
Popular Tags