001 /*
002 * Created on Mar 19, 2012
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005 * the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011 * specific language governing permissions and limitations under the License.
012 *
013 * Copyright @2006-2009 the original author or authors.
014 */
015 package org.fest.reflect.field.decorator;
016
017 import java.lang.reflect.InvocationTargetException;
018 import java.lang.reflect.Method;
019
020
021 /**
022 * A proxy for pre-decorating a field
023 * @author Ivan Hristov
024 *
025 */
026 public class PreDecorator<T> extends DecoratorInvocationHandler<T> {
027
028 public PreDecorator(T target, T decorator) {
029 super(target, decorator);
030 }
031
032 @Override protected Object invokeFirst(Method method, Object[] args) throws IllegalArgumentException,
033 IllegalAccessException, InvocationTargetException {
034 return method.invoke(getDecorator(), args);
035 }
036
037 @Override protected Object invokeSecond(Method method, Object[] args) throws IllegalArgumentException,
038 IllegalAccessException, InvocationTargetException {
039 return method.invoke(getTarget(), args);
040 }
041
042 @Override protected Object getResult(Object firstResult, Object secondResult) {
043 return shouldReturnDecoratorResult() ? firstResult : secondResult;
044 }
045 }