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