ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(
packageName, className);
composer.setSuperclass(requestedType);
SourceWriter w = composer.createSourceWriter(context, printWriter);
w.println("public void init() {");
w.indent();
for (ConnectorBundle bundle : bundles) {
detectBadProperties(bundle, logger);
String name = bundle.getName();
boolean isEager = name
.equals(ConnectorBundleLoader.EAGER_BUNDLE_NAME);
w.print("addAsyncBlockLoader(new AsyncBundleLoader(\"");
w.print(escape(name));
w.print("\", ");
w.print("new String[] {");
for (Entry<JClassType, Set<String>> entry : bundle.getIdentifiers()
.entrySet()) {
Set<String> identifiers = entry.getValue();
for (String id : identifiers) {
w.print("\"");
w.print(escape(id));
w.print("\",");
}
}
w.println("}) {");
w.indent();
w.print("protected void load(final ");
w.print(TypeDataStore.class.getName());
w.println(" store) {");
w.indent();
if (!isEager) {
w.print(GWT.class.getName());
w.print(".runAsync(");
}
w.println("new %s() {", RunAsyncCallback.class.getName());
w.indent();
w.println("public void onSuccess() {");
w.indent();
w.println("load();");
w.println("%s.get().setLoaded(getName());",
ConnectorBundleLoader.class.getName());
// Close onSuccess method
w.outdent();
w.println("}");
w.println("private void load() {");
w.indent();
String loadNativeJsBundle = "loadJsBundle";
printBundleData(logger, w, bundle, loadNativeJsBundle);
// Close load method
w.outdent();
w.println("}");
// Separate method for loading native JS stuff (e.g. callbacks)
String loadNativeJsMethodName = "loadNativeJs";
// To support fields of type long (#13692)
w.println("@com.google.gwt.core.client.UnsafeNativeLong");
w.println("private native void %s(%s store) /*-{",
loadNativeJsMethodName, TypeDataStore.class.getName());
w.indent();
List<String> jsMethodNames = printJsBundleData(logger, w, bundle,
loadNativeJsMethodName);
w.outdent();
w.println("}-*/;");
// Call all generated native method inside one Java method to avoid
// refercences inside native methods to each other
w.println("private void %s(%s store) {", loadNativeJsBundle,
TypeDataStore.class.getName());
w.indent();
printLoadJsBundleData(w, loadNativeJsBundle, jsMethodNames);
w.outdent();
w.println("}");
// onFailure method declaration starts
w.println("public void onFailure(Throwable reason) {");
w.indent();
w.println("%s.get().setLoadFailure(getName(), reason);",
ConnectorBundleLoader.class.getName());
w.outdent();
w.println("}");
// Close new RunAsyncCallback() {}
w.outdent();
w.print("}");
if (isEager) {
w.println(".onSuccess();");
} else {
w.println(");");
}
// Close load method
w.outdent();
w.println("}");
// Close add(new ...
w.outdent();
w.println("});");
}
if (cvalInfos != null && !cvalInfos.isEmpty()) {
w.println("{");
for (CValUiInfo c : cvalInfos) {
if ("evaluation".equals(c.type)) {
w.println("cvals.add(new CValUiInfo(\"" + c.product
+ "\", \"" + c.version + "\", \"" + c.widgetset
+ "\", null));");
}
}
w.println("}");
}
w.outdent();
w.println("}");
w.commit(logger);
}