View Javadoc

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