当前位置: 首页>>代码示例>>Java>>正文


Java Binding.setProperty方法代码示例

本文整理汇总了Java中groovy.lang.Binding.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java Binding.setProperty方法的具体用法?Java Binding.setProperty怎么用?Java Binding.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在groovy.lang.Binding的用法示例。


在下文中一共展示了Binding.setProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
public void run(CommandLine line, ToolRunningContext context) throws Exception {
    Path file = context.getFileSystem().getPath(line.getOptionValue(FILE));
    Writer writer = new OutputStreamWriter(context.getOutputStream());
    try {
        AppLogger logger = new AppLogger() {
            @Override
            public void log(String message, Object... args) {
                context.getOutputStream().println(String.format(message, args));
            }

            @Override
            public AppLogger tagged(String tag) {
                return this;
            }
        };
        try (AppData data = new AppData(context.getComputationManager(), fileSystemProviders,
                fileExtensions, projectFileExtensions, serviceExtensions, () -> logger)) {
            if (file.getFileName().toString().endsWith(".groovy")) {
                try {
                    Binding binding = new Binding();
                    binding.setProperty("args", line.getArgs());
                    GroovyScripts.run(file, data, binding, writer);
                } catch (Throwable t) {
                    Throwable rootCause = StackTraceUtils.sanitizeRootCause(t);
                    rootCause.printStackTrace(context.getErrorStream());
                }
            } else {
                throw new IllegalArgumentException("Script type not supported");
            }
        }
    } finally {
        writer.flush();
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:36,代码来源:RunScriptTool.java

示例2: init

import groovy.lang.Binding; //导入方法依赖的package包/类
@PostConstruct
public void init() {
    ImportCustomizer importCustomizer = new ImportCustomizer();
    importCustomizer.addStarImports("net.dv8tion.jda.core.entities");

    configuration = new CompilerConfiguration();
    configuration.addCompilationCustomizers(importCustomizer);

    sharedData = new Binding();
    sharedData.setProperty("ctx", context);
    sharedData.setProperty("jda", discordService.getJda());
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:13,代码来源:GroovyService.java

示例3: createBinding

import groovy.lang.Binding; //导入方法依赖的package包/类
private Binding createBinding() {
    Binding binding = new Binding();
    binding.setProperty("service", hostServices);
    binding.setProperty("targets", hostServices.getTargets());
    for (Map.Entry<String, Object> entry : variables.entrySet()) {
        binding.setProperty(entry.getKey(), entry.getValue());
    }
    return binding;
}
 
开发者ID:devent,项目名称:robobee-osgi,代码行数:10,代码来源:ParserImpl.java

示例4: reloadAppFolders

import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
public List<AppFolder> reloadAppFolders(List<AppFolder> folders) {
    log.debug("Reloading AppFolders {}", folders);

    StopWatch stopWatch = new Slf4JStopWatch("AppFolders");
    stopWatch.start();

    try {
        if (!folders.isEmpty()) {
            Binding binding = new Binding();
            binding.setVariable("persistence", persistence);
            binding.setVariable("metadata", metadata);
            binding.setProperty("userSession", userSessionSource.getUserSession());

            for (AppFolder folder : folders) {
                Transaction tx = persistence.createTransaction();
                try {
                    if (loadFolderQuantity(binding, folder)) {
                        tx.commit();
                    }
                } finally {
                    tx.end();
                }
            }
        }

        return folders;
    } finally {
        stopWatch.stop();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:32,代码来源:FoldersServiceBean.java

示例5: executeGroovyScript

import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
protected boolean executeGroovyScript(final ScriptResource file) {
    Binding bind = new Binding();
    bind.setProperty("ds", getDataSource());
    bind.setProperty("log", LoggerFactory.getLogger(String.format("%s$%s", DbUpdaterEngine.class.getName(),
            StringUtils.removeEndIgnoreCase(file.getName(), ".groovy"))));
    if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + UPGRADE_GROOVY_EXTENSION)) {
        bind.setProperty("postUpdate", new PostUpdateScripts() {
            @Override
            public void add(Closure closure) {
                postUpdateScripts.put(closure, file);

                postUpdate.add(closure);
            }

            @Override
            public List<Closure> getUpdates() {
                return postUpdate.getUpdates();
            }
        });
    }

    try {
        scripting.evaluateGroovy(file.getContent(), bind, ScriptExecutionPolicy.DO_NOT_USE_COMPILE_CACHE);
    } catch (Exception e) {
        throw new RuntimeException(ERROR + "Error executing Groovy script " + file.name + "\n" + e.getMessage(), e);
    }
    return !postUpdateScripts.containsValue(file);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:30,代码来源:DbUpdaterImpl.java

示例6: executeGroovyScript

import groovy.lang.Binding; //导入方法依赖的package包/类
protected boolean executeGroovyScript(ScriptResource file) {
    try {
        ClassLoader classLoader = getClass().getClassLoader();
        CompilerConfiguration cc = new CompilerConfiguration();
        cc.setRecompileGroovySource(true);

        Binding bind = new Binding();
        bind.setProperty("ds", getDataSource());
        bind.setProperty("log", LoggerFactory.getLogger(String.format("%s$%s", DbUpdaterEngine.class.getName(),
                StringUtils.removeEndIgnoreCase(file.getName(), ".groovy"))));
        if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + UPGRADE_GROOVY_EXTENSION)) {
            bind.setProperty("postUpdate", new PostUpdateScripts() {
                @Override
                public void add(Closure closure) {
                    super.add(closure);

                    log.warn("Added post update action will be ignored");
                }
            });
        }

        GroovyShell shell = new GroovyShell(classLoader, bind, cc);
        //noinspection UnnecessaryLocalVariable
        Script script = shell.parse(file.getContent());
        script.run();
    } catch (Exception e) {
        throw new RuntimeException(ERROR + "Error executing Groovy script " + file.name + "\n" + e.getMessage(), e);
    }
    return true;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:31,代码来源:DbUpdaterEngine.java


注:本文中的groovy.lang.Binding.setProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。