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 delegating to another instance. This is 028 * convenient if specific functionality of a {@code NodeHandler} is to be adapted for a special use case. Concrete sub 029 * classes have to implement the {@code getDecoratedNodeHandler()} method to provide the underlying handler. 030 * </p> 031 * 032 * @since 2.0 033 * @param <T> the type of the nodes supported by this handler 034 */ 035public abstract class NodeHandlerDecorator<T> implements NodeHandler<T> { 036 @Override 037 public String nodeName(final T node) { 038 return getDecoratedNodeHandler().nodeName(node); 039 } 040 041 @Override 042 public Object getValue(final T node) { 043 return getDecoratedNodeHandler().getValue(node); 044 } 045 046 @Override 047 public T getParent(final T node) { 048 return getDecoratedNodeHandler().getParent(node); 049 } 050 051 @Override 052 public List<T> getChildren(final T node) { 053 return getDecoratedNodeHandler().getChildren(node); 054 } 055 056 @Override 057 public <C> List<T> getMatchingChildren(final T node, final NodeMatcher<C> matcher, final C criterion) { 058 return getDecoratedNodeHandler().getMatchingChildren(node, matcher, criterion); 059 } 060 061 @Override 062 public <C> int getMatchingChildrenCount(final T node, final NodeMatcher<C> matcher, final C criterion) { 063 return getDecoratedNodeHandler().getMatchingChildrenCount(node, matcher, criterion); 064 } 065 066 @Override 067 public List<T> getChildren(final T node, final String name) { 068 return getDecoratedNodeHandler().getChildren(node, name); 069 } 070 071 @Override 072 public T getChild(final T node, final int index) { 073 return getDecoratedNodeHandler().getChild(node, index); 074 } 075 076 @Override 077 public int indexOfChild(final T parent, final T child) { 078 return getDecoratedNodeHandler().indexOfChild(parent, child); 079 } 080 081 @Override 082 public int getChildrenCount(final T node, final String name) { 083 return getDecoratedNodeHandler().getChildrenCount(node, name); 084 } 085 086 @Override 087 public Set<String> getAttributes(final T node) { 088 return getDecoratedNodeHandler().getAttributes(node); 089 } 090 091 @Override 092 public boolean hasAttributes(final T node) { 093 return getDecoratedNodeHandler().hasAttributes(node); 094 } 095 096 @Override 097 public Object getAttributeValue(final T node, final String name) { 098 return getDecoratedNodeHandler().getAttributeValue(node, name); 099 } 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}