    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.Set;
    021
    022/**
    023 * <p>
    024 * An abstract base class for decorators of a {@code NodeHandler}.
    025 * </p>
    026 * <p>
    027 * This class implements all methods of the {@code NodeHandler} interface by
    028 * delegating to another instance. This is convenient if specific functionality
    029 * of a {@code NodeHandler} is to be adapted for a special use case. Concrete
    030 * sub classes have to implement the {@code getDecoratedNodeHandler()} method to
    031 * provide the underlying handler.
    032 * </p>
    033 *
    034 * @version $Id: NodeHandlerDecorator.java 1842194 2018-09-27 22:24:23Z ggregory $
    035 * @since 2.0
    036 * @param <T> the type of the nodes supported by this handler
    037 */
    038public abstract class NodeHandlerDecorator<T> implements NodeHandler<T>
    039{
    040    @Override
    041    public String nodeName(final T node)
    042    {
    043        return getDecoratedNodeHandler().nodeName(node);
    044    }
    045
    046    @Override
    047    public Object getValue(final T node)
    048    {
    049        return getDecoratedNodeHandler().getValue(node);
    050    }
    051
    052    @Override
    053    public T getParent(final T node)
    054    {
    055        return getDecoratedNodeHandler().getParent(node);
    056    }
    057
    058    @Override
    059    public List<T> getChildren(final T node)
    060    {
    061        return getDecoratedNodeHandler().getChildren(node);
    062    }
    063
    064    @Override
    065    public <C> List<T> getMatchingChildren(final T node, final NodeMatcher<C> matcher,
    066            final C criterion)
    067    {
    068        return getDecoratedNodeHandler().getMatchingChildren(node, matcher,
    069                criterion);
    070    }
    071
    072    @Override
    073    public <C> int getMatchingChildrenCount(final T node, final NodeMatcher<C> matcher,
    074            final C criterion)
    075    {
    076        return getDecoratedNodeHandler().getMatchingChildrenCount(node,
    077                matcher, criterion);
    078    }
    079
    080    @Override
    081    public List<T> getChildren(final T node, final String name)
    082    {
    083        return getDecoratedNodeHandler().getChildren(node, name);
    084    }
    085
    086    @Override
    087    public T getChild(final T node, final int index)
    088    {
    089        return getDecoratedNodeHandler().getChild(node, index);
    090    }
    091
    092    @Override
    093    public int indexOfChild(final T parent, final T child)
    094    {
    095        return getDecoratedNodeHandler().indexOfChild(parent, child);
    096    }
    097
    098    @Override
    099    public int getChildrenCount(final T node, final String name)
    100    {
    101        return getDecoratedNodeHandler().getChildrenCount(node, name);
    102    }
    103
    104    @Override
    105    public Set<String> getAttributes(final T node)
    106    {
    107        return getDecoratedNodeHandler().getAttributes(node);
    108    }
    109
    110    @Override
    111    public boolean hasAttributes(final T node)
    112    {
    113        return getDecoratedNodeHandler().hasAttributes(node);
    114    }
    115
    116    @Override
    117    public Object getAttributeValue(final T node, final String name)
    118    {
    119        return getDecoratedNodeHandler().getAttributeValue(node, name);
    120    }
    121
    122    @Override
    123    public boolean isDefined(final T node)
    124    {
    125        return getDecoratedNodeHandler().isDefined(node);
    126    }
    127
    128    @Override
    129    public T getRootNode()
    130    {
    131        return getDecoratedNodeHandler().getRootNode();
    132    }
    133
    134    /**
    135     * Returns the {@code NodeHandler} object that is decorated by this
    136     * instance. All method calls are delegated to this object.
    137     *
    138     * @return the decorated {@code NodeHandler}
    139     */
    140    protected abstract NodeHandler<T> getDecoratedNodeHandler();
    141}