use of ren.yale.java.interceptor.Interceptor in project Summer by yale8848.
the class MethodsProcessor method getIntercepter.
private static Interceptor[] getIntercepter(Class<? extends Interceptor>[] inter) {
try {
Interceptor[] interceptors = new Interceptor[inter.length];
int i = 0;
for (Class<? extends Interceptor> cls : inter) {
Interceptor interceptor = cls.newInstance();
interceptors[i] = interceptor;
i++;
}
return interceptors;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of ren.yale.java.interceptor.Interceptor in project Summer by yale8848.
the class MethodsProcessor method get.
public static void get(List<ClassInfo> classInfos, Class clazz) {
Path path = (Path) clazz.getAnnotation(Path.class);
if (path == null || path.value() == null) {
return;
}
ClassInfo classInfo = new ClassInfo();
classInfo.setClassPath(path.value());
classInfo.setClazzObj(newClass(clazz));
classInfo.setClazz(clazz);
Interceptor[] interceptorsClazz = getBefores((Before) clazz.getAnnotation(Before.class));
if (interceptorsClazz != null) {
classInfo.setBefores(interceptorsClazz);
}
interceptorsClazz = getAfters((After) clazz.getAnnotation(After.class));
if (interceptorsClazz != null) {
classInfo.setAfters(interceptorsClazz);
}
for (Method method : clazz.getMethods()) {
Class mt = method.getDeclaringClass();
if (mt == Object.class) {
continue;
}
MethodInfo methodInfo = new MethodInfo();
Interceptor[] interceptorsMethod = getBefores((Before) method.getAnnotation(Before.class));
if (interceptorsMethod != null) {
methodInfo.setBefores(interceptorsMethod);
}
interceptorsMethod = getAfters((After) method.getAnnotation(After.class));
if (interceptorsMethod != null) {
methodInfo.setAfters(interceptorsMethod);
}
Blocking blocking = method.getAnnotation(Blocking.class);
if (blocking != null) {
methodInfo.setBlocking(true);
}
Path pathMthod = (Path) method.getAnnotation(Path.class);
Produces produces = (Produces) method.getAnnotation(Produces.class);
methodInfo.setMethodPath(getPathValue(pathMthod));
methodInfo.setProducesType(getProducesValue(produces));
methodInfo.setHttpMethod(getHttpMethod(method));
methodInfo.setMethod(method);
Parameter[] parameters = method.getParameters();
Class<?>[] parameterTypes = method.getParameterTypes();
Annotation[][] annotations = method.getParameterAnnotations();
int i = 0;
for (Annotation[] an : annotations) {
ArgInfo argInfo = new ArgInfo();
argInfo.setAnnotation(an);
argInfo.setClazz(parameterTypes[i]);
argInfo.setParameter(parameters[i]);
for (Annotation ant : an) {
if (ant instanceof Context) {
argInfo.setContext(true);
} else if (ant instanceof DefaultValue) {
argInfo.setDefaultValue(((DefaultValue) ant).value());
} else if (ant instanceof PathParam) {
argInfo.setPathParam(true);
argInfo.setPathParam(((PathParam) ant).value());
} else if (ant instanceof QueryParam) {
argInfo.setQueryParam(true);
argInfo.setQueryParam(((QueryParam) ant).value());
} else if (ant instanceof FormParam) {
argInfo.setFormParam(true);
argInfo.setFormParam(((FormParam) ant).value());
}
}
i++;
methodInfo.addArgInfo(argInfo);
}
classInfo.addMethodInfo(methodInfo);
}
classInfos.add(classInfo);
}
Aggregations