1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.11 2004/02/17 04:34:01 minchau Exp $
  18. */
  19. package com.sun.org.apache.xpath.internal.functions;
  20. import com.sun.org.apache.xalan.internal.res.XSLMessages;
  21. import com.sun.org.apache.xpath.internal.XPathContext;
  22. import com.sun.org.apache.xpath.internal.objects.XObject;
  23. import com.sun.org.apache.xpath.internal.objects.XString;
  24. /**
  25. * Execute the Concat() function.
  26. * @xsl.usage advanced
  27. */
  28. public class FuncConcat extends FunctionMultiArgs
  29. {
  30. /**
  31. * Execute the function. The function must return
  32. * a valid object.
  33. * @param xctxt The current execution context.
  34. * @return A valid XObject.
  35. *
  36. * @throws javax.xml.transform.TransformerException
  37. */
  38. public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
  39. {
  40. StringBuffer sb = new StringBuffer();
  41. // Compiler says we must have at least two arguments.
  42. sb.append(m_arg0.execute(xctxt).str());
  43. sb.append(m_arg1.execute(xctxt).str());
  44. if (null != m_arg2)
  45. sb.append(m_arg2.execute(xctxt).str());
  46. if (null != m_args)
  47. {
  48. for (int i = 0; i < m_args.length; i++)
  49. {
  50. sb.append(m_args[i].execute(xctxt).str());
  51. }
  52. }
  53. return new XString(sb.toString());
  54. }
  55. /**
  56. * Check that the number of arguments passed to this function is correct.
  57. *
  58. *
  59. * @param argNum The number of arguments that is being passed to the function.
  60. *
  61. * @throws WrongNumberArgsException
  62. */
  63. public void checkNumberArgs(int argNum) throws WrongNumberArgsException
  64. {
  65. if (argNum < 2)
  66. reportWrongNumberArgs();
  67. }
  68. /**
  69. * Constructs and throws a WrongNumberArgException with the appropriate
  70. * message for this function object.
  71. *
  72. * @throws WrongNumberArgsException
  73. */
  74. protected void reportWrongNumberArgs() throws WrongNumberArgsException {
  75. throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("gtone", null));
  76. }
  77. }