    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.configuration2.tree;
    018
    019import java.util.List;
    020import java.util.Map;
    021
    022/**
    023 * <p>
    024 * Definition of an interface which allows resolving a (property) key for different manipulating operations.
    025 * </p>
    026 * <p>
    027 * This interface is used when interacting with a node model. It is an abstraction over a concrete
    028 * {@link ExpressionEngine} instance. It also implements some functionality for creating special helper objects for the
    029 * processing of complex update operations.
    030 * </p>
    031 *
    032 * @since 2.0
    033 * @param <T> the type of the nodes supported by this resolver
    034 */
    035public interface NodeKeyResolver<T> {
    036    /**
    037     * Performs a query for the specified key on the given root node. This is a thin wrapper over the {@code query()} method
    038     * of an {@link ExpressionEngine}.
    039     *
    040     * @param root the root node
    041     * @param key the key to be resolved
    042     * @param handler the {@code NodeHandler}
    043     * @return a list with query results
    044     */
    045    List<QueryResult<T>> resolveKey(T root, String key, NodeHandler<T> handler);
    046
    047    /**
    048     * Performs a query for the specified key on the given root node returning only node results. Some operations require
    049     * results of type node and do not support attributes (e.g. for tracking nodes). This operation can be used in such
    050     * cases. It works like {@code resolveKey()}, but filters only for results of type node.
    051     *
    052     * @param root the root node
    053     * @param key the key to be resolved
    054     * @param handler the {@code NodeHandler}
    055     * @return a list with the resolved nodes
    056     */
    057    List<T> resolveNodeKey(T root, String key, NodeHandler<T> handler);
    058
    059    /**
    060     * Resolves a key of an add operation. Result is a {@code NodeAddData} object containing all information for actually
    061     * performing the add operation at the specified key.
    062     *
    063     * @param root the root node
    064     * @param key the key to be resolved
    065     * @param handler the {@code NodeHandler}
    066     * @return a {@code NodeAddData} object to be used for the add operation
    067     */
    068    NodeAddData<T> resolveAddKey(T root, String key, NodeHandler<T> handler);
    069
    070    /**
    071     * Resolves a key for an update operation. Result is a {@code NodeUpdateData} object containing all information for
    072     * actually performing the update operation at the specified key using the provided new value object.
    073     *
    074     * @param root the root node
    075     * @param key the key to be resolved
    076     * @param newValue the new value for the key to be updated; this can be a single value or a container for multiple
    077     *        values
    078     * @param handler the {@code NodeHandler}
    079     * @return a {@code NodeUpdateData} object to be used for this update operation
    080     */
    081    NodeUpdateData<T> resolveUpdateKey(T root, String key, Object newValue, NodeHandler<T> handler);
    082
    083    /**
    084     * Generates a unique key for the specified node. This method is used if keys have to be generated for nodes received as
    085     * query results. An implementation must generate a canonical key which is compatible with the current expression
    086     * engine. The passed in map can be used by an implementation as cache. It is created initially by the caller and then
    087     * passed in subsequent calls. An implementation may use this to avoid that keys for nodes already encountered have to
    088     * be generated again.
    089     *
    090     * @param node the node in question
    091     * @param cache a map serving as cache
    092     * @param handler the {@code NodeHandler}
    093     * @return a key for the specified node
    094     */
    095    String nodeKey(T node, Map<T, String> cache, NodeHandler<T> handler);
    096}