我有一个非常奇怪的错误,只发生在 chrome 和 safari 中。
调用 GWT.Create(foo.class); 时出现 UmbrellaException;(延迟绑定)
有人知道吗?
我发现 java 脚本使用以下 javascript 引发了一个伞式异常:
function entry_0(jsFunction){
return function(){
try {
return entry0(jsFunction, this, arguments);
}
catch (e) {
throw e;
Uncaught com.google.web.bindery.event.shared.UmbrellaException: Exception caught: Exception caught: null
}
}
;
}
在 gwt 中,它在特定的 java 代码上
IAmsPresenterFactory factory = (IAmsPresenterFactory) GWT.create(IReflectiveAmsFactory.class);
其中 IReflectiveAmsFactory 是按类名(字符串)创建实例...(名称 gwt 的类)
public class IReflectiveAmsFactory implements IAmsFactoryWrapper {
}
public interface IAmsPresenterFactory {
IDynamicAmsPresenter newInstance(String className, AmsClientFactory clientfactory, String id);
}
<generate-with class="ch.zhaw.ams.server.ams.AmsPresenterGenerator">
<when-type-assignable class="ch.zhaw.ams.client.ams.IAmsFactoryWrapper" />
</generate-with>
完整的代码片段:
Request<IModuleBaseProxy> req = clientfactory.getRequestFactory().moduleRequest().findModuleBase(modtoken);
req.fire(new Receiver<IModuleBaseProxy>() {
@Override
public void onSuccess(IModuleBaseProxy response) {
System.out.println("found");
if (response != null) {
---> HERE
IAmsPresenterFactory factory = (IAmsPresenterFactory) GWT
---> ERROR .create(IReflectiveAmsFactory.class);
String clazz = response.getConfigSite();
AmsClientFactory apcf = null;
if (clientfactory == null) {
apcf = new AmsClientFactory();
} else {
apcf = clientfactory;
}
IDynamicAmsPresenter p = factory.newInstance(clazz, apcf, modtoken);
HasWidgets content = view.getContent();
// ContentPresenter contentPresenter = new
// ContentPresenter(apcf, p, new
// ContentView(modtoken));
p.go(content);
}
}
});
我的发电机类:
import java.io.PrintWriter;
import com.google.gwt.core.ext.Generator;
import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;
public class AmsPresenterGenerator extends Generator {
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
throws UnableToCompleteException {
logger.log(TreeLogger.INFO, "Generating source for " + typeName, null);
TypeOracle typeOracle = context.getTypeOracle();
JClassType clazz = typeOracle.findType(typeName);
if (clazz == null) {
logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
throw new UnableToCompleteException();
}
try {
logger.log(TreeLogger.INFO, "Generating source for " + clazz.getQualifiedSourceName(), null);
JClassType reflectableType = typeOracle.getType("ch.zhaw.ams.client.ams.IDynamicAmsPresenter");
SourceWriter sourceWriter = getSourceWriter(clazz, context, logger);
if (sourceWriter != null) {
sourceWriter.println("public " + reflectableType.getQualifiedSourceName()
+ " newInstance(String className, AmsClientFactory clientfactory, String id) {");
JClassType[] types = typeOracle.getTypes();
int count = 0;
for (int i = 0; i < types.length; i++) {
// System.out.println(""+types[i].getName());
if (types[i].isInterface() == null && types[i].isAssignableTo(reflectableType)) {
System.out.println("Done:" + types[i].getName());
if (count == 0) {
sourceWriter.println(" if(\"" + types[i].getQualifiedSourceName()
+ "\".equals(className)) {" + " return new " + types[i].getQualifiedSourceName()
+ "(clientfactory, id);" + "}");
} else {
sourceWriter.println(" else if(\"" + types[i].getQualifiedSourceName()
+ "\".equals(className)) {" + " return new " + types[i].getQualifiedSourceName()
+ "(clientfactory, id);" + "}");
}
count++;
}
}
sourceWriter.println("return null;");
sourceWriter.println("}");
sourceWriter.commit(logger);
logger.log(TreeLogger.INFO, "Done Generating source for " + clazz.getName(), null);
return clazz.getQualifiedSourceName() + "Wrapper";
}
} catch (NotFoundException e) {
e.printStackTrace();
}
return null;
}
public SourceWriter getSourceWriter(JClassType classType, GeneratorContext context, TreeLogger logger) {
String packageName = classType.getPackage().getName();
String simpleName = classType.getSimpleSourceName() + "Wrapper";
ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
composer.addImplementedInterface("ch.zhaw.ams.client.ams.IAmsPresenterFactory");
PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
if (printWriter == null) {
return null;
} else {
SourceWriter sw = composer.createSourceWriter(context, printWriter);
return sw;
}
}
}