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


Java ResourceException类代码示例

本文整理汇总了Java中groovy.util.ResourceException的典型用法代码示例。如果您正苦于以下问题:Java ResourceException类的具体用法?Java ResourceException怎么用?Java ResourceException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: doEnsureDelegate

import groovy.util.ResourceException; //导入依赖的package包/类
private PortofinoRealm doEnsureDelegate()
        throws ScriptException, ResourceException, IllegalAccessException, InstantiationException {
    Class<?> scriptClass = groovyScriptEngine.loadScriptByName(scriptUrl);
    if(scriptClass.isInstance(security)) { //Class did not change
        return security;
    } else {
        logger.info("Refreshing Portofino Realm Delegate instance (Security.groovy)");
        if(security != null) {
            logger.debug("Script class changed: from " + security.getClass() + " to " + scriptClass);
        }
        Object securityTemp = scriptClass.newInstance();
        if(securityTemp instanceof PortofinoRealm) {
            PortofinoRealm realm = (PortofinoRealm) securityTemp;
            configureDelegate(realm);
            PortofinoRealm oldSecurity = security;
            security = realm;
            LifecycleUtils.destroy(oldSecurity);
            return realm;
        } else {
             throw new ClassCastException(
                     "Security object is not an instance of " + PortofinoRealm.class + ": " + securityTemp +
                     " (" + securityTemp.getClass().getSuperclass() + " " +
                     Arrays.asList(securityTemp.getClass().getInterfaces()) + ")");
        }
    }
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:27,代码来源:SecurityGroovyRealm.java

示例2: testGroovyScriptEngineVsGroovyShell

import groovy.util.ResourceException; //导入依赖的package包/类
public void testGroovyScriptEngineVsGroovyShell() throws IOException, ResourceException, ScriptException {
    // @todo refactor this path
    File currentDir = new File("./src/test/groovy/bugs");
    String file = "bug1567_script.groovy";

    Binding binding = new Binding();
    GroovyShell shell = new GroovyShell(binding);
    String[] test = null;
    Object result = shell.run(new File(currentDir, file), test);

    String[] roots = new String[]{currentDir.getAbsolutePath()};
    GroovyScriptEngine gse = new GroovyScriptEngine(roots);
    binding = new Binding();
    // a MME was ensued here stating no 't.start()' was available
    // in the script
    gse.run(file, binding);
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:Groovy1567_Bug.java

示例3: execute

import groovy.util.ResourceException; //导入依赖的package包/类
/**
 * Triggers thee execution of SJS compilation.
 *
 * @throws MojoExecutionException
 *     whenever an unexpected error occurs when executing mojo.
 */
@Override
public void execute() throws MojoExecutionException {
  if (isChangeDetected()) {
    try {
      runSjsCompilation();
    } catch (IOException | DependencyResolutionRequiredException | ScriptException | ResourceException ex) {
      throw new MojoExecutionException(
          "An unexpected exception occurred when running SJS compilation.", ex);
    }
  } else {
    getLog().info("No change detected. Skipping generation.");
  }
  Resource outputResource = new Resource();
  outputResource.setDirectory(outputDir.getPath());
  project.addResource(outputResource);
}
 
开发者ID:jspresso,项目名称:jspresso-ce,代码行数:23,代码来源:SjsMojo.java

示例4: main

import groovy.util.ResourceException; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    if(args.length != 1) {
        printUsage("Not enough arguments");
    }
    new ScriptRunner(new ResourceConnector() {
        
        @Override
        public URLConnection getResourceConnection(String name)
                throws ResourceException {
            try {
                return new URL("file://" + name).openConnection();
            } catch (IOException e) {
                throw new ResourceException(e);
            }
        }
    }).run(args[0]);
}
 
开发者ID:arquillian,项目名称:arquillian-script,代码行数:18,代码来源:ScriptRunner.java

示例5: getResourceConnection

import groovy.util.ResourceException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public URLConnection getResourceConnection(String scriptName) throws ResourceException {
    try {
        return new LepResourceKeyURLConnection(mapper.map(scriptName),
                                               managerService.getResourceService(),
                                               managerService);
    } catch (Exception e) {
        // FIXME add logging (GroovyScriptEngine eats ResourceException's...) !!!
        throw new ResourceException("Error while building "
                                        + LepResourceKeyURLConnection.class.getSimpleName()
                                        + ": " + e.getMessage(), e);
    }
}
 
开发者ID:xm-online,项目名称:xm-lep,代码行数:17,代码来源:LepScriptResourceConnector.java

示例6: reloadScript

import groovy.util.ResourceException; //导入依赖的package包/类
public Script reloadScript(String scriptName) {
    try {
        invalidateCache();

        GroovyScriptEngine groovy = new GroovyScriptEngine(createClasspath(getEngineOperations().getEngine()).toArray(new String[0]),
                shell.getClassLoader());
        Script script = groovy.createScript(scriptName, binding);
        script.run();
        return script;
    } catch (IOException | ResourceException | ScriptException e) {
        throw SpongeUtils.wrapException(e);
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:14,代码来源:GroovyKnowledgeBaseInterpreter.java

示例7: getGroovyRenderer

import groovy.util.ResourceException; //导入依赖的package包/类
private PrimitiveRenderer getGroovyRenderer() throws IOException, ResourceException, ScriptException {
  if (this.groovyRenderer == null) {
    GroovyScriptEngine gse = this.getGroovyScriptEngine();
    Binding binding = this.getBinding();
    gse.run(this.groovyFile.getName(), binding);
    this.groovyRenderer = (PrimitiveRenderer) binding.getVariable("renderer");
  }
  return this.groovyRenderer;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:10,代码来源:GroovyPrimitiveRenderer.java

示例8: SecurityGroovyRealm

import groovy.util.ResourceException; //导入依赖的package包/类
public SecurityGroovyRealm(GroovyScriptEngine groovyScriptEngine, String scriptUrl, ServletContext servletContext)
        throws ScriptException, ResourceException, InstantiationException, IllegalAccessException {
    this.groovyScriptEngine = groovyScriptEngine;
    this.scriptUrl = scriptUrl;
    this.servletContext = servletContext;
    doEnsureDelegate();
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:8,代码来源:SecurityGroovyRealm.java

示例9: getGroovyClass

import groovy.util.ResourceException; //导入依赖的package包/类
public static Class<?> getGroovyClass(File scriptFile) throws IOException, ScriptException, ResourceException {
    if(!scriptFile.exists()) {
        return null;
    }
    GroovyScriptEngine scriptEngine =
            (GroovyScriptEngine) ElementsThreadLocals.getServletContext().getAttribute(
                    BaseModule.GROOVY_SCRIPT_ENGINE);
    return scriptEngine.loadScriptByName(scriptFile.toURI().toString());
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:10,代码来源:ScriptingUtil.java

示例10: removeNamePrefix

import groovy.util.ResourceException; //导入依赖的package包/类
protected String removeNamePrefix(String name) throws ResourceException {
    if (namePrefix == null) {
        generateNamePrefixOnce();
    }
    if (name.startsWith(namePrefix)) {//usualy name has text
        return name.substring(namePrefix.length());
    }
    return name;
}
 
开发者ID:apache,项目名称:groovy,代码行数:10,代码来源:AbstractHttpServlet.java

示例11: getResourceConnection

import groovy.util.ResourceException; //导入依赖的package包/类
/**
 * Interface method for ResourceContainer. This is used by the GroovyScriptEngine.
 */
public URLConnection getResourceConnection (String name) throws ResourceException {
    name = removeNamePrefix(name).replace('\\', '/');

    //remove the leading / as we are trying with a leading / now
    if (name.startsWith("WEB-INF/groovy/")) {
        name = name.substring(15);//just for uniformity
    } else if (name.startsWith("/")) {
        name = name.substring(1);
    }

    /*
    * Try to locate the resource and return an opened connection to it.
    */
    try {
        URL url = servletContext.getResource('/' + name);
        if (url == null) {
            url = servletContext.getResource("/WEB-INF/groovy/" + name);
        }
        if (url == null) {
            throw new ResourceException("Resource \"" + name + "\" not found!");
        }
        return url.openConnection();
    } catch (IOException e) {
        throw new ResourceException("Problems getting resource named \"" + name + "\"!", e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:AbstractHttpServlet.java

示例12: runSjsCompilation

import groovy.util.ResourceException; //导入依赖的package包/类
private void runSjsCompilation() throws IOException, ResourceException,
    ScriptException, DependencyResolutionRequiredException {
  Properties projectProperties = project.getProperties();
  projectProperties.put("srcDir", srcDir.getAbsolutePath());
  projectProperties.put("outputDir", outputDir.getAbsolutePath());
  projectProperties.put("modelOutputFileName", modelOutputFileName);
  projectProperties.put("viewOutputFileName", viewOutputFileName);
  projectProperties.put("backOutputFileName", backOutputFileName);
  projectProperties.put("frontOutputFileName", frontOutputFileName);

  List<URL> classpath;
  classpath = new ArrayList<>();
  classpath.add(srcDir.toURI().toURL());
  List<String> compileClasspathElements = project
      .getCompileClasspathElements();
  for (String element : compileClasspathElements) {
    if (!element.equals(project.getBuild().getOutputDirectory())) {
      File elementFile = new File(element);
      getLog().debug(
          "Adding element to plugin classpath " + elementFile.getPath());
      URL url = elementFile.toURI().toURL();
      classpath.add(url);
    }
  }
  GroovyScriptEngine gse = new GroovyScriptEngine(
      classpath.toArray(new URL[classpath.size()]));
  Binding binding = new Binding();
  binding.setVariable("project", project);
  binding.setVariable("fail", new FailClosure());
  String refinedApplicationFileName = applicationFileName;
  if (!new File(srcDir + File.separator + applicationFileName).exists()) {
    if (applicationFileName.contains(SJSEXT)) {
      refinedApplicationFileName = applicationFileName.replaceAll(SJSEXT, GROOVY_EXT);
    } else if(applicationFileName.contains(GROOVY_EXT)) {
      refinedApplicationFileName = applicationFileName.replaceAll(GROOVY_EXT, SJSEXT);
    }
  }
  gse.run(refinedApplicationFileName, binding);
}
 
开发者ID:jspresso,项目名称:jspresso-ce,代码行数:40,代码来源:SjsMojo.java

示例13: getResourceConnection

import groovy.util.ResourceException; //导入依赖的package包/类
@Override
public URLConnection getResourceConnection(final String name)
        throws ResourceException {
    if(scripts.containsKey(name)) {
        try {
            return new URL(null, "string://" + name, new URLStreamHandler() {
                
                @Override
                protected URLConnection openConnection(URL u) throws IOException {
                    return new URLConnection(u) {
                        
                        @Override
                        public void connect() throws IOException {
                        }
                        @Override
                        public InputStream getInputStream() throws IOException {
                            return new ByteArrayInputStream(scripts.get(name).getBytes());
                        }
                    };
                }
            }).openConnection();
        } catch (Exception e) {
            throw new ResourceException(e);
        }
    }
    return null;
}
 
开发者ID:arquillian,项目名称:arquillian-script,代码行数:28,代码来源:BasicEnvTestCase.java

示例14: getGroovyObject

import groovy.util.ResourceException; //导入依赖的package包/类
public static GroovyObject getGroovyObject(File file) throws IOException, ScriptException, ResourceException {
    if(!file.exists()) {
        return null;
    }

    Class groovyClass = getGroovyClass(file);

    try {
        return (GroovyObject) groovyClass.newInstance();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:14,代码来源:ScriptingUtil.java

示例15: launch

import groovy.util.ResourceException; //导入依赖的package包/类
public Object launch(List<String> roots, String scriptName, Map<String, Object> params) throws IOException, ResourceException, ScriptException {
    CLIConnection conn = createCliConnection(params);
    try {
        conn.connect(params);
        Binding binding = new Binding();
        Expect4Groovy.createBindings(conn, binding, true);
        binding.setProperty("params", params);
        GroovyScriptEngine gse = new GroovyScriptEngine(roots.toArray(new String[roots.size()]));
        return gse.run(scriptName, binding);
    } finally {
        conn.disconnect();
    }
}
 
开发者ID:iTransformers,项目名称:expect4groovy,代码行数:14,代码来源:Expect4GroovyScriptLauncher.java


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