001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.jxpath; 018 019import java.util.List; 020 021/** 022 * If an extenstion function has an argument of type ExpressionContext, 023 * it can gain access to the current node of an XPath expression context. 024 * <p> 025 * Example: 026 * <blockquote><pre> 027 * public class MyExtenstionFunctions { 028 * public static String objectType(ExpressionContext context){ 029 * Object value = context.getContextNodePointer().getValue(); 030 * if (value == null){ 031 * return "null"; 032 * } 033 * return value.getClass().getName(); 034 * } 035 * } 036 * </pre></blockquote> 037 * 038 * You can then register this extension function using a {@link ClassFunctions 039 * ClassFunctions} object and call it like this: 040 * <blockquote><pre> 041 * "/descendent-or-self::node()[ns:objectType() = 'java.util.Date']" 042 * </pre></blockquote> 043 * This expression will find all nodes of the graph that are dates. 044 */ 045public interface ExpressionContext { 046 047 /** 048 * Get the JXPathContext in which this function is being evaluated. 049 * 050 * @return A list representing the current context nodes. 051 */ 052 JXPathContext getJXPathContext(); 053 054 /** 055 * Get the current context node. 056 * 057 * @return The current context node pointer. 058 */ 059 Pointer getContextNodePointer(); 060 061 /** 062 * Get the current context node list. Each element of the list is 063 * a Pointer. 064 * 065 * @return A list representing the current context nodes. 066 */ 067 List getContextNodeList(); 068 069 /** 070 * Returns the current context position. 071 * @return int 072 */ 073 int getPosition(); 074}