use of org.nutz.mvc.ActionChainMaker 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;
}
use of org.nutz.mvc.ActionChainMaker in project nutz by nutzam.
the class NutLoading method createChainMaker.
protected ActionChainMaker createChainMaker(NutConfig config, Class<?> mainModule) {
ChainBy ann = mainModule.getAnnotation(ChainBy.class);
ActionChainMaker maker = null == ann ? new NutActionChainMaker(new String[] {}) : Loadings.evalObj(config, ann.type(), ann.args());
if (log.isDebugEnabled())
log.debugf("@ChainBy(%s)", maker.getClass().getName());
return maker;
}
Aggregations