Search in sources :

Example 1 with ActionInfo

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;
}
Also used : Chain(org.nutz.mvc.annotation.Chain) Filters(org.nutz.mvc.annotation.Filters) At(org.nutz.mvc.annotation.At) InputStream(java.io.InputStream) ClassMeta(org.nutz.lang.util.ClassMeta) ActionInfo(org.nutz.mvc.ActionInfo) Encoding(org.nutz.mvc.annotation.Encoding) AdaptBy(org.nutz.mvc.annotation.AdaptBy) PathMap(org.nutz.mvc.annotation.PathMap) Ok(org.nutz.mvc.annotation.Ok) Fail(org.nutz.mvc.annotation.Fail)

Example 2 with ActionInfo

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;
}
Also used : Chain(org.nutz.mvc.annotation.Chain) Filters(org.nutz.mvc.annotation.Filters) At(org.nutz.mvc.annotation.At) ActionInfo(org.nutz.mvc.ActionInfo) Encoding(org.nutz.mvc.annotation.Encoding) AdaptBy(org.nutz.mvc.annotation.AdaptBy) Ok(org.nutz.mvc.annotation.Ok) Fail(org.nutz.mvc.annotation.Fail)

Example 3 with ActionInfo

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;
}
Also used : UrlMapping(org.nutz.mvc.UrlMapping) ActionChainMaker(org.nutz.mvc.ActionChainMaker) ActionInfo(org.nutz.mvc.ActionInfo) Method(java.lang.reflect.Method) At(org.nutz.mvc.annotation.At) DefaultViewMaker(org.nutz.mvc.view.DefaultViewMaker) ViewMaker(org.nutz.mvc.ViewMaker)

Aggregations

ActionInfo (org.nutz.mvc.ActionInfo)3 At (org.nutz.mvc.annotation.At)3 AdaptBy (org.nutz.mvc.annotation.AdaptBy)2 Chain (org.nutz.mvc.annotation.Chain)2 Encoding (org.nutz.mvc.annotation.Encoding)2 Fail (org.nutz.mvc.annotation.Fail)2 Filters (org.nutz.mvc.annotation.Filters)2 Ok (org.nutz.mvc.annotation.Ok)2 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 ClassMeta (org.nutz.lang.util.ClassMeta)1 ActionChainMaker (org.nutz.mvc.ActionChainMaker)1 UrlMapping (org.nutz.mvc.UrlMapping)1 ViewMaker (org.nutz.mvc.ViewMaker)1 PathMap (org.nutz.mvc.annotation.PathMap)1 DefaultViewMaker (org.nutz.mvc.view.DefaultViewMaker)1