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 /**
20 * <p>
21 * Definition of a <em>Visitor</em> interface for a configuration node structure.
22 * </p>
23 * <p>
24 * This is a typical application of the GoF <em>Visitor</em> pattern. An object implementing this interface can be used
25 * to traverse a hierarchical structure of nodes in various ways. The type of the nodes in the structure is generic; a
26 * corresponding {@link NodeHandler} implementation must be available for navigating through the structure.
27 * </p>
28 * <p>
29 * Note that the exact way the methods of a {@code ConfigurationNodeVisitor} are invoked is dependent on a specific
30 * traversal process.
31 * </p>
32 *
33 * @param <T> the type of the nodes processed by this visitor
34 * @since 1.3
35 */
36 public interface ConfigurationNodeVisitor<T> {
37 /**
38 * Returns a flag whether the current visit process should be aborted. This method allows a visitor implementation to
39 * state that it does not need any further data. It may be used for example by visitors that search for a certain node in the
40 * hierarchy. After that node was found, there is no need to process the remaining nodes, too. This method is called
41 * after each visited node. A result of <strong>true</strong> indicates that the current iteration is to be aborted.
42 *
43 * @return a flag if the visit process should be stopped
44 */
45 boolean terminate();
46
47 /**
48 * Visits the specified node after after its children - if existing - have been processed.
49 *
50 * @param node the node to be visited
51 * @param handler the {@code NodeHandler}
52 */
53 void visitAfterChildren(T node, NodeHandler<T> handler);
54
55 /**
56 * Visits the specified node before the children of this node - if existing - are processed.
57 *
58 * @param node the node to be visited
59 * @param handler the {@code NodeHandler}
60 */
61 void visitBeforeChildren(T node, NodeHandler<T> handler);
62 }