コード例 #1
0
ファイル: ScriptBindings.java プロジェクト: gokceng/Activiti
 public boolean containsKey(Object key) {
   for (Resolver scriptResolver : scriptResolvers) {
     if (scriptResolver.containsKey(key)) {
       return true;
     }
   }
   return defaultBindings.containsKey(key);
 }
コード例 #2
0
  @Override
  public void handleAction(
      final Context context, final ActionRequest request, final Bindings handler)
      throws ResourceException {
    super.handleAction(context, request, handler);
    for (Map.Entry<String, String> entry : request.getAdditionalParameters().entrySet()) {
      if (handler.containsKey(entry.getKey())) {
        continue;
      }
      if (bindings != null) {
        bindings.put(entry.getKey(), entry.getValue());
      }
    }

    handler.put("request", request);
    handler.put("resources", configuration.get("resources").copy().getObject());
  }
コード例 #3
0
ファイル: CustomScriptManager.java プロジェクト: mwohlf/nchar
  @SuppressWarnings("rawtypes")
  // the caller is responsible for setting the task environment
  @Override
  protected Object evaluate(final ScriptEngine scriptEngine, final String script) {

    LOGGER.debug("evaluate called for {}", script);

    // Bindings bindings = new CustomEnvironmentBindings();
    // we can add any custom binding here if we override the EnvironmentBindings
    final Bindings bindings = new EnvironmentBindings(readContextNames, writeContextName);
    scriptEngine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);

    if (!bindings.containsKey("task")) {
      LOGGER.warn("calling a script and no task in context, the script is [{}]", script);
    } else {
      LOGGER.info("got a task in the context >{}<", bindings.get("task"));
    }

    try {
      // we get a nullpointer exception if we have a comments only script, try to prevent this
      // by checking for a nullpointer clazz before calling eval on tne script engine:
      Class clazz = new GroovyClassLoader().parseClass(script);
      if (clazz == null) {
        LOGGER.debug("script parsed to null");
        return null;
      } else {
        final Object result = scriptEngine.eval(script);
        LOGGER.debug("script evaluated to {}", result);
        return result;
      }
    } catch (final Exception ex) {
      LOGGER.warn(
          "script error in script, the error is: {}, the script is: [{}], throwing error ",
          ex.getMessage(),
          script);
      throw new JbpmException("script evaluation error: " + ex.getMessage(), ex);
    }
  }