01: /*
02: * Copyright 1999-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: /*
17: * $Id: FuncConcat.java,v 1.12 2004/08/17 19:25:36 jycli Exp $
18: */
19: package org.apache.xpath.functions;
20:
21: import org.apache.xalan.res.XSLMessages;
22: import org.apache.xpath.XPathContext;
23: import org.apache.xpath.objects.XObject;
24: import org.apache.xpath.objects.XString;
25:
26: /**
27: * Execute the Concat() function.
28: * @xsl.usage advanced
29: */
30: public class FuncConcat extends FunctionMultiArgs {
31: static final long serialVersionUID = 1737228885202314413L;
32:
33: /**
34: * Execute the function. The function must return
35: * a valid object.
36: * @param xctxt The current execution context.
37: * @return A valid XObject.
38: *
39: * @throws javax.xml.transform.TransformerException
40: */
41: public XObject execute(XPathContext xctxt)
42: throws javax.xml.transform.TransformerException {
43:
44: StringBuffer sb = new StringBuffer();
45:
46: // Compiler says we must have at least two arguments.
47: sb.append(m_arg0.execute(xctxt).str());
48: sb.append(m_arg1.execute(xctxt).str());
49:
50: if (null != m_arg2)
51: sb.append(m_arg2.execute(xctxt).str());
52:
53: if (null != m_args) {
54: for (int i = 0; i < m_args.length; i++) {
55: sb.append(m_args[i].execute(xctxt).str());
56: }
57: }
58:
59: return new XString(sb.toString());
60: }
61:
62: /**
63: * Check that the number of arguments passed to this function is correct.
64: *
65: *
66: * @param argNum The number of arguments that is being passed to the function.
67: *
68: * @throws WrongNumberArgsException
69: */
70: public void checkNumberArgs(int argNum)
71: throws WrongNumberArgsException {
72: if (argNum < 2)
73: reportWrongNumberArgs();
74: }
75:
76: /**
77: * Constructs and throws a WrongNumberArgException with the appropriate
78: * message for this function object.
79: *
80: * @throws WrongNumberArgsException
81: */
82: protected void reportWrongNumberArgs()
83: throws WrongNumberArgsException {
84: throw new WrongNumberArgsException(XSLMessages
85: .createXPATHMessage("gtone", null));
86: }
87: }
|