use of org.nutz.mvc.ActionInfo in project nutz by nutzam.
the class Loadings method createInfo.
public static ActionInfo createInfo(Class<?> type) {
ActionInfo ai = new ActionInfo();
evalEncoding(ai, Mirror.getAnnotationDeep(type, Encoding.class));
evalHttpAdaptor(ai, Mirror.getAnnotationDeep(type, AdaptBy.class));
evalActionFilters(ai, Mirror.getAnnotationDeep(type, Filters.class));
evalPathMap(ai, Mirror.getAnnotationDeep(type, PathMap.class));
evalOk(ai, Mirror.getAnnotationDeep(type, Ok.class));
evalFail(ai, Mirror.getAnnotationDeep(type, Fail.class));
evalAt(ai, Mirror.getAnnotationDeep(type, At.class), type.getSimpleName());
evalActionChainMaker(ai, Mirror.getAnnotationDeep(type, Chain.class));
evalModule(ai, type);
if (Mvcs.DISPLAY_METHOD_LINENUMBER) {
InputStream ins = type.getClassLoader().getResourceAsStream(type.getName().replace(".", "/") + ".class");
if (ins != null) {
try {
ClassMeta meta = ClassMetaReader.build(ins);
ai.setMeta(meta);
} catch (Exception e) {
}
}
}
return ai;
}
use of org.nutz.mvc.ActionInfo in project nutz by nutzam.
the class Loadings method createInfo.
public static ActionInfo createInfo(Method method) {
ActionInfo ai = new ActionInfo();
evalEncoding(ai, Mirror.getAnnotationDeep(method, Encoding.class));
evalHttpAdaptor(ai, Mirror.getAnnotationDeep(method, AdaptBy.class));
evalActionFilters(ai, Mirror.getAnnotationDeep(method, Filters.class));
evalOk(ai, Mirror.getAnnotationDeep(method, Ok.class));
evalFail(ai, Mirror.getAnnotationDeep(method, Fail.class));
evalAt(ai, Mirror.getAnnotationDeep(method, At.class), method.getName());
evalActionChainMaker(ai, Mirror.getAnnotationDeep(method, Chain.class));
evalHttpMethod(ai, method, Mirror.getAnnotationDeep(method, At.class));
ai.setMethod(method);
return ai;
}
use of org.nutz.mvc.ActionInfo in project nutz by nutzam.
the class NutLoading method evalUrlMapping.
protected UrlMapping evalUrlMapping(NutConfig config, Class<?> mainModule, Ioc ioc) throws Exception {
/*
* @ TODO 个人建议可以将这个方法所涉及的内容转换到Loadings类或相应的组装类中,
* 以便将本类加以隔离,使本的职责仅限于MVC整体的初使化,而不再负责UrlMapping的加载
*/
/*
* 准备 UrlMapping
*/
UrlMapping mapping = createUrlMapping(config);
if (log.isInfoEnabled())
log.infof("Build URL mapping by %s ...", mapping.getClass().getName());
/*
* 创建视图工厂
*/
ViewMaker[] makers = createViewMakers(mainModule, ioc);
/*
* 创建动作链工厂
*/
ActionChainMaker maker = createChainMaker(config, mainModule);
/*
* 创建主模块的配置信息
*/
ActionInfo mainInfo = Loadings.createInfo(mainModule);
/*
* 准备要加载的模块列表
*/
// TODO 为什么用Set呢? 用List不是更快吗?
Set<Class<?>> modules = Loadings.scanModules(ioc, mainModule);
if (modules.isEmpty()) {
if (log.isWarnEnabled())
log.warn("None module classes found!!!");
}
int atMethods = 0;
/*
* 分析所有的子模块
*/
for (Class<?> module : modules) {
ActionInfo moduleInfo = Loadings.createInfo(module).mergeWith(mainInfo);
for (Method method : module.getMethods()) {
if (!Modifier.isPublic(method.getModifiers()) || method.isBridge())
continue;
if (Mirror.getAnnotationDeep(method, At.class) == null)
continue;
// 增加到映射中
ActionInfo info = Loadings.createInfo(method).mergeWith(moduleInfo);
info.setViewMakers(makers);
mapping.add(maker, info, config);
atMethods++;
}
// 记录pathMap
if (null != moduleInfo.getPathMap()) {
for (Entry<String, String> en : moduleInfo.getPathMap().entrySet()) {
config.getAtMap().add(en.getKey(), en.getValue());
}
}
}
if (atMethods == 0) {
if (log.isWarnEnabled())
log.warn("None @At found in any modules class!!");
} else {
log.infof("Found %d module methods", atMethods);
}
config.setUrlMapping(mapping);
config.setActionChainMaker(maker);
config.setViewMakers(makers);
return mapping;
}
Aggregations