panda.ioc.aop.impl.DefaultMirrors Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-glue Show documentation
Show all versions of panda-glue Show documentation
Panda Glue is a ASM/AOP module of the Panda Framework.
The newest version!
package panda.ioc.aop.impl;
import java.util.List;
import panda.aop.ClassAgent;
import panda.aop.ClassDefiner;
import panda.aop.DefaultClassDefiner;
import panda.aop.MethodInterceptor;
import panda.aop.asm.AsmClassAgent;
import panda.ioc.Ioc;
import panda.ioc.aop.Mirrors;
import panda.ioc.aop.config.AopConfigration;
import panda.ioc.aop.config.InterceptorPair;
import panda.ioc.aop.config.impl.AnnotationAopConfigration;
import panda.log.Log;
import panda.log.Logs;
/**
* 通过AopConfigration来识别需要拦截的方法,并根据需要生成新的类
*/
public class DefaultMirrors extends Mirrors {
private static final Log log = Logs.getLog(DefaultMirrors.class);
private ClassDefiner cd;
private AopConfigration aopConfigration;
@Override
public Class getMirror(Ioc ioc, Class type, String name) {
if (MethodInterceptor.class.isAssignableFrom(type)
|| type.getName().endsWith(ClassAgent.CLASSNAME_SUFFIX)
|| AopConfigration.IOCNAME.equals(name)
|| AopConfigration.class.isAssignableFrom(type)) {
return type;
}
if (aopConfigration == null) {
aopConfigration = ioc.getIfExists(AopConfigration.class, AopConfigration.IOCNAME);
}
if (aopConfigration == null) {
aopConfigration = new AnnotationAopConfigration();
}
List interceptorPairs = aopConfigration.getInterceptorPairList(ioc, type);
if (interceptorPairs == null || interceptorPairs.size() < 1) {
if (log.isDebugEnabled()) {
log.debugf("%s , no config to enable AOP.", type);
}
return type;
}
cd = DefaultClassDefiner.create();
ClassAgent agent = new AsmClassAgent();
for (InterceptorPair interceptorPair : interceptorPairs) {
agent.addInterceptor(interceptorPair.getMethodMatcher(), interceptorPair.getMethodInterceptor());
}
return agent.define(cd, type);
}
public void setAopConfigration(AopConfigration aopConfigration) {
this.aopConfigration = aopConfigration;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy