View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.jxpath;
18  
19  import java.util.List;
20  
21  /**
22   * If an extenstion function has an argument of type ExpressionContext,
23   * it can gain access to the current node of an XPath expression context.
24   * <p>
25   * Example:
26   * <blockquote><pre>
27   * public class MyExtenstionFunctions {
28   *    public static String objectType(ExpressionContext context){
29   *       Object value = context.getContextNodePointer().getValue();
30   *       if (value == null){
31   *           return "null";
32   *       }
33   *       return value.getClass().getName();
34   *    }
35   * }
36   * </pre></blockquote>
37   *
38   * You can then register this extension function using a {@link ClassFunctions
39   * ClassFunctions} object and call it like this:
40   * <blockquote><pre>
41   *   "/descendent-or-self::node()[ns:objectType() = 'java.util.Date']"
42   * </pre></blockquote>
43   * This expression will find all nodes of the graph that are dates.
44   */
45  public interface ExpressionContext {
46  
47      /**
48       * Get the JXPathContext in which this function is being evaluated.
49       *
50       * @return A list representing the current context nodes.
51       */
52      JXPathContext getJXPathContext();
53  
54      /**
55       * Get the current context node.
56       *
57       * @return The current context node pointer.
58       */
59      Pointer getContextNodePointer();
60  
61      /**
62       * Get the current context node list.  Each element of the list is
63       * a Pointer.
64       *
65       * @return A list representing the current context nodes.
66       */
67      List getContextNodeList();
68  
69      /**
70       * Returns the current context position.
71       * @return int
72       */
73      int getPosition();
74  }