package org.theonefx.wcframework.aop; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.theonefx.wcframework.aop.annotation.InterceptType; import org.theonefx.wcframework.aop.exception.AopMetadataException; public class AdvisorInfo { private String ref; /** * 切入点:ID=>Pointcut */ private Map<String, Pointcut> pointcuts = new HashMap<String, Pointcut>(); private List<AdviceHolder> holders = new ArrayList<AdvisorInfo.AdviceHolder>(); public String getRef() { return ref; } public void setRef(String ref) { this.ref = ref; } public List<AdviceHolder> getHolders() { return holders; } public Map<String, Pointcut> getPointcuts() { return pointcuts; } public void addPointcut(String id, Pointcut pointcut) { pointcuts.put(id, pointcut); } public void addAdviceHolder(String method, InterceptType type, String pointcutId, String[] ignoreExceptions) { AdviceHolder holder = new AdviceHolder(); holder.setMethod(method); holder.setType(type); holder.setPointcutId(pointcutId); if (ignoreExceptions != null && ignoreExceptions.length > 0) { Class<?>[] ignoreExceptionClasses = new Class<?>[ignoreExceptions.length]; for(int i = 0;i<ignoreExceptions.length;i++){ String s = ignoreExceptions[i]; try { ignoreExceptionClasses[i] = Class.forName(s); } catch (ClassNotFoundException e) { throw new AopMetadataException("找不到'" + s + "'的异常"); } } holder.setIgnoreException(ignoreExceptionClasses); } holders.add(holder); } public static class AdviceHolder { private String method; private InterceptType type; private String pointcutId; private Class<?>[] ignoreException; public Class<?>[] getIgnoreException() { return ignoreException; } public void setIgnoreException(Class<?>[] ignoreException) { this.ignoreException = ignoreException; } public String getMethod() { return method; } public void setMethod(String method) { this.method = method; } public InterceptType getType() { return type; } public void setType(InterceptType type) { this.type = type; } public String getPointcutId() { return pointcutId; } public void setPointcutId(String pointcutId) { this.pointcutId = pointcutId; } } }