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.io.Serializable;
020
021/**
022 * Pointers represent locations of objects and their properties
023 * in Java object graphs. JXPathContext has methods
024 * ({@link JXPathContext#getPointer(java.lang.String) getPointer()}
025 * and  ({@link JXPathContext#iteratePointers(java.lang.String)
026 * iteratePointers()}, which, given an XPath, produce Pointers for the objects
027 * or properties described the the path. For example, <code>ctx.getPointer
028 * ("foo/bar")</code> will produce a Pointer that can get and set the property
029 * "bar" of the object which is the value of the property "foo" of the root
030 * object. The value of <code>ctx.getPointer("aMap/aKey[3]")</code> will be a
031 * pointer to the 3'rd element of the array, which is the value for the key
032 * "aKey" of the map, which is the value of the property "aMap" of the root
033 * object.
034 *
035 * @author Dmitri Plotnikov
036 * @version $Revision: 652845 $ $Date: 2008-05-02 13:46:46 -0400 (Fri, 02 May 2008) $
037 */
038public interface Pointer extends Cloneable, Comparable, Serializable {
039
040    /**
041     * Returns the value of the object, property or collection element
042     * this pointer represents. May convert the value to one of the
043     * canonical InfoSet types: String, Number, Boolean, Set.
044     *
045     * For example, in the case of an XML element, getValue() will
046     * return the text contained by the element rather than
047     * the element itself.
048     * @return Object value
049     */
050    Object getValue();
051
052    /**
053     * Returns the raw value of the object, property or collection element
054     * this pointer represents.  Never converts the object to a
055     * canonical type: returns it as is.
056     *
057     * For example, for an XML element, getNode() will
058     * return the element itself rather than the text it contains.
059     * @return Object node
060     */
061    Object getNode();
062
063    /**
064     * Modifies the value of the object, property or collection element
065     * this pointer represents.
066     * @param value value to set
067     */
068    void setValue(Object value);
069
070    /**
071     * Returns the node this pointer is based on.
072     * @return Object
073     */
074    Object getRootNode();
075
076    /**
077     * Returns a string that is a proper "canonical" XPath that corresponds to
078     * this pointer.  Consider this example:
079     * <p><code>Pointer  ptr = ctx.getPointer("//employees[firstName = 'John']")
080     * </code>
081     * <p>The  value of <code>ptr.asPath()</code> will look something like
082     * <code>"/departments[2]/employees[3]"</code>, so, basically, it represents
083     * the concrete location(s) of the result of a search performed by JXPath.
084     * If an object in the pointer's path is a Dynamic Property object (like a
085     * Map), the asPath method generates an XPath that looks like this: <code>"
086     * /departments[@name = 'HR']/employees[3]"</code>.
087     * @return String path
088     */
089    String asPath();
090
091    /**
092     * Pointers are cloneable.
093     * @return cloned Object
094     */
095    Object clone();
096}