1

次のような構成ストア クラスがいくつかあります。

public class Configuration {

    private static final Map<DocType, Map<ReportType, Template>> templates = new HashMap<>();

    static {
        Map<ReportType, Template> docZeroTemplates = new HashMap<>();
        docZeroTemplates.put(REPORT_ZERO, new Template("/templates/ReportZero.jrxml", ReportZeroSource.class));
        docZeroTemplates.put(REPORT_ONE, new Template("/templates/ReportOne.jrxml", ReportOneSource.class));
        templates.put(DocType.DOC_ZERO, docZeroTemplates);
    }

}

利点:

  • IDE によって提供されるリファクタリングとナビゲーションのサポート。

短所:

  • よくわかりませんが、何か問題があるようです。

それが構成と呼ばれるべきかどうかさえわかりません。そのようなクラスを XML に置き換える必要がありますか? このような:

<configuration>
  <document type="document0">
    <reports>
      <report type="report0">
        <path>/templates/document0/report0.jrxml</path>
        <source>org.company.report.ReportZero</source>
      </report>
    </reports>
  </document>
</configuration>
4

0 に答える 0