Java Code Examples for com.jfinal.template.Engine#addSharedMethod()

The following examples show how to use com.jfinal.template.Engine#addSharedMethod() . 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: AppJbootServiceImplGenerator.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forServiceImpl");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example 2
Source File: JbootServiceInterfaceGenerator.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forService");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example 3
Source File: ServiceApiGenerator.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forService");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example 4
Source File: ServiceProviderGenerator.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate base model ...");
    System.out.println("Base Model Output Dir: " + baseModelOutputDir);

    Engine engine = Engine.create("forServiceImpl");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", javaKeyword);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example 5
Source File: JbootServiceImplGenerator.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void generate(List<TableMeta> tableMetas) {
    System.out.println("Generate Service Impl ...");
    System.out.println("Service Impl Output Dir: " + outputDir);

    Engine engine = Engine.create("forServiceImpl");
    engine.setSourceFactory(new ClassPathSourceFactory());
    engine.addSharedMethod(new StrKit());
    engine.addSharedObject("getterTypeMap", getterTypeMap);
    engine.addSharedObject("javaKeyword", JavaKeyword.me);

    for (TableMeta tableMeta : tableMetas) {
        genBaseModelContent(tableMeta);
    }
    writeToFile(tableMetas);
}
 
Example 6
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 7
Source File: ModuleGenerator.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void genPomXml() {

        String modulePath = basePath;
        String modelPath = basePath + "/module-" + moduleName + "-model";
        String webPath = basePath + "/module-" + moduleName + "-web";
        String serviceApiPath = basePath + "/module-" + moduleName + "-service-api";
        String serviceProviderPath = basePath + "/module-" + moduleName + "-service-provider";


        File modelFile = new File(modelPath);
        File webFile = new File(webPath);
        File serviceApiFile = new File(serviceApiPath);
        File serviceProviderFile = new File(serviceProviderPath);

        makeSrcDirectory(modelFile);
        makeSrcDirectory(webFile);
        makeSrcDirectory(serviceApiFile);
        makeSrcDirectory(serviceProviderFile);

        Map map = new HashMap();
        map.put("moduleName", moduleName);
        Engine engine = new Engine();
        engine.setToClassPathSourceFactory();    // 从 class path 内读模板文件
        engine.addSharedMethod(new StrKit());

        File modulePomXmlFile = new File(modulePath, "pom.xml");
        if (!modulePomXmlFile.exists()) {
            engine.getTemplate("io/jpress/codegen/templates/pom_module_template.jf").render(map, modulePomXmlFile);
        }

        File modelPomXmlFile = new File(modelFile, "pom.xml");
        if (!modelPomXmlFile.exists()) {
            engine.getTemplate("io/jpress/codegen/templates/pom_model_template.jf").render(map, modelPomXmlFile);
        }

        File webPomXmlFile = new File(webFile, "pom.xml");
        if (!webPomXmlFile.exists()) {
            engine.getTemplate("io/jpress/codegen/templates/pom_web_template.jf").render(map, webPomXmlFile);
        }

        File serviceApiPomXmlFile = new File(serviceApiFile, "pom.xml");
        if (!serviceApiPomXmlFile.exists()) {
            engine.getTemplate("io/jpress/codegen/templates/pom_service_api_template.jf").render(map, serviceApiPomXmlFile);
        }

        File serviceProviderPomXmlFile = new File(serviceProviderFile, "pom.xml");
        if (!serviceProviderPomXmlFile.exists()) {
            engine.getTemplate("io/jpress/codegen/templates/pom_service_provider_template.jf").render(map, serviceProviderPomXmlFile);
        }

    }