001    /*
002     * (c) 2003-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 23-May-2004
010     */
011    package com.thoughtworks.proxy.kit;
012    
013    import java.lang.reflect.Method;
014    
015    import com.thoughtworks.proxy.Invoker;
016    
017    
018    /**
019     * A simple {@link Invoker} implementation, that routes any call to a target object. A <code>null</code> value as
020     * target can be handled, the invocation result will always be <code>null</code>.
021     *
022     * @author Aslak Helles&oslash;y
023     * @since 0.2
024     */
025    public class SimpleInvoker implements Invoker {
026    
027        private static final long serialVersionUID = 1L;
028    
029        private Object target;
030    
031        /**
032         * Construct a SimpleInvoker.
033         *
034         * @param target the invocation target.
035         * @since 0.2
036         */
037        public SimpleInvoker(final Object target) {
038            this.target = target;
039        }
040    
041        public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
042            return (target == null ? null : method.invoke(target, args));
043        }
044    
045        /**
046         * Retrieve the target of the invocations.
047         *
048         * @return the target object
049         * @since 0.2
050         */
051        protected Object getTarget() {
052            return target;
053        }
054    }