    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 */
    017
    018package org.apache.commons.jxpath;
    019
    020import java.util.List;
    021
    022/**
    023 * If an extenstion function has an argument of type ExpressionContext, it can gain access to the current node of an XPath expression context.
    024 * <p>
    025 * Example: <blockquote>
    026 *
    027 * <pre>
    028 * public class MyExtenstionFunctions {
    029 *
    030 *     public static String objectType(ExpressionContext context) {
    031 *         Object value = context.getContextNodePointer().getValue();
    032 *         if (value == null) {
    033 *             return "null";
    034 *         }
    035 *         return value.getClass().getName();
    036 *     }
    037 * }
    038 * </pre>
    039 *
    040 * </blockquote>
    041 *
    042 * You can then register this extension function using a {@link ClassFunctions ClassFunctions} object and call it like this: <blockquote>
    043 *
    044 * <pre>
    045 * "/descendent-or-self::node()[ns:objectType() = 'java.util.Date']"
    046 * </pre>
    047 *
    048 * </blockquote> This expression will find all nodes of the graph that are dates.
    049 */
    050public interface ExpressionContext {
    051
    052    /**
    053     * Gets the current context node list. Each element of the list is a Pointer.
    054     *
    055     * @return A list representing the current context nodes.
    056     */
    057    List<Pointer> getContextNodeList();
    058
    059    /**
    060     * Gets the current context node.
    061     *
    062     * @return The current context node pointer.
    063     */
    064    Pointer getContextNodePointer();
    065
    066    /**
    067     * Gets the JXPathContext in which this function is being evaluated.
    068     *
    069     * @return A list representing the current context nodes.
    070     */
    071    JXPathContext getJXPathContext();
    072
    073    /**
    074     * Returns the current context position.
    075     *
    076     * @return int
    077     */
    078    int getPosition();
    079}