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.io.File;
20  import java.util.HashMap;
21  import java.util.HashSet;
22  import java.util.Iterator;
23  import java.util.Map;
24  import java.util.Set;
25  import org.apache.tools.ant.BuildException;
26  import com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason;
27  import com.geekologue.md4j.tools.ant.HibernateMappingProcessorTask;
28  
29  /***
30   * StrutsAction1Generator is actally a wrapper for it's nested generators that
31   * produce Actions, FormBeans and JSP pages
32   * 
33   * @author manos
34   */
35  public class StrutsAction1Generator implements HibernateMappingProcessorLiason {
36      private Set nesterGenerators = new HashSet();
37  
38      /***
39       * Default constructor
40       */
41      public StrutsAction1Generator() {
42      }
43  
44      /***
45       * @see com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason#init(com.geekologue.md4j.tools.ant.HibernateMappingProcessorTask)
46       */
47      public void init(Map context) {
48          // create nested generators for JSP 2.0 pages
49          this.nesterGenerators.add(createJspGenerator(context, "Search"));
50          this.nesterGenerators.add(createJspGenerator(context, "View"));
51          this.nesterGenerators.add(createJspGenerator(context, "Create"));
52          this.nesterGenerators.add(createJspGenerator(context, "Update"));
53          // create nested generators for Struts 1.x Forms
54          this.nesterGenerators.add(createFormbeanGenerator(context, "Search"));
55          this.nesterGenerators.add(createFormbeanGenerator(context, "Crud"));
56          // create nested generators for Struts 1.x CRUD Actions
57          this.nesterGenerators.add(createCrudActionGenerator(context, "Create"));
58          this.nesterGenerators.add(createCrudActionGenerator(context, "Update"));
59          // create nested generators for Struts 1.x load or search Actions
60          this.nesterGenerators.add(createLoadOrSearchActionGenerator(context,
61                  "Search"));
62          this.nesterGenerators.add(createLoadOrSearchActionGenerator(context,
63                  "View"));
64          this.nesterGenerators.add(createLoadOrSearchActionGenerator(context,
65                  "LoadCreate"));
66          this.nesterGenerators.add(createLoadOrSearchActionGenerator(context,
67                  "LoadUpdate"));
68      }
69  
70      private StrutsAction1NestedJsp2Generator createJspGenerator(Map context,
71              String actionType) {
72          Map params = new HashMap();
73          params.put("actionType", actionType);
74          StrutsAction1NestedJsp2Generator gen = new StrutsAction1NestedJsp2Generator(
75                  params);
76          gen.init(context);
77          return gen;
78      }
79  
80      private StrutsAction1NestedFormBeanGenerator createFormbeanGenerator(
81              Map context, String actionType) {
82          Map params = new HashMap();
83          params.put("actionType", actionType);
84          StrutsAction1NestedFormBeanGenerator gen = new StrutsAction1NestedFormBeanGenerator(
85                  params);
86          gen.init(context);
87          return gen;
88      }
89  
90      private StrutsAction1NestedCrudActionGenerator createCrudActionGenerator(
91              Map context, String actionType) {
92          Map params = new HashMap();
93          params.put("actionType", actionType);
94          StrutsAction1NestedCrudActionGenerator gen = new StrutsAction1NestedCrudActionGenerator(
95                  params);
96          gen.init(context);
97          return gen;
98      }
99  
100     private StrutsAction1NestedLoadOrSearchActionGenerator createLoadOrSearchActionGenerator(
101             Map context, String actionType) {
102         Map params = new HashMap();
103         params.put("actionType", actionType);
104         StrutsAction1NestedLoadOrSearchActionGenerator gen = new StrutsAction1NestedLoadOrSearchActionGenerator(
105                 params);
106         gen.init(context);
107         return gen;
108     }
109 
110     /***
111      * Dele=gate the call to nested generators
112      * 
113      * @see com.geekologue.md4j.tools.ant.HibernateMappingProcessorLiason#process(java.io.File,
114      *      java.lang.String)
115      */
116     public void process(File contextDir, String xmlFile) throws BuildException {
117         for (Iterator iter = this.nesterGenerators.iterator(); iter.hasNext();) {
118             ((AbstractXsltBasedGenerator) iter.next()).process(contextDir,
119                     xmlFile);
120         }
121     }
122 }