01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.XPathContext;
04: import net.sf.saxon.om.Item;
05: import net.sf.saxon.om.FastStringBuffer;
06: import net.sf.saxon.trans.XPathException;
07: import net.sf.saxon.value.AtomicValue;
08: import net.sf.saxon.value.SequenceType;
09: import net.sf.saxon.value.StringValue;
10:
11: public class Concat extends SystemFunction {
12:
13: /**
14: * Get the required type of the nth argument
15: */
16:
17: protected SequenceType getRequiredType(int arg) {
18: return getDetails().argumentTypes[0];
19: // concat() is a special case
20: }
21:
22: /**
23: * Evaluate the function in a string context
24: */
25:
26: public String evaluateAsString(XPathContext c)
27: throws XPathException {
28: return evaluateItem(c).getStringValue();
29: }
30:
31: /**
32: * Evaluate in a general context
33: */
34:
35: public Item evaluateItem(XPathContext c) throws XPathException {
36: int numArgs = argument.length;
37: FastStringBuffer sb = new FastStringBuffer(1024);
38: for (int i = 0; i < numArgs; i++) {
39: AtomicValue val = (AtomicValue) argument[i].evaluateItem(c);
40: if (val != null) {
41: sb.append(val.getStringValueCS());
42: }
43: }
44: return StringValue.makeStringValue(sb.condense());
45: }
46:
47: }
48:
49: //
50: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
51: // you may not use this file except in compliance with the License. You may obtain a copy of the
52: // License at http://www.mozilla.org/MPL/
53: //
54: // Software distributed under the License is distributed on an "AS IS" basis,
55: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
56: // See the License for the specific language governing rights and limitations under the License.
57: //
58: // The Original Code is: all this file.
59: //
60: // The Initial Developer of the Original Code is Michael H. Kay.
61: //
62: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
63: //
64: // Contributor(s): none.
65: //
|