@JSFunction public static void log(Context cx, Scriptable thisObj, Object[] args, Function funObj) { log(args); }
@JSFunction @SuppressWarnings("unused") public static Object getGlobal(Context cx, Scriptable thisObj, Object[] args, Function funObj) { ContextImpl self = (ContextImpl)thisObj; return self.globalProxy; } }
@JSFunction @SuppressWarnings("unused") public static void reset(Context cx, Scriptable thisObj, Object[] args, Function func) { JdbcConnection self = (JdbcConnection)thisObj; if (log.isDebugEnabled()) { log.debug("Resetting {} to be re-pooled", self.conn); } try { synchronized (self) { self.conn.setAutoCommit(true); } } catch (SQLException sqle) { if (log.isDebugEnabled()) { log.debug("Error on reset -- ignoring! {}", sqle); } } }
@JSFunction @SuppressWarnings("unused") public static void setAutoCommit(Context cx, Scriptable thisObj, Object[] args, Function func) { boolean auto = booleanArg(args, 0); JdbcConnection self = (JdbcConnection)thisObj; try { synchronized (self) { self.conn.setAutoCommit(auto); } } catch (SQLException sqle) { if (log.isDebugEnabled()) { log.debug("Error on setAutoCommit -- ignoring! {}", sqle); } } }
@JSFunction @SuppressWarnings("unused") public static void setTransformer(Context cx, Scriptable thisObj, Object[] args, Function funObj) { String className = stringArg(args, 0); XmlWrapImpl self = (XmlWrapImpl)thisObj; self.transFactory = TransformerFactory.newInstance(className, XmlWrap.class.getClassLoader()); self.configureTransformer(cx); }
@JSFunction @SuppressWarnings("unused") public static void close(Context cx, Scriptable thisObj, Object[] args, Function func) { JdbcResultHandle self = (JdbcResultHandle)thisObj; synchronized (self) { if (self.closed) { throw Utils.makeError(cx, self, "Already closed"); } try { self.closed = true; self.results.close(); self.statement.close(); } catch (SQLException se) { if (log.isDebugEnabled()) { log.debug("Error closing result set: {}", se); } } } } }
@JSFunction public static Object encodingExists(Context cx, Scriptable thisObj, Object[] args, Function funObj) { String encoding = stringArg(args, 0); return Context.javaToJS(Charset.isSupported(encoding), funObj); }
@JSFunction @SuppressWarnings("unused") public static Object runInContext(Context cx, Scriptable thisObj, Object[] args, Function funObj) { ContextImpl ctx = objArg(args, 0, ContextImpl.class, true); ScriptImpl self = (ScriptImpl)thisObj; return self.script.exec(cx, ctx.globalProxy); } }
@JSFunction @SuppressWarnings("unused") public static Object run(Context cx, Scriptable thisObj, Object[] args, Function funObj) { String code = stringArg(args, 0); String fileName = stringArg(args, 1, "anonymous"); ContextImpl self = (ContextImpl)thisObj; return cx.evaluateString(self.globalProxy, code, fileName, 1, null); }
@JSFunction @SuppressWarnings("unused") public static void rollback(Context cx, Scriptable thisObj, Object[] args, Function func) { final Function cb = functionArg(args, 0, true); final JdbcConnection self = (JdbcConnection)thisObj; final Object domain = self.runtime.getDomain(); self.runtime.getAsyncPool().execute(new Runnable() { @Override public void run() { try { synchronized (self) { self.conn.rollback(); } self.runtime.enqueueCallback(cb, cb, self, ScriptRuntime.emptyArgs); } catch (SQLException sqle) { self.returnError(cb, domain, sqle); } } }); }
@JSFunction public static Object decodeBuffer(Context cx, Scriptable thisObj, Object[] args, Function funObj) { Buffer.BufferImpl buf = objArg(args, 0, Buffer.BufferImpl.class, true); String encoding = stringArg(args, 1); IconvModuleImpl self = (IconvModuleImpl)thisObj; Charset cs = self.getCharset(cx, funObj, encoding); CharsetDecoder dec = cs.newDecoder(); dec.onUnmappableCharacter(CodingErrorAction.REPLACE); CharBuffer decoded; try { decoded = dec.decode(buf.getBuffer()); } catch (CharacterCodingException cce) { throw Utils.makeError(cx, funObj, cce.toString(), Constants.EINVAL); } return decoded.toString(); }
@JSFunction public static Object encodeString(Context cx, Scriptable thisObj, Object[] args, Function funObj) { String str = stringArg(args, 0); String encoding = stringArg(args, 1); IconvModuleImpl self = (IconvModuleImpl)thisObj; Charset cs = self.getCharset(cx, funObj, encoding); CharsetEncoder enc = cs.newEncoder(); enc.onUnmappableCharacter(CodingErrorAction.REPLACE); ByteBuffer decoded; try { decoded = enc.encode(CharBuffer.wrap(str)); } catch (CharacterCodingException cce) { throw Utils.makeError(cx, funObj, cce.toString(), Constants.EINVAL); } return Buffer.BufferImpl.newBuffer(cx, funObj, decoded, false); }
@JSFunction @SuppressWarnings("unused") public static void commit(Context cx, Scriptable thisObj, Object[] args, Function func) { final Function cb = functionArg(args, 0, true); final JdbcConnection self = (JdbcConnection)thisObj; final Object domain = self.runtime.getDomain(); self.runtime.getAsyncPool().execute(new Runnable() { @Override public void run() { try { synchronized (self) { self.conn.commit(); } self.runtime.enqueueCallback(cb, cb, self, ScriptRuntime.emptyArgs); } catch (SQLException sqle) { self.returnError(cb, domain, sqle); } } }); }
@JSFunction @SuppressWarnings("unused") public static Object createDocument(Context cx, Scriptable thisObj, Object[] args, Function funObj) { ensureArg(args, 0); XmlWrapImpl self = (XmlWrapImpl)thisObj; Source src = self.getSource(cx, args[0]); ScriptableObject ret = (ScriptableObject)cx.newObject(thisObj); ret.associateValue("document", src); return ret; }
@JSFunction @SuppressWarnings("unused") public static void close(Context cx, Scriptable thisObj, Object[] args, Function func)
@JSFunction @SuppressWarnings("unused") public static Object createStylesheet(Context cx, Scriptable thisObj, Object[] args, Function funObj) { ensureArg(args, 0); XmlWrapImpl self = (XmlWrapImpl)thisObj; Source src = self.getSource(cx, args[0]); try { // Keep in mind that we are in Node.js and the factory will be single-threaded. // Set the error listener to prevent stuff being written to standard error. Err errs = new Err(); self.transFactory.setErrorListener(errs); Templates tmpl = self.transFactory.newTemplates(src); ScriptableObject ret = (ScriptableObject)cx.newObject(thisObj); ret.associateValue("template", tmpl); return ret; } catch (TransformerConfigurationException e) { throw Utils.makeError(cx, thisObj, "XSLT transformer exception: " + e); } }
@JSFunction @SuppressWarnings("unused") public static void createConnection(Context cx, Scriptable thisObj, Object[] args, Function func)
@JSFunction @SuppressWarnings("unused") public static void executeStreaming(Context cx, Scriptable thisObj, Object[] args, Function func)
@JSFunction @SuppressWarnings("unused") public static Object transform(Context cx, Scriptable thisObj, Object[] args, Function funObj)
@JSFunction public static Object convert(Context cx, Scriptable thisObj, Object[] args, Function funObj) { ensureArg(args, 0); boolean lastChunk = booleanArg(args, 1, true); ByteBuffer inBuf; IconvImpl self = (IconvImpl)thisObj; if (args[0] == null) { inBuf = null; } else { Buffer.BufferImpl b = objArg(args, 0, Buffer.BufferImpl.class, true); inBuf = b.getBuffer(); } try { ByteBuffer result = self.converter.convert(inBuf, lastChunk); if (lastChunk) { self.converter.reset(); } if (result == null) { return null; } return Buffer.BufferImpl.newBuffer(cx, funObj, result, false); } catch (UnmappableCharacterException uce) { throw Utils.makeError(cx, funObj, uce.toString(), Constants.EILSEQ); } catch (CharacterCodingException cce) { throw Utils.makeError(cx, funObj, cce.toString(), Constants.EINVAL); } } }