Example usage for jdk.nashorn.api.scripting ScriptObjectMirror values

List of usage examples for jdk.nashorn.api.scripting ScriptObjectMirror values

Introduction

In this page you can find the example usage for jdk.nashorn.api.scripting ScriptObjectMirror values.

Prototype

@Override
    public Collection<Object> values() 

Source Link

Usage

From source file:com.baasbox.service.scripting.js.NashornMapper.java

License:Apache License

private JsonNode convertMirror(ScriptObjectMirror mirror) throws ScriptEvalException {
    if (mirror == null) {

        return NullNode.getInstance();
    } else if (ScriptObjectMirror.isUndefined(mirror)) {
        return MissingNode.getInstance();
    } else if (mirror.isFunction()) {
        return MissingNode.getInstance();
    } else if (mirror.isArray()) {
        Collection<Object> values = mirror.values();
        ArrayNode node = Json.mapper().createArrayNode();
        for (Object o : values) {
            JsonNode e = convertDeepJson(o);
            if (e.isMissingNode()) {
                continue;
            }//from w  w  w.j  a  v  a 2  s  .c om
            node.add(e);
        }
        return node;
    } else if (mirror.hasMember("toJSON")) {
        Object toJSON = mirror.callMember("toJSON");
        return convertDeepJson(toJSON);
    } else {
        ObjectNode obj = Json.mapper().createObjectNode();
        Set<Map.Entry<String, Object>> entries = mirror.entrySet();
        for (Map.Entry<String, Object> e : entries) {
            Object obv = e.getValue();
            JsonNode jsonNode = convertDeepJson(obv);
            if (jsonNode.isMissingNode()) {
                continue;
            }
            obj.put(e.getKey(), jsonNode);
        }
        return obj;
    }
}

From source file:com.intuit.karate.core.ScriptBridge.java

License:Open Source License

public Object append(Object... items) {
    List out = new ArrayList();
    if (items == null) {
        return out;
    }//  ww  w .  j a v a  2s .c o m
    for (Object item : items) {
        if (item == null) {
            continue;
        }
        if (item instanceof ScriptObjectMirror) { // no need when graal
            ScriptObjectMirror som = (ScriptObjectMirror) item;
            if (som.isArray()) {
                out.addAll(som.values());
            } else {
                out.add(som);
            }
        } else if (item instanceof Collection) {
            out.addAll((Collection) item);
        } else {
            out.add(item);
        }
    }
    return out;
}

From source file:com.intuit.karate.core.Tags.java

License:Open Source License

public boolean anyOf(ScriptObjectMirror som) {
    for (String s : removeTagPrefix(som.values())) {
        if (tags.contains(s)) {
            return true;
        }//from   w ww .  j  a  v a 2 s  .c o  m
    }
    return false;
}

From source file:com.intuit.karate.core.Tags.java

License:Open Source License

public boolean allOf(ScriptObjectMirror som) {
    return tags.containsAll(removeTagPrefix(som.values()));
}

From source file:com.nordea.oss.copybook.codegen.CopyBookConverter.java

License:MIT License

public List<String> convert(String copybookString, String packageName, String rootClassName, String accessor,
        String charset, String subClassHandling, String wrapperClassName) throws Exception {
    ScriptObjectMirror results = (ScriptObjectMirror) invocable.invokeFunction("convertCopybook", packageName,
            rootClassName, copybookString, accessor, charset, subClassHandling, wrapperClassName);
    return Arrays.asList(results.values().toArray(new String[results.size()]));
}

From source file:com.pivotal.cf.mobile.ats.json.ScriptObjectMirrorSerializer.java

License:Open Source License

@Override
public void serialize(ScriptObjectMirror value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonGenerationException {
    if (value.isArray()) {
        if (arraySerializer == null) {
            arraySerializer = (StdDelegatingSerializer) new StdDelegatingSerializer(ScriptObjectMirror.class,
                    new StdConverter<ScriptObjectMirror, Collection<Object>>() {

                        @Override
                        public Collection<Object> convert(ScriptObjectMirror value) {
                            return value.values();
                        }//from  w  w  w  .  j av a2  s  .  c  o  m

                    }).createContextual(provider, null);

        }
        arraySerializer.serialize(value, jgen, provider);
    } else {
        if (objectSerializer == null) {
            objectSerializer = (StdDelegatingSerializer) new StdDelegatingSerializer(ScriptObjectMirror.class,
                    new StdConverter<ScriptObjectMirror, Map<String, Object>>() {

                        @Override
                        public Map<String, Object> convert(ScriptObjectMirror value) {
                            return value;
                        }

                    }).createContextual(provider, null);

        }
        objectSerializer.serialize(value, jgen, provider);
    }
}

From source file:com.qwazr.connectors.LdapConnector.java

License:Apache License

public void createUser(LdapConnection connection, String dn, String clearPassword, ScriptObjectMirror attrs)
        throws LdapException {
    connection.bind();/* w w  w .  ja v a 2s.  co m*/
    Entry entry = new DefaultEntry(dn + ", " + base_dn);
    if (clearPassword != null)
        entry.add("userPassword", getShaPassword(clearPassword));
    if (attrs != null) {
        for (Map.Entry<String, Object> attr : attrs.entrySet()) {
            String key = attr.getKey();
            Object value = attr.getValue();
            if (value instanceof String) {
                entry.add(key, (String) value);
            } else if (value instanceof ScriptObjectMirror) {
                ScriptObjectMirror som = (ScriptObjectMirror) value;
                if (som.isArray()) {
                    for (Object obj : som.values())
                        entry.add(key, obj.toString());
                } else
                    throw new LdapException("Unsupported hash: " + som);
            } else
                throw new LdapException("Unsupported type: " + value.getClass());
        }
    }
    connection.add(entry);
}

From source file:com.qwazr.library.ldap.LdapConnector.java

License:Apache License

public void createUser(final LdapConnection connection, final String dn, final String passwordAttribute,
        final String clearPassword, final Map<String, Object> attrs) throws LdapException {
    connection.bind();// w  w  w  .j  av  a 2s . co  m
    final Entry entry = new DefaultEntry(dn + ", " + baseDn);
    if (clearPassword != null)
        entry.add(passwordAttribute, getShaPassword(clearPassword));
    if (attrs != null) {
        for (Map.Entry<String, Object> attr : attrs.entrySet()) {
            final String key = attr.getKey();
            final Object value = attr.getValue();
            if (value instanceof String) {
                entry.add(key, (String) value);
            } else if (value instanceof ScriptObjectMirror) {
                final ScriptObjectMirror som = (ScriptObjectMirror) value;
                if (som.isArray()) {
                    for (Object obj : som.values())
                        entry.add(key, obj.toString());
                } else
                    throw new LdapException("Unsupported hash: " + som);
            } else
                throw new LdapException("Unsupported type: " + value.getClass());
        }
    }
    connection.add(entry);
}

From source file:com.qwazr.utils.ScriptUtils.java

License:Apache License

public static <T> T[] toArray(ScriptObjectMirror som, Class<T> type) throws ScriptException {
    if (som == null)
        return null;
    if (!som.isArray())
        throw new ScriptException("The JS object is not an array");
    T[] array = (T[]) new Object[som.size()];
    final AtomicInteger i = new AtomicInteger(0);
    som.values().forEach(o -> array[i.getAndIncrement()] = ((ScriptObjectMirror) o).to(type));
    return array;
}

From source file:com.qwazr.utils.ScriptUtils.java

License:Apache License

public static void fillStringCollection(ScriptObjectMirror som, Collection<String> collection)
        throws ScriptException {
    if (som == null)
        return;//from  w w w  .jav  a  2s . c  om
    if (!som.isArray())
        throw new ScriptException("The JS object is not an array");
    som.values().forEach(o -> collection.add(o.toString()));
}