com.googlecode.gwt.test.internal.resources.TextResourceCallback Maven / Gradle / Ivy
package com.googlecode.gwt.test.internal.resources;
import com.google.gwt.resources.client.TextResource;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.List;
/**
* Callback interface where {@link TextResource } methods calls are redirected. For internal
* use only.
*
* @author Gael Lazzari
*/
class TextResourceCallback implements ResourcePrototypeCallback {
private static interface TextReader {
String readText() throws Exception;
}
private final TextReader textReader;
TextResourceCallback(final List resourceURLs) {
textReader = new TextReader() {
public String readText() throws Exception {
return TextResourceReader.get().readFiles(resourceURLs);
}
};
}
TextResourceCallback(final String text) {
textReader = new TextReader() {
public String readText() throws Exception {
return text;
}
};
}
public Object call(Method method, Object[] args) throws Exception {
if (method.getName().equals("getText")) {
return textReader.readText();
}
return null;
}
}