public static <T> T createInstanceOf(Class<T> type) { String script= "new " + type.getSimpleName() + "()"; return ScriptHelper.evalCasting(script, type, null); }
private void addFields(Object[] signatures, int modifier) { for (int i= 0; i < signatures.length; i++) { ScriptHelper.put("sig", signatures[i], this); String signature= ScriptHelper.evalCasting("sig.e", String.class, this); declaredFields.add(new Field(this, signature, modifier)); } }
@DelegateCode(ignore= true) public static ArrayBuffer createArrayBuffer(int length) { ScriptHelper.put("length", length, null); ArrayBuffer node= ScriptHelper.evalCasting("new ArrayBuffer(length)", ArrayBuffer.class, null); return node; } }
private static String executeHttpRequestInternal(boolean isAsync, String url, Map<String, String> parameters, final AsyncCallback<String> asyncCallback, boolean useGetMethod) throws UnsupportedEncodingException { ScriptHelper.put("url", url, null); final XMLHttpRequestExtension xmlHttpRequest= ScriptHelper.evalCasting("new XMLHttpRequest()", XMLHttpRequestExtension.class, null); xmlHttpRequest.open(useGetMethod ? "GET" : "POST", url, isAsync); xmlHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); String parameter= ""; if (parameters != null) for (Entry<String, String> entry : parameters.entrySet()) parameter+= URLEncoder.encode(entry.getKey(), "UTF-8") + "=" + URLEncoder.encode(entry.getValue(), "UTF-8") + "&"; if (isAsync) { xmlHttpRequest.setOnreadystatechange(new EventHandler() { public void handleEvent(Event evt) { if (xmlHttpRequest.getReadyState() == 4 && xmlHttpRequest.getStatus() == 200) asyncCallback.onSuccess(xmlHttpRequest.getResponseText()); else if (xmlHttpRequest.getStatus() == 404) asyncCallback.onError(); } }); } xmlHttpRequest.sendSync(parameter); return isAsync ? "" : (String) xmlHttpRequest.getResponseText(); }
public static Object newInstance(Class<?> componentType, int length) { ScriptHelper.put("componentType", componentType, null); ScriptHelper.put("length", length, null); String realName = ScriptHelper.evalCasting("componentType.realName", String.class, null); realName = "[L" + realName + ";"; ScriptHelper.put("classSignature", realName, null); Object eval = ScriptHelper.eval("dragomeJs.newArray(classSignature, [length]);", null); return eval; }
String url= (String) ScriptHelper.eval("((window.location.protocol === \"https:\") ? \"wss://\" : \"ws://\") + window.location.host + (location.pathname).substr(0, (location.pathname).lastIndexOf('/')) + s", this); ScriptHelper.put("url", url, this); WebSocket webSocket= ScriptHelper.evalCasting("new WebSocket(url)", WebSocket.class, this); webSocket.setOnopen(new EventListener()