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/13 17:58:48
    6    */
    7   package org.asyrinx.joey.gen.core.impl;
    8
    9   import org.asyrinx.brownie.seasar.aop.CacheInterceptor;
    10  import org.asyrinx.joey.gen.ant.DatabasesLoaderImpl;
    11  import org.asyrinx.joey.gen.ant.ModelLoaderImpl;
    12  import org.asyrinx.joey.gen.command.rdb2java.standard.BasicBuilder;
    13  import org.asyrinx.joey.gen.core.BizLogicDistiller;
    14  import org.asyrinx.joey.gen.model.rdb.xml.XmlToRdbImpl;
    15  import org.seasar.framework.container.InitMethodDef;
    16  import org.seasar.framework.container.S2Container;
    17  import org.seasar.framework.container.impl.ArgDefImpl;
    18  import org.seasar.framework.container.impl.AspectDefImpl;
    19  import org.seasar.framework.container.impl.ComponentDefImpl;
    20  import org.seasar.framework.container.impl.InitMethodDefImpl;
    21  import org.seasar.framework.container.impl.S2ContainerImpl;
    22
    23  /***
    24   * @author takeshi
    25   */
    26  public class S2ContainerLoader {
    27
    28      private static S2Container container = null;
    29
    30      public static S2Container getContainer() {
    31          if (container == null)
    32              container = initContainer();
    33          return container;
    34      }
    35
    36      /***
    37       * @return
    38       */
    39      private static S2Container initContainer() {
    40          //log.debug("JoeyGenerateTask#initContainer");
    41          //ClassLoaderがちゃんとdiconファイルやDTDを読んでくれないので、仕方なく自分でコンポーネント定義をコーディング
    42          //BrownieS2ContainerFactory.create("joey-gen.dicon",
    43          // this.getProject().getBaseDir().getAbsolutePath());
    44          final S2Container result = new S2ContainerImpl();
    45          result.register(XmlToRdbImpl.class);
    46          final ComponentDefImpl databasesLoaderDef = new ComponentDefImpl(DatabasesLoaderImpl.class);
    47          databasesLoaderDef.addAspectDef(new AspectDefImpl(new CacheInterceptor()));
    48          result.register(databasesLoaderDef);
    49          final ComponentDefImpl javaBuilderDef = new ComponentDefImpl(BasicBuilder.class);
    50          javaBuilderDef.addAspectDef(new AspectDefImpl(new CacheInterceptor()));
    51          result.register(javaBuilderDef);
    52          final ComponentDefImpl modelLoaderDef = new ComponentDefImpl(ModelLoaderImpl.class);
    53          result.register(modelLoaderDef);
    54          //
    55          final BizLogicDistiller javaDistiller = new BizLogicDistillerByLine( //
    56                  "// joey user's biz logic begin", //
    57                  "// joey user's biz logic end");
    58          final BizLogicDistiller xmlDistiller = new BizLogicDistillerByLine( //
    59                  "<!-- joey user's biz logic begin -->", //
    60                  "<!-- joey user's biz logic end -->");
    61          final ComponentDefImpl distillerCompositeDef = new ComponentDefImpl(BizLogicDistillerComposite.class);
    62          distillerCompositeDef.addInitMethodDef(newPutMethod("java", javaDistiller));
    63          distillerCompositeDef.addInitMethodDef(newPutMethod("dicon", xmlDistiller));
    64          distillerCompositeDef.addInitMethodDef(newPutMethod("xml", xmlDistiller));
    65          distillerCompositeDef.addInitMethodDef(newPutMethod("jwc", xmlDistiller));
    66          distillerCompositeDef.addInitMethodDef(newPutMethod("page", xmlDistiller));
    67          distillerCompositeDef.addInitMethodDef(newPutMethod("html", xmlDistiller));
    68          distillerCompositeDef.addInitMethodDef(newPutMethod("application", xmlDistiller));
    69          result.register(distillerCompositeDef);
    70          //
    71          final ComponentDefImpl velocityGeneratorDef = new ComponentDefImpl(JoeyVelocityGeneratorImpl.class);
    72          //velocityGeneratorDef.addPropertyDef(new PropertyDefImpl("query",
    73          // GenerationQuery.DONT_OVERWRITE));
    74          //velocityGeneratorDef.addPropertyDef(new PropertyDefImpl("query",
    75          // GenerationQuery.THROUGH));
    76          result.register(velocityGeneratorDef);
    77          return result;
    78      }
    79
    80      public static InitMethodDef newPutMethod(String ext, BizLogicDistiller distiller) {
    81          final InitMethodDefImpl result = new InitMethodDefImpl("put");
    82          result.addArgDef(new ArgDefImpl(ext));
    83          result.addArgDef(new ArgDefImpl(distiller));
    84          return result;
    85      }
    86
    87  }