001 /* 002 * (c) 2005, 2009, 2010 ThoughtWorks Ltd 003 * All rights reserved. 004 * 005 * The software in this package is published under the terms of the BSD 006 * style license a copy of which has been included with this distribution in 007 * the LICENSE.txt file. 008 * 009 * Created on 21-Jul-2005 010 */ 011 package com.thoughtworks.proxy.kit; 012 013 import java.lang.reflect.Method; 014 015 016 /** 017 * An Invoker that is able to call protected and private methods. If the proxies type is an abstract class, it might be 018 * necessary to use an PrivateInvoker instead of a SimpleInvoker. Otherwise the method implementations may not call the 019 * protected or private methods of the own type. 020 * 021 * @author Jörg Schaible 022 * @since 0.2 023 */ 024 public class PrivateInvoker extends SimpleInvoker { 025 026 private static final long serialVersionUID = 1L; 027 028 /** 029 * Construct a PrivateInvoker. 030 * 031 * @param target the invocation target. 032 * @since 0.2 033 */ 034 public PrivateInvoker(final Object target) { 035 super(target); 036 } 037 038 @Override 039 public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { 040 if (getTarget() != null && !method.isAccessible()) { 041 method.setAccessible(true); 042 } 043 return super.invoke(proxy, method, args); 044 } 045 046 }