01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.XPathContext;
04: import net.sf.saxon.expr.StaticProperty;
05: import net.sf.saxon.om.Item;
06: import net.sf.saxon.om.SequenceIterator;
07: import net.sf.saxon.trans.XPathException;
08:
09: /**
10: * This class supports the XPath 2.0 functions exactly-one(), one-or-more(), zero-or-one().
11: * Because Saxon doesn't do strict static type checking, these are essentially identity
12: * functions; the run-time type checking is done as part of the function call mechanism
13: */
14:
15: public class TreatFn extends SystemFunction {
16:
17: /**
18: * Return the error code to be used for type errors
19: */
20:
21: public String getErrorCodeForTypeErrors() {
22: switch (operation) {
23: case StaticProperty.ALLOWS_ZERO_OR_ONE:
24: return "FORG0003";
25: case StaticProperty.ALLOWS_ONE_OR_MORE:
26: return "FORG0004";
27: case StaticProperty.EXACTLY_ONE:
28: return "FORG0005";
29: default:
30: return "XPTY0004";
31: }
32: }
33:
34: /**
35: * Evaluate the function
36: */
37:
38: public Item evaluateItem(XPathContext context)
39: throws XPathException {
40: return argument[0].evaluateItem(context);
41: }
42:
43: /**
44: * Iterate over the results of the function
45: */
46:
47: public SequenceIterator iterate(XPathContext context)
48: throws XPathException {
49: return argument[0].iterate(context);
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: //
|