KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.functions;
2
3 import net.sf.saxon.expr.Expression;
4 import net.sf.saxon.expr.StaticContext;
5 import net.sf.saxon.expr.XPathContext;
6 import net.sf.saxon.om.Item;
7 import net.sf.saxon.trans.XPathException;
8 import net.sf.saxon.value.AtomicValue;
9
10 /**
11  * This class supports the get_X_from_Y functions defined in XPath 2.0
12  */

13
14 public class Component extends SystemFunction {
15
16     public static final int YEAR = 1;
17     public static final int MONTH = 2;
18     public static final int DAY = 3;
19     public static final int HOURS = 4;
20     public static final int MINUTES = 5;
21     public static final int SECONDS = 6;
22     public static final int TIMEZONE = 7;
23     public static final int LOCALNAME = 8;
24     public static final int NAMESPACE = 9;
25     public static final int PREFIX = 10;
26
27     int component;
28
29     public Expression simplify(StaticContext env) throws XPathException {
30         component = (operation >> 16) & 0xffff;
31         return super.simplify(env);
32     }
33
34     /**
35      * Evaluate the expression
36      */

37
38     public Item evaluateItem(XPathContext context) throws XPathException {
39         AtomicValue arg = (AtomicValue)argument[0].evaluateItem(context);
40
41         if (arg == null) {
42             return null;
43         }
44
45         return arg.getComponent(component);
46
47     }
48
49 }
50
51
52 //
53
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
54
// you may not use this file except in compliance with the License. You may obtain a copy of the
55
// License at http://www.mozilla.org/MPL/
56
//
57
// Software distributed under the License is distributed on an "AS IS" basis,
58
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
59
// See the License for the specific language governing rights and limitations under the License.
60
//
61
// The Original Code is: all this file.
62
//
63
// The Initial Developer of the Original Code is Michael H. Kay
64
//
65
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
66
//
67
// Contributor(s): none.
68
//
69
Popular Tags