Java Code Examples for javax.script.Bindings#entrySet()

The following examples show how to use javax.script.Bindings#entrySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeCompleter.java    From camunda-bpm-workbench with GNU Affero General Public License v3.0 6 votes vote down vote up
protected List<CodeCompletionHint> completeFromBindings(String prefix) {
  List<CodeCompletionHint> result = new ArrayList<CodeCompletionHint>();

  for (Bindings bindings : variableBindings) {
    for (Map.Entry<String, Object> binding : bindings.entrySet()) {
      if (binding.getKey().startsWith(prefix)) {
        CodeCompletionHint completionHint = new CodeCompletionHint();
        completionHint.setCompletedIdentifier(binding.getKey());
        completionHint.setCompletedMethod(binding.getKey());
        completionHint.setCompletedType(binding.getValue().getClass().getSimpleName());
        result.add(completionHint);
      }
    }
  }

  return result;
}
 
Example 2
Source File: CodeCompleter.java    From camunda-bpm-workbench with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Class<?> resolveRootType(String name) {
  for (Bindings bindings : variableBindings) {
    for (Map.Entry<String, Object> binding : bindings.entrySet()) {
      if (binding.getKey().equals(name)) {
        return binding.getValue().getClass();
      }
    }
  }

  throw new DebuggerException("No bound object found: " + name);
}
 
Example 3
Source File: GraphvizWriter.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void writeGraph(OutputStream os) throws IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    super.writeGraph(baos);

    try
    {
        StringBuilder builder = new StringBuilder();
        builder.append(IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("vizjs/viz.js")));
        builder.append("var result = new Viz(dotGraph);");

        String script = builder.toString();
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
        Compilable compilingEngine = (Compilable) engine;
        CompiledScript cscript = compilingEngine.compile(script);

        // Bindings bindings = cscript.getEngine().createBindings();
        Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
        for (Map.Entry me : bindings.entrySet())
        {
            System.out.printf("%s: %s\n", me.getKey(), String.valueOf(me.getValue()));
        }
        bindings.put("dotGraph", baos.toString());
        // cscript.eval();
        Object result = cscript.eval(bindings);
        LOG.info("Result:" + ReflectionToStringBuilder.toString(result));
    }
    catch (Exception e)
    {
        throw new IOException("Exception generating graph.", e);
    }
}