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 * @since 2.0 035 * @param <T> the type of the nodes supported by this handler 036 */ 037public abstract class NodeHandlerDecorator<T> implements NodeHandler<T> 038{ 039 @Override 040 public String nodeName(final T node) 041 { 042 return getDecoratedNodeHandler().nodeName(node); 043 } 044 045 @Override 046 public Object getValue(final T node) 047 { 048 return getDecoratedNodeHandler().getValue(node); 049 } 050 051 @Override 052 public T getParent(final T node) 053 { 054 return getDecoratedNodeHandler().getParent(node); 055 } 056 057 @Override 058 public List<T> getChildren(final T node) 059 { 060 return getDecoratedNodeHandler().getChildren(node); 061 } 062 063 @Override 064 public <C> List<T> getMatchingChildren(final T node, final NodeMatcher<C> matcher, 065 final C criterion) 066 { 067 return getDecoratedNodeHandler().getMatchingChildren(node, matcher, 068 criterion); 069 } 070 071 @Override 072 public <C> int getMatchingChildrenCount(final T node, final NodeMatcher<C> matcher, 073 final C criterion) 074 { 075 return getDecoratedNodeHandler().getMatchingChildrenCount(node, 076 matcher, criterion); 077 } 078 079 @Override 080 public List<T> getChildren(final T node, final String name) 081 { 082 return getDecoratedNodeHandler().getChildren(node, name); 083 } 084 085 @Override 086 public T getChild(final T node, final int index) 087 { 088 return getDecoratedNodeHandler().getChild(node, index); 089 } 090 091 @Override 092 public int indexOfChild(final T parent, final T child) 093 { 094 return getDecoratedNodeHandler().indexOfChild(parent, child); 095 } 096 097 @Override 098 public int getChildrenCount(final T node, final String name) 099 { 100 return getDecoratedNodeHandler().getChildrenCount(node, name); 101 } 102 103 @Override 104 public Set<String> getAttributes(final T node) 105 { 106 return getDecoratedNodeHandler().getAttributes(node); 107 } 108 109 @Override 110 public boolean hasAttributes(final T node) 111 { 112 return getDecoratedNodeHandler().hasAttributes(node); 113 } 114 115 @Override 116 public Object getAttributeValue(final T node, final String name) 117 { 118 return getDecoratedNodeHandler().getAttributeValue(node, name); 119 } 120 121 @Override 122 public boolean isDefined(final T node) 123 { 124 return getDecoratedNodeHandler().isDefined(node); 125 } 126 127 @Override 128 public T getRootNode() 129 { 130 return getDecoratedNodeHandler().getRootNode(); 131 } 132 133 /** 134 * Returns the {@code NodeHandler} object that is decorated by this 135 * instance. All method calls are delegated to this object. 136 * 137 * @return the decorated {@code NodeHandler} 138 */ 139 protected abstract NodeHandler<T> getDecoratedNodeHandler(); 140}