private <T> JsonpRequest<T> send( @IsTrustedResourceUri String url, AsyncCallback<T> callback, boolean expectInteger) { JsonpRequest<T> request; if (predeterminedId != null) { request = new JsonpRequest<T>(callback, timeout, expectInteger, callbackParam, failureCallbackParam, predeterminedId); } else { request = new JsonpRequest<T>(callback, timeout, expectInteger, callbackParam, failureCallbackParam); } request.send(url); return request; } }
private static String nextCallbackId() { return INCREMENTAL_ID_PREFIX + getAndIncrementCallbackCounter(); }
registerCallbacks(CALLBACKS, canHaveMultipleRequestsForSameId); StringBuilder uri = new StringBuilder(baseUri); uri.append(baseUri.contains("?") ? "&" : "?"); getHeadElement().appendChild(script);
/** * Cancels a pending request. Note that if you are using preset ID's, this * will not work, since there is no way of knowing if there are other * requests pending (or have already returned) for the same data. */ public void cancel() { timer.cancel(); unload(); }
private void onFailure(String message) { onFailure(new Exception(message)); }
/** * Create a new JSONP request. * * @param callback The callback instance to notify when the response comes * back * @param timeout Time in ms after which a {@link TimeoutException} will be * thrown * @param expectInteger Should be true if T is {@link Integer}, false * otherwise * @param callbackParam Name of the url param of the callback function name * @param failureCallbackParam Name of the url param containing the * failure callback function name, or null for no failure callback */ JsonpRequest(AsyncCallback<T> callback, int timeout, boolean expectInteger, String callbackParam, String failureCallbackParam) { callbackId = nextCallbackId(); this.callback = callback; this.timeout = timeout; this.expectInteger = expectInteger; this.callbackParam = callbackParam; this.failureCallbackParam = failureCallbackParam; this.canHaveMultipleRequestsForSameId = false; }
/** * Create a new JSONP request with a hardcoded id. This could be used to * manually control which resources are considered duplicates (by giving them * identical ids). Could also be used if the callback name needs to be * completely user controlled (since the id is part of the callback name). * * @param callback The callback instance to notify when the response comes * back * @param timeout Time in ms after which a {@link TimeoutException} will be * thrown * @param expectInteger Should be true if T is {@link Integer}, false * otherwise * @param callbackParam Name of the url param of the callback function name * @param failureCallbackParam Name of the url param containing the * failure callback function name, or null for no failure callback * @param id unique id for the resource that is being fetched */ JsonpRequest(AsyncCallback<T> callback, int timeout, boolean expectInteger, String callbackParam, String failureCallbackParam, String id) { callbackId = getPredeterminedId(id); this.callback = callback; this.timeout = timeout; this.expectInteger = expectInteger; this.callbackParam = callbackParam; this.failureCallbackParam = failureCallbackParam; this.canHaveMultipleRequestsForSameId = true; }
private void onSuccess(T data) { timer.cancel(); try { if (callback != null) { callback.onSuccess(data); } } finally { unload(); } }
private void onFailure(String message) { onFailure(new Exception(message)); }
/** * Create a new JSONP request. * * @param callback The callback instance to notify when the response comes * back * @param timeout Time in ms after which a {@link TimeoutException} will be * thrown * @param expectInteger Should be true if T is {@link Integer}, false * otherwise * @param callbackParam Name of the url param of the callback function name * @param failureCallbackParam Name of the url param containing the * failure callback function name, or null for no failure callback */ JsonpRequest(AsyncCallback<T> callback, int timeout, boolean expectInteger, String callbackParam, String failureCallbackParam) { callbackId = nextCallbackId(); this.callback = callback; this.timeout = timeout; this.expectInteger = expectInteger; this.callbackParam = callbackParam; this.failureCallbackParam = failureCallbackParam; this.canHaveMultipleRequestsForSameId = false; }
/** * Create a new JSONP request with a hardcoded id. This could be used to * manually control which resources are considered duplicates (by giving them * identical ids). Could also be used if the callback name needs to be * completely user controlled (since the id is part of the callback name). * * @param callback The callback instance to notify when the response comes * back * @param timeout Time in ms after which a {@link TimeoutException} will be * thrown * @param expectInteger Should be true if T is {@link Integer}, false * otherwise * @param callbackParam Name of the url param of the callback function name * @param failureCallbackParam Name of the url param containing the * failure callback function name, or null for no failure callback * @param id unique id for the resource that is being fetched */ JsonpRequest(AsyncCallback<T> callback, int timeout, boolean expectInteger, String callbackParam, String failureCallbackParam, String id) { callbackId = getPredeterminedId(id); this.callback = callback; this.timeout = timeout; this.expectInteger = expectInteger; this.callbackParam = callbackParam; this.failureCallbackParam = failureCallbackParam; this.canHaveMultipleRequestsForSameId = true; }
private <T> JsonpRequest<T> send(String url, AsyncCallback<T> callback, boolean expectInteger) { JsonpRequest<T> request; if (predeterminedId != null) { request = new JsonpRequest<T>(callback, timeout, expectInteger, callbackParam, failureCallbackParam, predeterminedId); } else { request = new JsonpRequest<T>(callback, timeout, expectInteger, callbackParam, failureCallbackParam); } request.send(url); return request; } }
registerCallbacks(CALLBACKS, canHaveMultipleRequestsForSameId); StringBuilder uri = new StringBuilder(baseUri); uri.append(baseUri.contains("?") ? "&" : "?"); getHeadElement().appendChild(script);
private void onFailure(Throwable ex) { timer.cancel(); try { if (callback != null) { callback.onFailure(ex); } } finally { unload(); } }
private void onFailure(String message) { onFailure(new Exception(message)); }
private static String nextCallbackId() { return INCREMENTAL_ID_PREFIX + getAndIncrementCallbackCounter(); }
/** * Create a new JSONP request. * * @param callback The callback instance to notify when the response comes * back * @param timeout Time in ms after which a {@link TimeoutException} will be * thrown * @param expectInteger Should be true if T is {@link Integer}, false * otherwise * @param callbackParam Name of the url param of the callback function name * @param failureCallbackParam Name of the url param containing the * failure callback function name, or null for no failure callback */ JsonpRequest(AsyncCallback<T> callback, int timeout, boolean expectInteger, String callbackParam, String failureCallbackParam) { callbackId = nextCallbackId(); this.callback = callback; this.timeout = timeout; this.expectInteger = expectInteger; this.callbackParam = callbackParam; this.failureCallbackParam = failureCallbackParam; this.canHaveMultipleRequestsForSameId = false; }
/** * Create a new JSONP request with a hardcoded id. This could be used to * manually control which resources are considered duplicates (by giving them * identical ids). Could also be used if the callback name needs to be * completely user controlled (since the id is part of the callback name). * * @param callback The callback instance to notify when the response comes * back * @param timeout Time in ms after which a {@link TimeoutException} will be * thrown * @param expectInteger Should be true if T is {@link Integer}, false * otherwise * @param callbackParam Name of the url param of the callback function name * @param failureCallbackParam Name of the url param containing the * failure callback function name, or null for no failure callback * @param id unique id for the resource that is being fetched */ JsonpRequest(AsyncCallback<T> callback, int timeout, boolean expectInteger, String callbackParam, String failureCallbackParam, String id) { callbackId = getPredeterminedId(id); this.callback = callback; this.timeout = timeout; this.expectInteger = expectInteger; this.callbackParam = callbackParam; this.failureCallbackParam = failureCallbackParam; this.canHaveMultipleRequestsForSameId = true; }
private <T> JsonpRequest<T> send(String url, AsyncCallback<T> callback, boolean expectInteger) { JsonpRequest<T> request; if (predeterminedId != null) { request = new JsonpRequest<T>(callback, timeout, expectInteger, callbackParam, failureCallbackParam, predeterminedId); } else { request = new JsonpRequest<T>(callback, timeout, expectInteger, callbackParam, failureCallbackParam); } request.send(url); return request; } }
registerCallbacks(CALLBACKS, canHaveMultipleRequestsForSameId); StringBuilder uri = new StringBuilder(baseUri); uri.append(baseUri.contains("?") ? "&" : "?"); getHeadElement().appendChild(script);