當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。