001    package groovy.lang;
002    
003    /**
004     * Implementers of this interface can be registered in the ProxyMetaClass for
005     * notifications about method calls for objects managed by the ProxyMetaClass.
006     * See groovy/lang/InterceptorTest.groovy for details.
007     * @author Dierk Koenig
008     */
009    public interface Interceptor {
010        /**
011         * This code is executed before the method is optionally called.
012         * @param object        receiver object for the method call
013         * @param methodName    name of the method to call
014         * @param arguments     arguments to the method call
015         * @return any arbitrary result that replaces the result of the
016         * original method call only if doInvoke() returns false and afterInvoke()
017         * relays this result.
018         */
019        Object beforeInvoke(Object object, String methodName, Object[] arguments);
020        /**
021         * This code is executed after the method is optionally called.
022         * @param object        receiver object for the called method
023         * @param methodName    name of the called method
024         * @param arguments     arguments to the called method
025         * @param result        result of the executed method call or result of beforeInvoke if method was not called
026         * @return any arbitrary result that can replace the result of the
027         * original method call. Typically, the result parameter is returned.
028         */
029        Object afterInvoke(Object object, String methodName, Object[] arguments, Object result);
030        /**
031         * @return whether the target method should be invoked at all.
032         */
033        boolean doInvoke();
034    }