1

GWTの据え置きバインディングジェネレーターを使用して、多くのボタンを含むjavaファイルとui.xmlファイルを生成しようとしました。

私のJavaファイルは生成され、私の-genの場所にうまく書き込まれます。しかし、対応するui.xmlファイルは私の-genフォルダーになく、その理由はわかりません。

ui.xmlファイルを作成する私の関数は次のようになります。

public String generate(TreeLogger logger, GeneratorContext context,
      String typeName) throws UnableToCompleteException {

    try {
      SourceWriter sw = getSourceWriter(typeName, context, logger);
      assert(sw != null);
      // after the file got created, I write the class content
      /* ... */ UiBinder Java code

      createUiXMLFile(typeName, context, logger);

      sw.commit(logger); 
      // after this command the java class file is written is to -gen folder
      System.out.println("class '" + typeName +  "Generated' was created succesfully");
      return typeName + "Generated";
    } catch(Exception e) {
      e.printStackTrace();
      return null;
    }
}


public void createUiXMLFile(String typeName, GeneratorContext context, 
        TreeLogger logger) throws Exception {

    // gets the type given by the String typeName
    JClassType classType = context.getTypeOracle().getType(typeName);
    // gets the package in which the new class should get created
    String packageName = classType.getPackage().getName();
    // gets the name of the class without the package name
    String simpleName = classType.getSimpleSourceName();
    simpleName = simpleName + "Generated";
    // for us to see what classes were generated by this generator

    OutputStream os = context.tryCreateResource(logger, 
          packageName.replace(".", "/")+"/"+simpleName+".ui.xml");
    // it does also not work if I just use
    // context.tryCreateResource(logger, simpleName+".ui.xml");

    ByteArrayOutputStream baus = new ByteArrayOutputStream();
    // just for testing, that I wrote the XML code into the PrintWriter
    PrintWriter pw = new PrintWriter(baus);

    pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    /* the UiBinder XML code ... */
    pw.println("</ui:UiBinder>");
    pw.flush();

    FileOutputStream fout = new FileOutputStream("C:\\...\\view\\UnicodeCharViewGenerated.ui.xml");
    fout.write(baus.toByteArray());
    fout.close();

    os.write(baus.toByteArray());
    context.commitResource(logger, os);
    // even after doing the commit the file is not written to the -gen location
}

Oracleに新しいファイルを追加するために関数を呼び出すのを忘れたと思います。しかし、どのメソッドを呼び出すべきかわかりません。

FileOutputStreamを使用して、ui.xmlファイルをEclipseワークスペースに直接書き込むと、機能しません。しかし、この行をコメントアウトすると、コンパイラーは.ui.xmlファイルを見つけることができず、遅延バインディングが失敗します。

4

1 に答える 1

-2

Javaスクリプト(gwt)による私の知識によると、コンテンツ(バイト配列)をシステムのドライブに書き込むことはできません。

于 2013-03-06T17:21:04.387 に答える