View Javadoc

    1   /*
    2    * joey-gen and its relative products are published under the terms
    3    * of the Apache Software License.
    4    *
    5    * Created on 2005/01/14 13:18:32
    6    */
    7   package org.asyrinx.joey.gen.task.impl;
    8
    9   import java.io.File;
    10  import java.io.IOException;
    11  import java.util.HashMap;
    12  import java.util.Map;
    13
    14  import org.apache.tools.ant.BuildException;
    15  import org.apache.velocity.context.Context;
    16  import org.asyrinx.brownie.core.io.FileNameUtils;
    17  import org.asyrinx.joey.gen.task.BizLogicDistiller;
    18  import org.asyrinx.joey.gen.task.GenerationQuery;
    19
    20  /***
    21   * @author takeshi
    22   */
    23  public class BizLogicDistillerComposite implements BizLogicDistiller, GenerationQuery {
    24
    25      /***
    26       *
    27       */
    28      public BizLogicDistillerComposite() {
    29          super();
    30      }
    31
    32      private final Map distillers = new HashMap();
    33
    34      public boolean canGenerate(String inputTemplate, File outputFile, Context context) {
    35          final String ext = FileNameUtils.getExtension(outputFile.getName());
    36          final String distilled;
    37          try {
    38              distilled = this.distill(outputFile);
    39          } catch (IOException e) {
    40              throw new BuildException(e);
    41          }
    42          context.put("bizLogic", distilled);
    43          return this.distillers.containsKey(ext);
    44      }
    45
    46      public String distill(File source) throws IOException {
    47          final String ext = FileNameUtils.getExtension(source.getName());
    48          final BizLogicDistiller distiller = (BizLogicDistiller) distillers.get(ext);
    49          if (distiller != null)
    50              return distiller.distill(source);
    51          else
    52              return "";
    53      }
    54
    55      public void put(String ext, BizLogicDistiller distiller) {
    56          this.distillers.put(ext, distiller);
    57      }
    58
    59  }