Example usage for jdk.nashorn.internal.objects NativeArray get

List of usage examples for jdk.nashorn.internal.objects NativeArray get

Introduction

In this page you can find the example usage for jdk.nashorn.internal.objects NativeArray get.

Prototype

@Override
    public Object get(final Object key) 

Source Link

Usage

From source file:com.asual.lesscss.compiler.NashornCompiler.java

License:Apache License

private Exception parseLessException(Exception root) {
    logger.debug("Parsing LESS Exception", root);
    if (root instanceof ECMAException) {
        ECMAException e = (ECMAException) root;
        Object thrown = e.getThrown();
        String type = null;// w  w  w . j  ava  2 s. c o m
        String message = null;
        String filename = null;
        int line = -1;
        int column = -1;
        List<String> extractList = new ArrayList<String>();
        if (thrown instanceof ScriptObject) {
            ScriptObject so = (ScriptObject) e.getThrown();
            type = so.get("type").toString() + " Error";
            message = so.get("message").toString();
            filename = "";
            if (so.has("filename")) {
                filename = so.get("filename").toString();
            }
            if (so.has("line")) {
                line = ((Long) so.get("line")).intValue();
            }
            if (so.has("column")) {
                column = ((Double) so.get("column")).intValue();
            }
            if (so.has("extract")) {
                NativeArray extract = (NativeArray) so.get("extract");
                for (int i = 0; i < extract.size(); i++) {
                    if (extract.get(i) instanceof String) {
                        extractList.add(((String) extract.get(i)).replace("\t", " "));
                    }
                }
            }
        } else {
            type = thrown.getClass().getSimpleName() + " Error";
            message = e.getMessage().replaceFirst("[^:]+: ", "");
        }
        return new LessException(message, type, filename, line, column, extractList);
    }
    return root;
}

From source file:org.jcruncher.less.LessProcessor.java

License:Apache License

private Exception parseLessException(Exception root) {
    //logger.debug("Parsing LESS Exception", root);
    if (root instanceof ECMAException) {
        ECMAException e = (ECMAException) root;
        Object thrown = e.getThrown();
        String type = null;/*from www  . jav a2 s.co  m*/
        String message = null;
        String filename = null;
        int line = -1;
        int column = -1;
        List<String> extractList = new ArrayList<String>();
        if (thrown instanceof ScriptObject) {
            ScriptObject so = (ScriptObject) e.getThrown();
            type = so.get("type").toString() + " Error";
            message = so.get("message").toString();
            filename = "";
            if (so.has("filename")) {
                filename = so.get("filename").toString();
            }
            if (so.has("line")) {
                line = ((Long) so.get("line")).intValue();
            }
            if (so.has("column")) {
                column = ((Double) so.get("column")).intValue();
            }
            if (so.has("extract")) {
                NativeArray extract = (NativeArray) so.get("extract");
                for (int i = 0; i < extract.size(); i++) {
                    if (extract.get(i) instanceof String) {
                        extractList.add(((String) extract.get(i)).replace("\t", " "));
                    }
                }
            }
        } else {
            type = thrown.getClass().getSimpleName() + " Error";
            message = e.getMessage().replaceFirst("[^:]+: ", "");
        }
        return new LessException(message, type, filename, line, column, extractList);
    }
    return root;
}

From source file:org.nuxeo.video.tools.operations.VideoConcatDemuxerOp.java

License:Open Source License

@OperationMethod
public Blob run(NativeArray inDocs) throws ClientException, IOException, CommandNotAvailable {

    DocumentModelListImpl dml = new DocumentModelListImpl();
    for (int i = 0; i < inDocs.size(); ++i) {
        dml.add((DocumentModel) inDocs.get(i));
    }//from  www.j a  v  a2 s.c  o m

    return run(dml);
}

From source file:org.siphon.common.js.JsTypeUtil.java

License:Open Source License

private static Object jsObjectToJava(NativeArray arg) throws UnsupportedConversionException {
    int size = getArrayLength(arg);
    List<Object> result = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        result.add(jsObjectToJava(arg.get(i)));
    }/*from  w  w w . j a va 2 s. c  om*/
    return result;
}

From source file:org.siphon.common.js.JsTypeUtil.java

License:Open Source License

private static byte[] parseBinary(Object value) throws UnsupportedConversionException {
    if (value instanceof byte[]) {
        return (byte[]) value;
    } else if (value instanceof Byte[]) {
        return ArrayUtils.toPrimitive((Byte[]) value);
    }/*from   w  ww  .j av  a 2 s  .  com*/
    if (value instanceof ScriptObjectMirror && ((ScriptObjectMirror) value).isArray()) {
        value = ((ScriptObjectMirror) value).to(NativeArray.class);
    }
    if (value instanceof NativeArray) {
        NativeArray arr = (NativeArray) value;
        byte[] r = new byte[JsTypeUtil.getArrayLength(arr)];
        for (int i = 0; i < JsTypeUtil.getArrayLength(arr); i++) {
            if (arr.get(i) instanceof Byte) {
                r[i] = (Byte) arr.get(i);
            } else if (arr.get(i) instanceof Double) {
                r[i] = ((Double) arr.get(i)).byteValue();
            } else if (arr.get(i) instanceof Integer) {
                r[i] = ((Integer) arr.get(i)).byteValue();
            }
        }
        return r;
    } else if (value instanceof String) {
        Decoder decoder = Base64.getDecoder();
        try {
            return decoder.decode((String) value);
        } catch (Exception e) {
            throw new UnsupportedConversionException("cannot parse base64 binary data " + value, e);
        }
    } else {
        throw new UnsupportedConversionException("unkown binary data " + value + " " + value.getClass(), null);
    }
}

From source file:org.siphon.jsmongo.MongoExecutor.java

License:Open Source License

private BsonValue nativeArrayToBson(NativeArray arr) throws SqlExecutorException {
    BsonArray result = new BsonArray();
    for (int i = 0; i < JsTypeUtil.getArrayLength(arr); i++) {
        result.add(jsValueToBson(arr.get(i)));
    }/*from   w  w w .  ja v  a  2 s .c o m*/
    return result;
}

From source file:org.siphon.jsmongo.MongoExecutor.java

License:Open Source License

private byte[] parseBinary(Object value) throws SqlExecutorException {
    if (value instanceof byte[]) {
        return (byte[]) value;
    } else if (value instanceof Byte[]) {
        return ArrayUtils.toPrimitive((Byte[]) value);
    }//w ww  .j a  v a 2 s  .co  m
    if (value instanceof ScriptObjectMirror && ((ScriptObjectMirror) value).isArray()) {
        value = ((ScriptObjectMirror) value).to(NativeArray.class);
    }
    if (value instanceof NativeArray) {
        NativeArray arr = (NativeArray) value;
        byte[] r = new byte[JsTypeUtil.getArrayLength(arr)];
        for (int i = 0; i < JsTypeUtil.getArrayLength(arr); i++) {
            if (arr.get(i) instanceof Byte) {
                r[i] = (Byte) arr.get(i);
            } else if (arr.get(i) instanceof Double) {
                r[i] = ((Double) arr.get(i)).byteValue();
            } else if (arr.get(i) instanceof Integer) {
                r[i] = ((Integer) arr.get(i)).byteValue();
            }
        }
        return r;
    } else if (value instanceof String) {
        Decoder decoder = Base64.getDecoder();
        try {
            return decoder.decode((String) value);
        } catch (Exception e) {
            throw new SqlExecutorException("cannot parse base64 binary data " + value, e);
        }
    } else {
        throw new SqlExecutorException("unkown binary data " + value + " " + value.getClass());
    }
}

From source file:org.siphon.jssql.SqlExecutor.java

License:Open Source License

/***
 * /*  ww w  .j  ava2 s . com*/
 * @param connection
 * @param callProcStmt pkg.proc(?, ?, ?)
 * @param args [arg1, arg2, {OUTCURSOR, arg3}]
 * @return success or not
 * @throws SqlExecutorException 
 */
public boolean call(Connection connection, String callProcStmt, NativeArray args) throws SqlExecutorException {
    if (connection == null) {
        return this.call(callProcStmt, args);
    }

    long start = System.currentTimeMillis();

    CallableStatement proc = null;
    boolean errorOccu = false;
    try {
        // if(logger.isDebugEnabled()) logger.debug("execute procedure " +
        // callProcStmt + " with args: " + JSON.tryStringify(args));

        proc = connection.prepareCall(String.format("{call %s}", callProcStmt));
        NativeArray nargs = args;
        setArgs(proc, nargs);
        boolean result = proc.execute();
        for (int i = 0; i < JsTypeUtil.getArrayLength(nargs); i++) {
            Object oarg = args.get(i);
            if (oarg instanceof ScriptObjectMirror) {
                ScriptObjectMirror arg = (ScriptObjectMirror) oarg;
                if (arg.containsKey("OUTCURSOR")) {
                    Object oarr = arg.get("OUTCURSOR");
                    if (oarr instanceof ScriptObjectMirror) {
                        ScriptObjectMirror outArr = (ScriptObjectMirror) oarr;
                        ResultSet rs = (ResultSet) proc.getObject(i + 1);
                        ScriptObjectMirror rsArry = rsToDataTable(rs);
                        rs.close();
                        Object[] ids = rsArry.keySet().toArray();
                        for (int j = 0; j < ids.length; j++) {
                            outArr.put((String) ids[j], rsArry.get(ids[j]));
                        }
                    }
                } else if (arg.containsKey("OUT")) {
                    int type = (int) arg.get("JDBC_TYPE");
                    Object output = translateOutputParameterValue(type, proc, i + 1);
                    arg.put("result", output);
                }
            }
        }
        return result;

    } catch (SQLException | UnsupportedDataTypeException | ScriptException | NoSuchMethodException e) {
        errorOccu = true;
        throw new SqlExecutorException(
                "error occurs when execute " + callProcStmt + " with args : " + JSON.tryStringify(args), e);
    } finally {
        long exhaust = System.currentTimeMillis() - start;
        if (exhaust > 30000) {
            logger.warn(String.format("%s with args:%s exhaust %s", callProcStmt, args, exhaust));
        }
        DbConnectionUtil.close(proc);
    }
}

From source file:org.siphon.jssql.SqlExecutor.java

License:Open Source License

private void setArgs(PreparedStatement ps, NativeArray args) throws SqlExecutorException, SQLException,
        UnsupportedDataTypeException, NoSuchMethodException, ScriptException {
    for (int i = 0; i < JsTypeUtil.getArrayLength(args); i++) {
        setArg(ps, i, args.get(i));
    }// www .  j av a2 s.  c  o  m

}

From source file:org.siphon.jssql.SqlExecutor.java

License:Open Source License

private Array createSqlArray(Connection connection, NativeArray arr)
        throws SQLException, UnsupportedDataTypeException, SqlExecutorException {
    Object[] objs = new Object[JsTypeUtil.getArrayLength(arr)];
    for (int i = 0; i < JsTypeUtil.getArrayLength(arr); i++) {
        objs[i] = arr.get(i);
    }/*from w w w .j  av a  2 s  .com*/
    String type = (String) objs[0];

    objs = Arrays.copyOfRange(objs, 1, objs.length);
    for (int i = 0; i < objs.length; i++) {
        objs[i] = convertJsObjToJavaType(objs[i]);
    }
    Array result = connection.createArrayOf(type, objs);
    return result;
}