org.nutz.ioc.aop.config.impl.AbstractAopConfigration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nutz Show documentation
Show all versions of nutz Show documentation
Nutz, which is a collections of lightweight frameworks, each of them can be used independently
package org.nutz.ioc.aop.config.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.nutz.aop.MethodInterceptor;
import org.nutz.aop.matcher.MethodMatcherFactory;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.aop.config.AopConfigration;
import org.nutz.ioc.aop.config.InterceptorPair;
import org.nutz.lang.Lang;
import org.nutz.lang.Mirror;
/**
*
*
* @author wendal([email protected])
*
*/
public abstract class AbstractAopConfigration implements AopConfigration {
private List aopItemList;
public List getInterceptorPairList(Ioc ioc, Class> clazz) {
List ipList = new ArrayList();
for (AopConfigrationItem aopItem : aopItemList) {
if (aopItem.matchClassName(clazz.getName()))
ipList.add(new InterceptorPair( getMethodInterceptor( ioc,
aopItem.getInterceptor(),
aopItem.isSingleton()),
MethodMatcherFactory.matcher(aopItem.getMethodName())));
}
return ipList;
}
public void setAopItemList(List aopItemList) {
this.aopItemList = aopItemList;
}
protected MethodInterceptor getMethodInterceptor( Ioc ioc,
String interceptorName,
boolean singleton) {
if (interceptorName.startsWith("ioc:"))
return ioc.get(MethodInterceptor.class, interceptorName.substring(4));
try {
if (singleton == false)
return (MethodInterceptor) Mirror.me(Lang.loadClass(interceptorName)).born();
MethodInterceptor methodInterceptor = cachedMethodInterceptor.get(interceptorName);
if (methodInterceptor == null) {
methodInterceptor = (MethodInterceptor) Mirror.me(Lang.loadClass(interceptorName)).born();
cachedMethodInterceptor.put(interceptorName, methodInterceptor);
}
return methodInterceptor;
}
catch (Throwable e) {
throw Lang.wrapThrow(e);
}
}
private HashMap cachedMethodInterceptor = new HashMap();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy