001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.aopalliance.intercept;
018
019/**
020 * Intercepts calls on an interface on its way to the target. These
021 * are nested "on top" of the target.
022 *
023 * <p>The user should implement the {@link #invoke(MethodInvocation)}
024 * method to modify the original behavior. E.g. the following class
025 * implements a tracing interceptor (traces all the calls on the
026 * intercepted method(s)):
027 *
028 * <pre class=code>
029 * class TracingInterceptor implements MethodInterceptor {
030 *   Object invoke(MethodInvocation i) throws Throwable {
031 *     System.out.println("method "+i.getMethod()+" is called on "+
032 *                        i.getThis()+" with args "+i.getArguments());
033 *     Object ret=i.proceed();
034 *     System.out.println("method "+i.getMethod()+" returns "+ret);
035 *     return ret;
036 *   }
037 * }
038 * </pre>
039 *
040 * @author Rod Johnson
041 */
042@FunctionalInterface
043public interface MethodInterceptor extends Interceptor {
044
045        /**
046         * Implement this method to perform extra treatments before and
047         * after the invocation. Polite implementations would certainly
048         * like to invoke {@link Joinpoint#proceed()}.
049         * @param invocation the method invocation joinpoint
050         * @return the result of the call to {@link Joinpoint#proceed()};
051         * might be intercepted by the interceptor
052         * @throws Throwable if the interceptors or the target object
053         * throws an exception
054         */
055        Object invoke(MethodInvocation invocation) throws Throwable;
056
057}