javax.script.ScriptEngine.getFactory()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中javax.script.ScriptEngine.getFactory()方法的一些代码示例,展示了ScriptEngine.getFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ScriptEngine.getFactory()方法的具体详情如下:
包路径:javax.script.ScriptEngine
类名称:ScriptEngine
方法名:getFactory

ScriptEngine.getFactory介绍

[英]Returns a ScriptEngineFactory for the class to which this ScriptEngine belongs.
[中]返回此ScriptEngine所属类的ScriptEngineFactory。

代码示例

代码示例来源:origin: looly/hutool

@Override
public ScriptEngineFactory getFactory() {
  return engine.getFactory();
}

代码示例来源:origin: looly/hutool

@Override
public ScriptEngineFactory getFactory() {
  return engine.getFactory();
}

代码示例来源:origin: looly/hutool

@Override
public ScriptEngineFactory getFactory() {
  return engine.getFactory();
}

代码示例来源:origin: looly/hutool

@Override
public ScriptEngineFactory getFactory() {
  return engine.getFactory();
}

代码示例来源:origin: Activiti/Activiti

Object threadingParameter = scriptEngine.getFactory().getParameter("THREADING");
if (threadingParameter != null) {

代码示例来源:origin: apache/nifi

log.error("Error adding script engine {}", new Object[]{scriptEngine.getFactory().getEngineName()});

代码示例来源:origin: cbeust/testng

boolean includeMethodFromExpression(ITestNGMethod tm) {
 Map<String, String> groups = Maps.newHashMap();
 for (String group : tm.getGroups()) {
  groups.put(group, group);
 }
 try {
  setContext(engine, groups, tm);
  Object evalResult = engine.eval(expression);
  if (evalResult == null) {
   String msg = String.format("The " + engine.getFactory().getLanguageName() + " expression [%s] evaluated to null.", expression);
   throw new TestNGException(msg);
  }
  return (Boolean) evalResult;
 } catch (ScriptException e) {
  throw new TestNGException(e);
 } finally {
  resetContext(engine);
 }
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testBase() {
  ScriptEngineManager factory = new ScriptEngineManager();
  ScriptEngine engine = factory.getEngineByName("jphp");
  ScriptEngineFactory f = engine.getFactory();
  Assert.assertNotNull(engine);
  Assert.assertTrue(engine instanceof Compilable);
  Assert.assertNotNull(f);
  Assert.assertEquals(Information.NAME, f.getEngineName());
  Assert.assertEquals("php", f.getLanguageName());
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Allows checking whether the script engine can be cached.
 *
 * @param scriptEngine the script engine to check.
 * @return true if the script engine may be cached.
 */
protected boolean isCachable(ScriptEngine scriptEngine) {
 // Check if script-engine supports multithreading. If true it can be cached.
 Object threadingParameter = scriptEngine.getFactory().getParameter("THREADING");
 return threadingParameter != null;
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Allows checking whether the script engine can be cached.
 *
 * @param scriptEngine the script engine to check.
 * @return true if the script engine may be cached.
 */
protected boolean isCachable(ScriptEngine scriptEngine) {
 // Check if script-engine supports multithreading. If true it can be cached.
 Object threadingParameter = scriptEngine.getFactory().getParameter("THREADING");
 return threadingParameter != null;
}

代码示例来源:origin: spring-projects/spring-integration

protected AbstractScriptExecutor(String language) {
  Assert.hasText(language, "language must not be empty");
  this.language = language;
  this.scriptEngine = new ScriptEngineManager().getEngineByName(this.language);
  Assert.notNull(this.scriptEngine, invalidLanguageMessage(this.language));
  if (this.logger.isDebugEnabled()) {
    this.logger.debug("Using script engine : " + this.scriptEngine.getFactory().getEngineName());
  }
}

代码示例来源:origin: spring-projects/spring-integration

private String getLanguageFromFileExtension(String scriptLocation, ParserContext parserContext, Element element) {
    ScriptEngineManager engineManager = new ScriptEngineManager();
    ScriptEngine engine = null;

    int index = scriptLocation.lastIndexOf(".") + 1;
    if (index < 1) {
      return null;
    }
    String extension = scriptLocation.substring(index);

    engine = engineManager.getEngineByExtension(extension);

    if (engine == null) {
      parserContext.getReaderContext().error(
          "No suitable scripting engine found for extension '" + extension + "'", element);
    }

    return engine.getFactory().getLanguageName();
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

public CompiledScript compile(ScriptEngine scriptEngine, String language, String src) {
 if(scriptEngine instanceof Compilable && !scriptEngine.getFactory().getLanguageName().equalsIgnoreCase("ecmascript")) {
  Compilable compilingEngine = (Compilable) scriptEngine;
  try {
   CompiledScript compiledScript = compilingEngine.compile(src);
   LOG.debugCompiledScriptUsing(language);
   return compiledScript;
  } catch (ScriptException e) {
   throw new ScriptCompilationException("Unable to compile script: " + e.getMessage(), e);
  }
 } else {
  // engine does not support compilation
  return null;
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

public CompiledScript compile(ScriptEngine scriptEngine, String language, String src) {
 if(scriptEngine instanceof Compilable && !scriptEngine.getFactory().getLanguageName().equalsIgnoreCase("ecmascript")) {
  Compilable compilingEngine = (Compilable) scriptEngine;
  try {
   CompiledScript compiledScript = compilingEngine.compile(src);
   LOG.debugCompiledScriptUsing(language);
   return compiledScript;
  } catch (ScriptException e) {
   throw new ScriptCompilationException("Unable to compile script: " + e.getMessage(), e);
  }
 } else {
  // engine does not support compilation
  return null;
 }
}

代码示例来源:origin: schemacrawler/SchemaCrawler

private ScriptEngine getScriptEngine()
 throws SchemaCrawlerException
{
 final String scriptFileName = outputOptions.getOutputFormatValue();
 if (isBlank(scriptFileName))
 {
  throw new SchemaCrawlerCommandLineException("Please specify a script to execute");
 }
 final String scriptExtension = getFileExtension(scriptFileName);
 final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
 final ScriptEngine scriptEngine;
 if (isBlank(scriptExtension))
 {
  scriptEngine = scriptEngineManager.getEngineByName("nashorn");
 }
 else
 {
  scriptEngine = scriptEngineManager.getEngineByExtension(scriptExtension);
 }
 if (scriptEngine == null)
 {
  throw new SchemaCrawlerException("Script engine not found");
 }
 logScriptEngineDetails(Level.CONFIG, scriptEngine.getFactory());
 return scriptEngine;
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected Object evaluateScriptExpression(String expressionLanguage, VariableContext variableContext, String expressionText, CachedCompiledScriptSupport cachedCompiledScriptSupport) {
 ScriptEngine scriptEngine = getScriptEngineForName(expressionLanguage);
 // wrap script engine bindings + variable context and pass enhanced
 // bindings to the script engine.
 Bindings bindings = VariableContextScriptBindings.wrap(scriptEngine.createBindings(), variableContext);
 bindings.put("variableContext", variableContext);
 try {
  if (scriptEngine instanceof Compilable) {
   CompiledScript compiledScript = cachedCompiledScriptSupport.getCachedCompiledScript();
   if (compiledScript == null) {
    synchronized (cachedCompiledScriptSupport) {
     compiledScript = cachedCompiledScriptSupport.getCachedCompiledScript();
     if(compiledScript == null) {
      Compilable compilableScriptEngine = (Compilable) scriptEngine;
      compiledScript = compilableScriptEngine.compile(expressionText);
      cachedCompiledScriptSupport.cacheCompiledScript(compiledScript);
     }
    }
   }
   return compiledScript.eval(bindings);
  }
  else {
   return scriptEngine.eval(expressionText, bindings);
  }
 }
 catch (ScriptException e) {
  throw LOG.unableToEvaluateExpression(expressionText, scriptEngine.getFactory().getLanguageName(), e);
 }
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator

/**
   * Checks whether the given engine is thread-safe or not.
   *
   * @return true if the given engine is thread-safe, false otherwise.
   */
  private boolean engineAllowsParallelAccessFromMultipleThreads() {
    String threadingType = (String) engine.getFactory().getParameter( "THREADING" );

    return "THREAD-ISOLATED".equals( threadingType ) || "STATELESS".equals( threadingType );
  }
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

/**
 * Allows checking whether the script engine can be cached.
 *
 * @param scriptEngine the script engine to check.
 * @return true if the script engine may be cached.
 */
protected boolean isCachable(ScriptEngine scriptEngine) {
 // Check if script-engine supports multithreading. If true it can be cached.
 Object threadingParameter = scriptEngine.getFactory().getParameter("THREADING");
 return threadingParameter != null;
}

代码示例来源:origin: com.googlecode.cernunnos/cernunnos

@Override
public boolean isThreadSafe(String key, ScriptEngine instance) {
  final ScriptEngineFactory factory = instance.getFactory();
  final Object threadingAbility = factory.getParameter("THREADING");
  return threadingAbility != null && ("THREAD-ISOLATED".equals(threadingAbility) || "STATELESS".equals(threadingAbility));
}

代码示例来源:origin: org.apache.myfaces.extensions.cdi.bundles/myfaces-extcdi-bundle-jsf20

/**
   * {@inheritDoc}
   */
  public ScriptEngineFactory getFactory()
  {
    return getScriptEngine().getFactory();
  }
}

相关文章