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