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 * https://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 package org.apache.commons.configuration2.tree;
18
19 import java.util.List;
20 import java.util.Map;
21
22 /**
23 * <p>
24 * Definition of an interface which allows resolving a (property) key for different manipulating operations.
25 * </p>
26 * <p>
27 * This interface is used when interacting with a node model. It is an abstraction over a concrete
28 * {@link ExpressionEngine} instance. It also implements some functionality for creating special helper objects for the
29 * processing of complex update operations.
30 * </p>
31 *
32 * @param <T> the type of the nodes supported by this resolver
33 * @since 2.0
34 */
35 public interface NodeKeyResolver<T> {
36
37 /**
38 * Generates a unique key for the specified node. This method is used if keys have to be generated for nodes received as
39 * query results. An implementation must generate a canonical key which is compatible with the current expression
40 * engine. The passed in map can be used by an implementation as cache. It is created initially by the caller and then
41 * passed in subsequent calls. An implementation may use this to avoid that keys for nodes already encountered have to
42 * be generated again.
43 *
44 * @param node the node in question
45 * @param cache a map serving as cache
46 * @param handler the {@code NodeHandler}
47 * @return a key for the specified node
48 */
49 String nodeKey(T node, Map<T, String> cache, NodeHandler<T> handler);
50
51 /**
52 * Resolves a key of an add operation. Result is a {@code NodeAddData} object containing all information for actually
53 * performing the add operation at the specified key.
54 *
55 * @param root the root node
56 * @param key the key to be resolved
57 * @param handler the {@code NodeHandler}
58 * @return a {@code NodeAddData} object to be used for the add operation
59 */
60 NodeAddData<T> resolveAddKey(T root, String key, NodeHandler<T> handler);
61
62 /**
63 * Performs a query for the specified key on the given root node. This is a thin wrapper over the {@code query()} method
64 * of an {@link ExpressionEngine}.
65 *
66 * @param root the root node
67 * @param key the key to be resolved
68 * @param handler the {@code NodeHandler}
69 * @return a list with query results
70 */
71 List<QueryResult<T>> resolveKey(T root, String key, NodeHandler<T> handler);
72
73 /**
74 * Performs a query for the specified key on the given root node returning only node results. Some operations require
75 * results of type node and do not support attributes (for example for tracking nodes). This operation can be used in such
76 * cases. It works like {@code resolveKey()}, but filters only for results of type node.
77 *
78 * @param root the root node
79 * @param key the key to be resolved
80 * @param handler the {@code NodeHandler}
81 * @return a list with the resolved nodes
82 */
83 List<T> resolveNodeKey(T root, String key, NodeHandler<T> handler);
84
85 /**
86 * Resolves a key for an update operation. Result is a {@code NodeUpdateData} object containing all information for
87 * actually performing the update operation at the specified key using the provided new value object.
88 *
89 * @param root the root node
90 * @param key the key to be resolved
91 * @param newValue the new value for the key to be updated; this can be a single value or a container for multiple
92 * values
93 * @param handler the {@code NodeHandler}
94 * @return a {@code NodeUpdateData} object to be used for this update operation
95 */
96 NodeUpdateData<T> resolveUpdateKey(T root, String key, Object newValue, NodeHandler<T> handler);
97 }