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. package org.apache.commons.jxpath;
  17. import java.util.List;
  18. /**
  19. * If an extenstion function has an argument of type ExpressionContext,
  20. * it can gain access to the current node of an XPath expression context.
  21. * <p>
  22. * Example:
  23. * <blockquote><pre>
  24. * public class MyExtenstionFunctions {
  25. * public static String objectType(ExpressionContext context){
  26. * Object value = context.getContextNodePointer().getValue();
  27. * if (value == null){
  28. * return "null";
  29. * }
  30. * return value.getClass().getName();
  31. * }
  32. * }
  33. * </pre></blockquote>
  34. *
  35. * You can then register this extension function using a {@link ClassFunctions
  36. * ClassFunctions} object and call it like this:
  37. * <blockquote><pre>
  38. * "/descendent-or-self::node()[ns:objectType() = 'java.util.Date']"
  39. * </pre></blockquote>
  40. * This expression will find all nodes of the graph that are dates.
  41. */
  42. public interface ExpressionContext {
  43. /**
  44. * Get the JXPathContext in which this function is being evaluated.
  45. *
  46. * @return A list representing the current context nodes.
  47. */
  48. JXPathContext getJXPathContext();
  49. /**
  50. * Get the current context node.
  51. *
  52. * @return The current context node pointer.
  53. */
  54. Pointer getContextNodePointer();
  55. /**
  56. * Get the current context node list. Each element of the list is
  57. * a Pointer.
  58. *
  59. * @return A list representing the current context nodes.
  60. */
  61. List getContextNodeList();
  62. /**
  63. * Returns the current context position.
  64. */
  65. int getPosition();
  66. }