View Javadoc

1   /*
2    * Copyright Emmanouil Batsis
3    * 
4    * Licensed under the GNU General Public License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.gnu.org/licenses/gpl.txt
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   * 
16   */
17  package com.geekologue.md4j.generators;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  import org.apache.tools.ant.util.FileNameMapper;
22  import org.apache.tools.ant.util.RegexpPatternMapper;
23  import com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason;
24  import com.geekologue.md4j.tools.ant.HibernateMappingProcessorTask;
25  
26  /***
27   * Context parameters:
28   * <ul>
29   * <li>singletonDaos: Whether to use JVM Singleton DAOs
30   * </ul>
31   * 
32   * @author manos
33   */
34  public class Ejb21Generator extends AbstractXsltBasedGenerator implements
35          HibernateMappingProcessorLiason {
36      private static final String XSLT_PATH = "md4j-ejb-21.xsl";
37  
38      /***
39       * 
40       */
41      public Ejb21Generator() {
42          super(Ejb21Generator.XSLT_PATH);
43      }
44  
45      /***
46       * @see com.geekologue.md4j.tools.ant.generators.XsltGeneratorSettings#getStylePath()
47       */
48      public String getStylePath() {
49          return Ejb21Generator.XSLT_PATH;
50      }
51  
52      /***
53       * Equal to &lt;regexpmapper handledirsep="true" from="(.*)/(.*).hbm.xml"
54       * to="\1/business/\2ManagerBean.java" /&gt;
55       * 
56       * @see com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason#getSimpleMapper()
57       */
58      public FileNameMapper getSimpleMapper() {
59          RegexpPatternMapper simpleMapper = new RegexpPatternMapper();
60          simpleMapper.setHandleDirSep(true);
61          simpleMapper.setFrom("(.*)/(.*).hbm.xml");
62          simpleMapper.setTo("//1/business///2ManagerBean.java");
63          return simpleMapper;
64      }
65  
66      /***
67       * 
68       * @see com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason#getSimpleMapper()
69       */
70      public FileNameMapper getNestedMapper() {
71          throw new RuntimeException("Nested mapppers are yet to be suported");
72      }
73  
74      /***
75       * Initializes XSLT parameters etc
76       * 
77       * @see com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason#init(java.util.Map)
78       */
79      public void init(Map context) {
80          this.styleParameters.put("package", context.get("package"));
81          // note the diff between the two keys
82          this.styleParameters.put("ejbMethod", context
83                  .get("ejbdocletViewMethod"));
84          this.styleParameters.put("singletonDaos", context.get("singletonDaos"));
85          super.init(context);
86      }
87  }