com.google.gwt.resources.client.ResourcePrototype Java Examples

The following examples show how to use com.google.gwt.resources.client.ResourcePrototype. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsAssetsProvider.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String loadAsset(String name) {
    name = name.replace('.', '_');

    Log.d("AssetsRuntime", "loadAsset: " + name);
    for (ClientBundleWithLookup b : bundles) {
        ResourcePrototype res = b.getResource(name);
        if (res != null) {
            Log.d("AssetsRuntime", "loadAsset " + res);
            return ((TextResource) res).getText();
        }
    }

    return null;
}
 
Example #2
Source File: FakeClientBundleProvider.java    From gwtmockito with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a fake resource class that returns its own name where possible.
 */
@SuppressWarnings("unchecked") // safe since the proxy implements type
private <T> T createFakeResource(Class<T> type, final String name) {
  return (T) Proxy.newProxyInstance(
      FakeClientBundleProvider.class.getClassLoader(),
      new Class<?>[] {type},
      new InvocationHandler() {
        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Exception {
          Class<?> returnType = method.getReturnType();
          if (returnType == String.class) {
            return name;
          } else if (returnType == SafeHtml.class) {
            return SafeHtmlUtils.fromTrustedString(name);
          } else if (returnType == SafeUri.class) {
            return UriUtils.fromTrustedString(name);
          } else if (returnType == boolean.class) {
            return false;
          } else if (returnType == int.class) {
            return 0;
          } else if (method.getParameterTypes().length > 0
              && method.getParameterTypes()[0] == ResourceCallback.class) {
            // Read the underlying resource type out of the generic parameter
            // in the method's argument
            Class<?> resourceType = 
                (Class<?>) 
                ((ParameterizedType) args[0].getClass().getGenericInterfaces()[0])
                .getActualTypeArguments()[0];
            ((ResourceCallback<ResourcePrototype>) args[0]).onSuccess(
                (ResourcePrototype) createFakeResource(resourceType, name));
            return null;
          } else if (returnType.isInstance(proxy)) {
            // for custom methods producing ResourcePrototype
            return proxy;
          } else {
            throw new IllegalArgumentException(
                "Unexpected return type for method " + method.getName());
          }
        }
      });
}