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.io.Serializable;
21
22 /**
23 * Pointers represent locations of objects and their properties in Java object graphs. JXPathContext has methods
24 * ({@link JXPathContext#getPointer(java.lang.String) getPointer()} and ({@link JXPathContext#iteratePointers(java.lang.String) iteratePointers()}, which, given
25 * an XPath, produce Pointers for the objects or properties described the path. For example, {@code ctx.getPointer
26 * ("foo/bar")} will produce a Pointer that can get and set the property "bar" of the object which is the value of the property "foo" of the root object. The
27 * value of {@code ctx.getPointer("aMap/aKey[3]")} will be a pointer to the 3'rd element of the array, which is the value for the key "aKey" of the map, which
28 * is the value of the property "aMap" of the root object.
29 */
30 public interface Pointer extends Cloneable, Comparable, Serializable {
31
32 /**
33 * Returns a string that is a proper "canonical" XPath that corresponds to this pointer. Consider this example:
34 * <p>
35 * {@code Pointer ptr = ctx.getPointer("//employees[firstName = 'John']")
36 * }
37 * </p>
38 * <p>
39 * The value of {@code ptr.asPath()} will look something like {@code "/departments[2]/employees[3]"}, so, basically, it represents the concrete location(s)
40 * of the result of a search performed by JXPath. If an object in the pointer's path is a Dynamic Property object (like a Map), the asPath method generates
41 * an XPath that looks like this: {@code "
42 * /departments[@name = 'HR']/employees[3]"}.
43 *
44 * @return String path
45 */
46 String asPath();
47
48 /**
49 * Pointers are cloneable.
50 *
51 * @return cloned Object
52 */
53 Object clone();
54
55 /**
56 * Returns the raw value of the object, property or collection element this pointer represents. Never converts the object to a canonical type: returns it as
57 * is.
58 * <p>
59 * For example, for an XML element, getNode() will return the element itself rather than the text it contains.
60 * </p>
61 *
62 * @return Object node
63 */
64 Object getNode();
65
66 /**
67 * Returns the node this pointer is based on.
68 *
69 * @return Object
70 */
71 Object getRootNode();
72
73 /**
74 * Returns the value of the object, property or collection element this pointer represents. May convert the value to one of the canonical InfoSet types:
75 * String, Number, Boolean, Set.
76 * <p>
77 * For example, in the case of an XML element, getValue() will return the text contained by the element rather than the element itself.
78 * </p>
79 *
80 * @return Object value
81 */
82 Object getValue();
83
84 /**
85 * Modifies the value of the object, property or collection element this pointer represents.
86 *
87 * @param value value to set
88 */
89 void setValue(Object value);
90 }