Example usage for javax.script Bindings keySet

List of usage examples for javax.script Bindings keySet

Introduction

In this page you can find the example usage for javax.script Bindings keySet.

Prototype

Set<K> keySet();

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:GetToKnowBindingsAndScopes.java

public static void dumpBindings(Bindings bindings) {
    if (bindings == null)
        System.out.println("  No bindings");
    else/*from   w ww  . j  a  v  a  2s.  c  om*/
        for (String key : bindings.keySet())
            System.out.println("  " + key + ": " + bindings.get(key));
    System.out.println();
}

From source file:org.apache.sling.scripting.sightly.impl.engine.UnitLoader.java

private CompilationOutput obtainOutput(String source, Bindings bindings, RenderContextImpl renderContext) {
    JavaClassBackend backend = new JavaClassBackend();
    sightlyCompilerService.compile(source, new GlobalShadowCheckBackend(backend, bindings.keySet()),
            renderContext);//  w  ww  .j a v a2  s  .  c o  m
    return backend.build();
}

From source file:org.mycontroller.standalone.scripts.McScriptEngineUtils.java

public static HashMap<String, Object> getBindings(Bindings bindings) {
    HashMap<String, Object> engineScopes = new HashMap<String, Object>();
    for (String key : bindings.keySet()) {
        //Do not add mcApi and __builtins__
        if (!key.equals(MC_API) && !key.startsWith("__")) {
            engineScopes.put(key, bindings.get(key));
        }//from   w ww  .  ja  va  2  s .  co  m
    }
    return engineScopes;
}

From source file:org.rhq.scripting.javascript.JavascriptCompletor.java

private Map<String, Object> getContextMatches(String start) {
    Map<String, Object> found = new HashMap<String, Object>();
    if (context != null) {
        for (Integer scope : context.getScopes()) {
            Bindings bindings = context.getBindings(scope);
            for (String var : bindings.keySet()) {
                if (var.startsWith(start)) {
                    found.put(var, bindings.get(var));
                }//  w  w  w. ja v  a 2  s .c  o  m
            }
        }
    }

    //this was originally part of the code completor that lived in the CLI
    //I don't think we need it, because the services are present under the
    //same names in the context. This code can never add any new matches.
    /*
    if (services != null) {
    for (String var : services.keySet()) {
        if (var.startsWith(start)) {
            found.put(var, services.get(var));
        }
    }
    }
    */

    return found;
}

From source file:org.rhq.scripting.javascript.JavascriptCompletor.java

/**
 * Look through all available contexts to find bindings that both start with
 * the supplied start and match the typeFilter.
 * @param start//from   w w w  .  j  ava 2 s  . co m
 * @param typeFilter
 * @return
 */
private Map<String, Object> getContextMatches(String start, Class<?> typeFilter) {
    Map<String, Object> found = new HashMap<String, Object>();
    if (context != null) {
        for (int scope : context.getScopes()) {
            Bindings bindings = context.getBindings(scope);
            for (String var : bindings.keySet()) {
                if (var.startsWith(start)) {

                    if ((bindings.get(var) != null && typeFilter.isAssignableFrom(bindings.get(var).getClass()))
                            || recomplete == 3) {
                        found.put(var, bindings.get(var));
                    }
                }
            }
        }

        if (typeFilter.isEnum()) {
            for (Object ec : typeFilter.getEnumConstants()) {
                Enum<?> e = (Enum<?>) ec;
                String code = typeFilter.getSimpleName() + "." + e.name();
                if (code.startsWith(start)) {
                    found.put(typeFilter.getSimpleName() + "." + e.name(), e);
                }
            }
        }
    }
    return found;
}