クロムとサファリでのみ発生する、非常に奇妙なエラーがあります。
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;
}
}
}