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.springframework.aop; 018 019import org.springframework.lang.Nullable; 020 021/** 022 * A {@code TargetSource} is used to obtain the current "target" of 023 * an AOP invocation, which will be invoked via reflection if no around 024 * advice chooses to end the interceptor chain itself. 025 * 026 * <p>If a {@code TargetSource} is "static", it will always return 027 * the same target, allowing optimizations in the AOP framework. Dynamic 028 * target sources can support pooling, hot swapping, etc. 029 * 030 * <p>Application developers don't usually need to work with 031 * {@code TargetSources} directly: this is an AOP framework interface. 032 * 033 * @author Rod Johnson 034 * @author Juergen Hoeller 035 */ 036public interface TargetSource extends TargetClassAware { 037 038 /** 039 * Return the type of targets returned by this {@link TargetSource}. 040 * <p>Can return {@code null}, although certain usages of a {@code TargetSource} 041 * might just work with a predetermined target class. 042 * @return the type of targets returned by this {@link TargetSource} 043 */ 044 @Override 045 @Nullable 046 Class<?> getTargetClass(); 047 048 /** 049 * Will all calls to {@link #getTarget()} return the same object? 050 * <p>In that case, there will be no need to invoke {@link #releaseTarget(Object)}, 051 * and the AOP framework can cache the return value of {@link #getTarget()}. 052 * @return {@code true} if the target is immutable 053 * @see #getTarget 054 */ 055 boolean isStatic(); 056 057 /** 058 * Return a target instance. Invoked immediately before the 059 * AOP framework calls the "target" of an AOP method invocation. 060 * @return the target object which contains the joinpoint, 061 * or {@code null} if there is no actual target instance 062 * @throws Exception if the target object can't be resolved 063 */ 064 @Nullable 065 Object getTarget() throws Exception; 066 067 /** 068 * Release the given target object obtained from the 069 * {@link #getTarget()} method, if any. 070 * @param target object obtained from a call to {@link #getTarget()} 071 * @throws Exception if the object can't be released 072 */ 073 void releaseTarget(Object target) throws Exception; 074 075}