01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.Expression;
04: import net.sf.saxon.expr.StaticContext;
05: import net.sf.saxon.expr.XPathContext;
06: import net.sf.saxon.om.Item;
07: import net.sf.saxon.trans.XPathException;
08: import net.sf.saxon.value.AtomicValue;
09:
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: public static final int MICROSECONDS = 11; // internal use only
27:
28: int component;
29:
30: public Expression simplify(StaticContext env) throws XPathException {
31: component = (operation >> 16) & 0xffff;
32: return super .simplify(env);
33: }
34:
35: /**
36: * Evaluate the expression
37: */
38:
39: public Item evaluateItem(XPathContext context)
40: throws XPathException {
41: AtomicValue arg = (AtomicValue) argument[0]
42: .evaluateItem(context);
43:
44: if (arg == null) {
45: return null;
46: }
47:
48: return arg.getComponent(component);
49:
50: }
51:
52: }
53:
54: //
55: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
56: // you may not use this file except in compliance with the License. You may obtain a copy of the
57: // License at http://www.mozilla.org/MPL/
58: //
59: // Software distributed under the License is distributed on an "AS IS" basis,
60: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
61: // See the License for the specific language governing rights and limitations under the License.
62: //
63: // The Original Code is: all this file.
64: //
65: // The Initial Developer of the Original Code is Michael H. Kay
66: //
67: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
68: //
69: // Contributor(s): none.
70: //
|