View Javadoc
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  package org.apache.commons.configuration2.tree;
18  
19  import java.util.List;
20  import java.util.Set;
21  
22  /**
23   * <p>
24   * An abstract base class for decorators of a {@code NodeHandler}.
25   * </p>
26   * <p>
27   * This class implements all methods of the {@code NodeHandler} interface by delegating to another instance. This is
28   * convenient if specific functionality of a {@code NodeHandler} is to be adapted for a special use case. Concrete sub
29   * classes have to implement the {@code getDecoratedNodeHandler()} method to provide the underlying handler.
30   * </p>
31   *
32   * @since 2.0
33   * @param <T> the type of the nodes supported by this handler
34   */
35  public abstract class NodeHandlerDecorator<T> implements NodeHandler<T> {
36      @Override
37      public String nodeName(final T node) {
38          return getDecoratedNodeHandler().nodeName(node);
39      }
40  
41      @Override
42      public Object getValue(final T node) {
43          return getDecoratedNodeHandler().getValue(node);
44      }
45  
46      @Override
47      public T getParent(final T node) {
48          return getDecoratedNodeHandler().getParent(node);
49      }
50  
51      @Override
52      public List<T> getChildren(final T node) {
53          return getDecoratedNodeHandler().getChildren(node);
54      }
55  
56      @Override
57      public <C> List<T> getMatchingChildren(final T node, final NodeMatcher<C> matcher, final C criterion) {
58          return getDecoratedNodeHandler().getMatchingChildren(node, matcher, criterion);
59      }
60  
61      @Override
62      public <C> int getMatchingChildrenCount(final T node, final NodeMatcher<C> matcher, final C criterion) {
63          return getDecoratedNodeHandler().getMatchingChildrenCount(node, matcher, criterion);
64      }
65  
66      @Override
67      public List<T> getChildren(final T node, final String name) {
68          return getDecoratedNodeHandler().getChildren(node, name);
69      }
70  
71      @Override
72      public T getChild(final T node, final int index) {
73          return getDecoratedNodeHandler().getChild(node, index);
74      }
75  
76      @Override
77      public int indexOfChild(final T parent, final T child) {
78          return getDecoratedNodeHandler().indexOfChild(parent, child);
79      }
80  
81      @Override
82      public int getChildrenCount(final T node, final String name) {
83          return getDecoratedNodeHandler().getChildrenCount(node, name);
84      }
85  
86      @Override
87      public Set<String> getAttributes(final T node) {
88          return getDecoratedNodeHandler().getAttributes(node);
89      }
90  
91      @Override
92      public boolean hasAttributes(final T node) {
93          return getDecoratedNodeHandler().hasAttributes(node);
94      }
95  
96      @Override
97      public Object getAttributeValue(final T node, final String name) {
98          return getDecoratedNodeHandler().getAttributeValue(node, name);
99      }
100 
101     @Override
102     public boolean isDefined(final T node) {
103         return getDecoratedNodeHandler().isDefined(node);
104     }
105 
106     @Override
107     public T getRootNode() {
108         return getDecoratedNodeHandler().getRootNode();
109     }
110 
111     /**
112      * Gets the {@code NodeHandler} object that is decorated by this instance. All method calls are delegated to this
113      * object.
114      *
115      * @return the decorated {@code NodeHandler}
116      */
117     protected abstract NodeHandler<T> getDecoratedNodeHandler();
118 }