io.jboot.web.directive.annotation.JFinalDirective Java Examples

The following examples show how to use io.jboot.web.directive.annotation.JFinalDirective. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JbootCoreConfig.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
public void configEngine(Engine engine) {

    //通过 java -jar xxx.jar 在单独的jar里运行
    if (runInFatjar()) {
        engine.setToClassPathSourceFactory();
        engine.setBaseTemplatePath("webapp");
    }

    List<Class> directiveClasses = ClassScanner.scanClass();
    for (Class clazz : directiveClasses) {
        JFinalDirective directive = (JFinalDirective) clazz.getAnnotation(JFinalDirective.class);
        if (directive != null) {
            engine.addDirective(AnnotationUtil.get(directive.value()), clazz);
        }

        JFinalSharedMethod sharedMethod = (JFinalSharedMethod) clazz.getAnnotation(JFinalSharedMethod.class);
        if (sharedMethod != null) {
            engine.addSharedMethod(ClassUtil.newInstance(clazz));
        }

        JFinalSharedStaticMethod sharedStaticMethod = (JFinalSharedStaticMethod) clazz.getAnnotation(JFinalSharedStaticMethod.class);
        if (sharedStaticMethod != null) {
            engine.addSharedStaticMethod(clazz);
        }

        JFinalSharedObject sharedObject = (JFinalSharedObject) clazz.getAnnotation(JFinalSharedObject.class);
        if (sharedObject != null) {
            engine.addSharedObject(AnnotationUtil.get(sharedObject.value()), ClassUtil.newInstance(clazz));
        }
    }

    JbootAppListenerManager.me().onEngineConfig(engine);
}
 
Example #2
Source File: AddonManager.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addDirectives(AddonInfo addonInfo) {
    List<Class<? extends Directive>> directives = addonInfo.getDirectives();
    if (directives != null) {
        for (Class<? extends Directive> c : directives) {
            JFinalDirective ann = c.getAnnotation(JFinalDirective.class);
            String directiveName = AnnotationUtil.get(ann.value());
            // 先移除,后添加,若有相同指令的情况下,
            // 后安装的插件会替换掉已经存在的指令
            RenderManager.me().getEngine().removeDirective(directiveName);
            RenderManager.me().getEngine().addDirective(directiveName, c);
        }
    }
}
 
Example #3
Source File: AddonManager.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void deleteDirectives(AddonInfo addonInfo) {
    List<Class<? extends Directive>> directives = addonInfo.getDirectives();
    if (directives != null) {
        for (Class<? extends Directive> c : directives) {
            JFinalDirective ann = c.getAnnotation(JFinalDirective.class);
            RenderManager.me().getEngine().removeDirective(AnnotationUtil.get(ann.value()));
        }
    }
}
 
Example #4
Source File: AddonInfo.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void addDirective(Class<? extends Directive> clazz) {
    JFinalDirective directive = clazz.getAnnotation(JFinalDirective.class);
    if (directive == null) {
        return;
    }
    if (directives == null) {
        directives = new ArrayList<>();
    }
    directives.add(clazz);
}