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.Map;
20  import org.apache.tools.ant.util.FileNameMapper;
21  import org.apache.tools.ant.util.RegexpPatternMapper;
22  import com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason;
23  import com.geekologue.md4j.tools.ant.HibernateMappingProcessorTask;
24  
25  /***
26   * Creates Search or CRUD Struts 1.x Action Form Beans depending on the
27   * "actionType" XSLT param (see constructor. StrutsAction1Generator uses
28   * instances of this class as nested generators to create Struts Form Bean Java
29   * classes.
30   * 
31   * @author manos
32   */
33  public class StrutsAction1NestedFormBeanGenerator extends
34          AbstractXsltBasedGenerator implements HibernateMappingProcessorLiason {
35      private static final String XSLT_PATH = "md4j-strutsaction1-formbean.xsl";
36  
37      /***
38       * 
39       */
40      public StrutsAction1NestedFormBeanGenerator(Map xslParams) {
41          super(StrutsAction1NestedFormBeanGenerator.XSLT_PATH);
42          this.styleParameters = xslParams;
43      }
44  
45      /***
46       * Equal to <regexpmapper handledirsep="true" from="(.*)/(.*).hbm.xml"
47       * to="\1/web/\2@{actionType}Form.java" />
48       * 
49       * @see com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason#getSimpleMapper()
50       */
51      public FileNameMapper getSimpleMapper() {
52          RegexpPatternMapper simpleMapper = new RegexpPatternMapper();
53          simpleMapper.setHandleDirSep(true);
54          simpleMapper.setFrom("(.*)/(.*).hbm.xml");
55          simpleMapper.setTo("//1/web///2"
56                  + this.styleParameters.get("actionType") + "Form.java");
57          return simpleMapper;
58      }
59  
60      /***
61       * 
62       * @see com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason#getSimpleMapper()
63       */
64      public FileNameMapper getNestedMapper() {
65          throw new RuntimeException("Nested mapppers are yet to be suported");
66      }
67  
68      public void init(Map context) {
69          this.styleParameters.put("package", context.get("package"));
70          super.init(context);
71      }
72  }