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: FuncCurrent.java,v 1.13 2004/02/17 04:34:01 minchau Exp $
  18. */
  19. package com.sun.org.apache.xpath.internal.functions;
  20. import com.sun.org.apache.xml.internal.dtm.DTM;
  21. import com.sun.org.apache.xml.internal.dtm.DTMIterator;
  22. import com.sun.org.apache.xpath.internal.XPathContext;
  23. import com.sun.org.apache.xpath.internal.axes.LocPathIterator;
  24. import com.sun.org.apache.xpath.internal.axes.PredicatedNodeTest;
  25. import com.sun.org.apache.xpath.internal.objects.XNodeSet;
  26. import com.sun.org.apache.xpath.internal.objects.XObject;
  27. import com.sun.org.apache.xpath.internal.axes.SubContextList;
  28. import com.sun.org.apache.xpath.internal.patterns.StepPattern;
  29. import com.sun.org.apache.xalan.internal.res.XSLMessages;
  30. import com.sun.org.apache.xalan.internal.res.XSLTErrorResources;
  31. /**
  32. * Execute the current() function.
  33. * @xsl.usage advanced
  34. */
  35. public class FuncCurrent extends Function
  36. {
  37. /**
  38. * Execute the function. The function must return
  39. * a valid object.
  40. * @param xctxt The current execution context.
  41. * @return A valid XObject.
  42. *
  43. * @throws javax.xml.transform.TransformerException
  44. */
  45. public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
  46. {
  47. SubContextList subContextList = xctxt.getCurrentNodeList();
  48. int currentNode = DTM.NULL;
  49. if (null != subContextList) {
  50. if (subContextList instanceof PredicatedNodeTest) {
  51. LocPathIterator iter = ((PredicatedNodeTest)subContextList)
  52. .getLocPathIterator();
  53. currentNode = iter.getCurrentContextNode();
  54. } else if(subContextList instanceof StepPattern) {
  55. throw new RuntimeException(XSLMessages.createMessage(
  56. XSLTErrorResources.ER_PROCESSOR_ERROR,null));
  57. }
  58. } else {
  59. // not predicate => ContextNode == CurrentNode
  60. currentNode = xctxt.getContextNode();
  61. }
  62. return new XNodeSet(currentNode, xctxt.getDTMManager());
  63. }
  64. /**
  65. * No arguments to process, so this does nothing.
  66. */
  67. public void fixupVariables(java.util.Vector vars, int globalsSize)
  68. {
  69. // no-op
  70. }
  71. }