/** * Create a new advisor for this DeclareParents field. * @param interfaceType static field defining the introduction * @param typePattern type pattern the introduction is restricted to * @param defaultImpl the default implementation class */ public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> defaultImpl) { this(interfaceType, typePattern, new DelegatePerTargetObjectIntroductionInterceptor(defaultImpl, interfaceType)); }
public DelegatePerTargetObjectIntroductionInterceptor(Class<?> defaultImplType, Class<?> interfaceType) { this.defaultImplType = defaultImplType; this.interfaceType = interfaceType; // Create a new delegate now (but don't store it in the map). // We do this for two reasons: // 1) to fail early if there is a problem instantiating delegates // 2) to populate the interface map once and once only Object delegate = createNewDelegate(); implementInterfacesOnObject(delegate); suppressInterface(IntroductionInterceptor.class); suppressInterface(DynamicIntroductionAdvice.class); }
/** * Subclasses may need to override this if they want to perform custom * behaviour in around advice. However, subclasses should invoke this * method, which handles introduced interfaces and forwarding to the target. */ @Override @Nullable public Object invoke(MethodInvocation mi) throws Throwable { if (isMethodOnIntroducedInterface(mi)) { Object delegate = getIntroductionDelegateFor(mi.getThis()); // Using the following method rather than direct reflection, // we get correct handling of InvocationTargetException // if the introduced method throws an exception. Object retVal = AopUtils.invokeJoinpointUsingReflection(delegate, mi.getMethod(), mi.getArguments()); // Massage return value if possible: if the delegate returned itself, // we really want to return the proxy. if (retVal == delegate && mi instanceof ProxyMethodInvocation) { retVal = ((ProxyMethodInvocation) mi).getProxy(); } return retVal; } return doProceed(mi); }
private Object getIntroductionDelegateFor(Object targetObject) { synchronized (this.delegateMap) { if (this.delegateMap.containsKey(targetObject)) { return this.delegateMap.get(targetObject); } else { Object delegate = createNewDelegate(); this.delegateMap.put(targetObject, delegate); return delegate; } } }
private Object getIntroductionDelegateFor(Object targetObject) { synchronized (this.delegateMap) { if (this.delegateMap.containsKey(targetObject)) { return this.delegateMap.get(targetObject); } else { Object delegate = createNewDelegate(); this.delegateMap.put(targetObject, delegate); return delegate; } } }
public DelegatePerTargetObjectIntroductionInterceptor(Class<?> defaultImplType, Class<?> interfaceType) { this.defaultImplType = defaultImplType; this.interfaceType = interfaceType; // Create a new delegate now (but don't store it in the map). // We do this for two reasons: // 1) to fail early if there is a problem instantiating delegates // 2) to populate the interface map once and once only Object delegate = createNewDelegate(); implementInterfacesOnObject(delegate); suppressInterface(IntroductionInterceptor.class); suppressInterface(DynamicIntroductionAdvice.class); }
/** * Subclasses may need to override this if they want to perform custom * behaviour in around advice. However, subclasses should invoke this * method, which handles introduced interfaces and forwarding to the target. */ @Override public Object invoke(MethodInvocation mi) throws Throwable { if (isMethodOnIntroducedInterface(mi)) { Object delegate = getIntroductionDelegateFor(mi.getThis()); // Using the following method rather than direct reflection, // we get correct handling of InvocationTargetException // if the introduced method throws an exception. Object retVal = AopUtils.invokeJoinpointUsingReflection(delegate, mi.getMethod(), mi.getArguments()); // Massage return value if possible: if the delegate returned itself, // we really want to return the proxy. if (retVal == delegate && mi instanceof ProxyMethodInvocation) { retVal = ((ProxyMethodInvocation) mi).getProxy(); } return retVal; } return doProceed(mi); }
private Object getIntroductionDelegateFor(Object targetObject) { synchronized (this.delegateMap) { if (this.delegateMap.containsKey(targetObject)) { return this.delegateMap.get(targetObject); } else { Object delegate = createNewDelegate(); this.delegateMap.put(targetObject, delegate); return delegate; } } }
/** * Create a new advisor for this DeclareParents field. * @param interfaceType static field defining the introduction * @param typePattern type pattern the introduction is restricted to * @param defaultImpl the default implementation class */ public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> defaultImpl) { this(interfaceType, typePattern, new DelegatePerTargetObjectIntroductionInterceptor(defaultImpl, interfaceType)); }
public DelegatePerTargetObjectIntroductionInterceptor(Class<?> defaultImplType, Class<?> interfaceType) { this.defaultImplType = defaultImplType; this.interfaceType = interfaceType; // Create a new delegate now (but don't store it in the map). // We do this for two reasons: // 1) to fail early if there is a problem instantiating delegates // 2) to populate the interface map once and once only Object delegate = createNewDelegate(); implementInterfacesOnObject(delegate); suppressInterface(IntroductionInterceptor.class); suppressInterface(DynamicIntroductionAdvice.class); }
/** * Subclasses may need to override this if they want to perform custom * behaviour in around advice. However, subclasses should invoke this * method, which handles introduced interfaces and forwarding to the target. */ @Override @Nullable public Object invoke(MethodInvocation mi) throws Throwable { if (isMethodOnIntroducedInterface(mi)) { Object delegate = getIntroductionDelegateFor(mi.getThis()); // Using the following method rather than direct reflection, // we get correct handling of InvocationTargetException // if the introduced method throws an exception. Object retVal = AopUtils.invokeJoinpointUsingReflection(delegate, mi.getMethod(), mi.getArguments()); // Massage return value if possible: if the delegate returned itself, // we really want to return the proxy. if (retVal == delegate && mi instanceof ProxyMethodInvocation) { retVal = ((ProxyMethodInvocation) mi).getProxy(); } return retVal; } return doProceed(mi); }
/** * Create a new advisor for this DeclareParents field. * @param interfaceType static field defining the introduction * @param typePattern type pattern the introduction is restricted to * @param defaultImpl the default implementation class */ public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> defaultImpl) { this(interfaceType, typePattern, new DelegatePerTargetObjectIntroductionInterceptor(defaultImpl, interfaceType)); }