ontomde-uml2-struts 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,89 @@
1
+
2
+
3
+ module Mrdf_Model
4
+
5
+ def struts_generateSpringApplicationContext
6
+ return unless context[:struts_useSpring]
7
+ mtk_writeSession("#{context[:webContentDir]}/WEB-INF/applicationContext.xml") {
8
+ struts_writeSpringApplicationContext
9
+ }
10
+ end
11
+
12
+ def struts_writeSpringApplicationContext
13
+
14
+ write <<END
15
+ <?xml version="1.0" encoding="UTF-8"?>
16
+
17
+ <beans xmlns="http://www.springframework.org/schema/beans"
18
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19
+ xmlns:aop="http://www.springframework.org/schema/aop"
20
+ xmlns:tx="http://www.springframework.org/schema/tx"
21
+ xsi:schemaLocation="
22
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
23
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
24
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
25
+
26
+ <!-- ===========================actions struts ================================ -->
27
+
28
+ #{mtk_stss { struts_writeSpringStrutsBean }}
29
+
30
+ <!-- ============================================ DAO beans =================================== -->
31
+
32
+ #{mtk_stss { struts_writeSpringBean }}
33
+
34
+ <!-- scope="prototype" because PersistenceContextType is extended and thus not thread safe. We need to have a single private PersistenceContext for the duration of the transaction. We need EXTENTED because SGBD need to be accessed read-only from JSPs, after transaction has been committed -->
35
+ <bean id="#{Muml_Class::DB_Context.gsub(/^.*\./,'')}" class="#{Muml_Class::DB_Context}" scope="prototype" />
36
+ <bean class="#{Muml_Class::DB_Context}$#{Muml_Class::DB_Context.gsub(/^.*\./,'')}SpringContext" />
37
+ </beans>
38
+ END
39
+
40
+ end
41
+ def struts_springIgnore(b)
42
+ return true if b.struts_action_one0.nil?
43
+ #return true if b.java_DAOClass_one0.nil?
44
+ return false
45
+ end
46
+ def struts_writeSpringStrutsBean
47
+ eachStrutsBean { |b|
48
+ next if struts_springIgnore(b)
49
+ #puts "b=#{b.java_qualifiedName}"
50
+
51
+ if b.struts_action_one.nil?
52
+ #puts "!!!! #{b} n'a pas de struts_action"
53
+ next
54
+ end
55
+ suffixes=["-new"]
56
+ b.struts_ownedTab.each {|tab|
57
+ idOnglet=tab.java_Name_one
58
+ suffixes<< "#{idOnglet}-submit"
59
+ }
60
+ suffixes.each { |suffix|
61
+ if b.uml_isAbstract?
62
+ write("<!-- ignore abstract : #{b.java_Name} -->\n")
63
+ else
64
+ write <<END
65
+ <bean name="/#{b.java_Name}#{suffix}"
66
+ parent="txProxyTemplate"
67
+ scope="session">
68
+ <property name="target"><bean class="#{b.struts_action_one.java_qualifiedName}"/></property>
69
+ </bean>
70
+ END
71
+ end
72
+ }}
73
+ end
74
+
75
+ def struts_writeSpringBean
76
+ # beans are no longer spring beans
77
+ return
78
+ eachStrutsBean { |b|
79
+ next if struts_springIgnore(b)
80
+ dao=b.java_DAOClass_one
81
+ if b.uml_isAbstract?
82
+ write("<!-- ignore abstract : #{b.java_Name} -->\n")
83
+ else
84
+ write %{<bean id="#{dao.java_Name}" class="#{dao.java_qualifiedName}" />\n}
85
+ end
86
+ }
87
+ end
88
+
89
+ end #module
@@ -0,0 +1,232 @@
1
+
2
+ module Muml_Class
3
+ def struts_formName
4
+ return "#{java_qualifiedName.tr('.','_')}"
5
+ end
6
+
7
+ STRUTS_SWITCH_TO_FLEX_FORWARD="switchToFlexFwd"
8
+ FLEX_SWITCH_TO_JSP_PATH="/flex/switchToFlex.jsp"
9
+ NOGIF_FORWARD="NOGIF_FWD"
10
+
11
+ #STRUTS_DOWNLOAD_FORWARD="downloadFwd"
12
+ #STRUTS_DOWNLOAD_JSP_PATH="/download.jsp"
13
+ end
14
+
15
+ module Mrdf_Model
16
+
17
+ def struts_struts_config_generate
18
+ mtk_writeSession("#{context[:webContentDir]}/WEB-INF/struts-config.xml") {
19
+ struts_struts_config_writeFile
20
+ }
21
+ end
22
+
23
+
24
+
25
+
26
+ def struts_struts_config_writeFile
27
+ # CAUTION no CR befor <?xml> instruction
28
+ before=<<END
29
+ <?xml version="1.0" encoding="iso-8859-1"?>
30
+ <!DOCTYPE struts-config PUBLIC
31
+ "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
32
+ "http://struts.apache.org/dtds/struts-config_1_3.dtd">
33
+
34
+ <struts-config>
35
+ END
36
+ after=<<END
37
+ <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
38
+ <set-property property="pathnames" value="/WEB-INF/validation.xml, /WEB-INF/validator-rules.xml"/>
39
+ <set-property property="stopOnFirstError" value="true"/>
40
+ </plug-in>
41
+ </struts-config>
42
+ END
43
+
44
+ #<!ELEMENT struts-config (data-sources?, form-beans?, global-exceptions?, global-forwards?, action-mappings?, controller?, message-resources*, plug-in*)>
45
+
46
+ encloseWrite(before,after) {
47
+ struts_write_struts_config_form_beans
48
+ struts_struts_config_writeFile_GlobalException
49
+ struts_struts_config_writeFile_GlobalForwards
50
+ struts_write_struts_config_action_mappings
51
+ struts_writeSpringRequestProcess_controller
52
+ write(%{<!-- Message are in /WEB-INF/classes/ApplicationResources*.properties -->\n})
53
+ write(%{<message-resources parameter="MessageResources"/>\n})
54
+ struts_writeSpringRequestProcess_plugin
55
+ }
56
+ end
57
+ def struts_struts_config_writeFile_struts_config
58
+ end
59
+
60
+ def struts_struts_config_writeFile_GlobalException
61
+ before="<global-exceptions>"
62
+ after="</global-exceptions>"
63
+ encloseWrite(before,after) {
64
+ write <<ENDEXCEPTION
65
+ <exception
66
+ key="errors.ioException"
67
+ type="#{struts_getFunctionalException.java_qualifiedName}"
68
+ path="errorPage.jsp"
69
+ handler="#{struts_getExceptionHandlerClass.java_qualifiedName}"
70
+ />
71
+ ENDEXCEPTION
72
+ }
73
+ end
74
+
75
+ def struts_struts_config_writeFile_GlobalForwards
76
+ before=<<END
77
+ <global-forwards>
78
+ <forward name="#{Muml_Class::STRUTS_SWITCH_TO_FLEX_FORWARD}" path="#{Muml_Class::FLEX_SWITCH_TO_JSP_PATH}" />
79
+ <forward name="#{Muml_Class::NOGIF_FORWARD}" path="/res/orange/image/noImage.gif" />
80
+ END
81
+ after=<<END
82
+ </global-forwards>
83
+ END
84
+ encloseWrite(before,after) {
85
+ #<!--
86
+ # <global-forwards type="org.apache.struts.webapp.examples.CustomActionForward">
87
+ # <forward name="welcome" path="/welcome.do">
88
+ # <set-property property="example" value="EXAMPLE"/>
89
+ # </forward>
90
+ # </global-forwards>
91
+ #-->
92
+ struts_struts_config_writeFile_GlobalForwards_editAction
93
+ }
94
+ end
95
+ def struts_struts_config_writeFile_GlobalForwards_editAction
96
+ eachStrutsBean { |c|
97
+ b=c.struts_actionFormSrc_one0
98
+ next if b.nil?
99
+ write(%{<forward path="/#{b.java_Name}-new.do?#{Muml_Classifier::STRUTS_DISPATCH_FIELD_NAME}=#{Muml_Classifier::STRUTS_ACTION_STARTEDIT}"
100
+ name="#{b.struts_editForwardName}" redirect="false" />\n})
101
+ }
102
+
103
+ end
104
+
105
+ def struts_write_struts_config_form_beans
106
+ write %{ <form-beans>\n}
107
+
108
+ struts_ActionLocaleWriteActionBean
109
+
110
+ eachStrutsBean { |b|
111
+ b.struts_write_struts_config_form_bean
112
+ }
113
+ write %{ </form-beans>\n}
114
+ end
115
+
116
+ # struts-config configuration for spring
117
+ def struts_writeSpringRequestProcess_controller
118
+ return unless context[:struts_useSpring]
119
+ write <<END
120
+ <controller>
121
+ <set-property
122
+ property="processorClass"
123
+ value="org.springframework.web.struts.DelegatingRequestProcessor"
124
+ />
125
+ </controller>
126
+ END
127
+ end
128
+
129
+ def struts_writeSpringRequestProcess_plugin
130
+ return
131
+ return unless context[:struts_useSpring]
132
+ write <<END
133
+ <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
134
+ <set-property
135
+ property="contextConfigLocation"
136
+ value="/WEB-INF/applicationContext.xml, /WEB-INF/applicationContext-jpa.xml"
137
+ />
138
+ </plug-in>
139
+ END
140
+ end
141
+
142
+
143
+ def struts_write_struts_config_action_mappings
144
+ #write(%{<action-mappings type="org.apache.struts.webapp.examples.CustomActionMapping"> \n})
145
+ before=%{ <action-mappings> \n}
146
+ after=<<END
147
+ <action path="/Welcome" forward="/index.jsp" />
148
+ </action-mappings>
149
+ END
150
+
151
+ encloseWrite(before,after) {
152
+ write(%{#{struts_getReloadDefinitionsActionConfig}\n})
153
+ struts_ActionLocaleWriteActionPath
154
+ eachStrutsBean { |b|
155
+ b.struts_write_struts_config_action_mapping
156
+ }
157
+ }
158
+ end
159
+ end
160
+ module Muml_Class
161
+
162
+ STRUTS_EDIT_FWD_POSTFIX="_fwEdit"
163
+ def struts_editForwardName
164
+ return "#{java_Name}#{STRUTS_EDIT_FWD_POSTFIX}"
165
+ end
166
+ def struts_write_struts_config_form_bean
167
+ return if struts_actionForm.empty?
168
+
169
+ write <<END
170
+ <form-bean name="#{self.struts_actionForm_one.java_uniqueName}" type="#{struts_actionForm_one.java_qualifiedName}"/>
171
+ END
172
+ #<!-- set-property property="example" value="EXAMPLE"/ -->
173
+ end
174
+
175
+
176
+ def struts_get_struts_config_action_mapping_actionTypeClause
177
+ # if context[:struts_useSpring]
178
+ # return %{type="defined in spring"}
179
+ #else
180
+ return %{type="#{struts_action_one.java_qualifiedName}"}
181
+ #end
182
+ end
183
+
184
+
185
+
186
+ def struts_write_struts_config_action_mapping
187
+ return if struts_action.empty?
188
+
189
+ fwd=""
190
+ struts_ownedTab.each{ |tab|
191
+ idOnglet=tab.java_Name_one
192
+ fwd=fwd+%{\n <forward name="#{idOnglet}" path="/pages/#{java_InternalFilePath}form/#{java_Name}#{idOnglet}.jsp" />}
193
+ }
194
+
195
+ mtk_protected {
196
+
197
+ write <<END
198
+ <action path="/#{java_Name}-new"
199
+ #{struts_get_struts_config_action_mapping_actionTypeClause}
200
+ name="#{self.struts_actionForm_one.java_Name}"
201
+ scope="session"
202
+ validate="false"
203
+ cancellable="true"
204
+ parameter="#{Muml_Class::STRUTS_DISPATCH_FIELD_NAME}"
205
+ input="/pages/#{java_InternalFilePath}form/#{java_Name}#{struts_defaultTabId}.jsp"
206
+ >#{fwd}
207
+ <forward name="cancel" path="/Welcome.do" />
208
+ <forward name="#{STRUTS_INPUT_FWD}" path="/pages/#{java_InternalFilePath}form/#{java_Name}#{struts_defaultTabId}.jsp"/>
209
+ </action>
210
+ END
211
+ struts_ownedTab.each{ |tab|
212
+ idOnglet=tab.java_Name_one
213
+ #struts_tabs.each{|idOnglet|
214
+ write <<END
215
+ <action path="/#{java_Name}#{idOnglet}-submit"
216
+ #{struts_get_struts_config_action_mapping_actionTypeClause}
217
+ name="#{self.struts_actionForm_one.java_Name}"
218
+ scope="session"
219
+ validate="true"
220
+ cancellable="true"
221
+ parameter="#{Muml_Class::STRUTS_DISPATCH_FIELD_NAME}"
222
+ input="/pages/#{java_InternalFilePath}form/#{java_Name}#{idOnglet}.jsp"
223
+ >#{fwd}
224
+ <forward name="cancel" path="/Welcome.do" />
225
+ <forward name="#{STRUTS_INPUT_FWD}" path="/pages/#{java_InternalFilePath}form/#{java_Name}#{idOnglet}.jsp"/>
226
+ </action>
227
+ END
228
+ }
229
+ }
230
+ end
231
+
232
+ end # Muml_Class
@@ -0,0 +1,116 @@
1
+
2
+ module Mrdf_Model
3
+
4
+ def struts_validation_generate
5
+ mtk_writeSession("#{context[:webContentDir]}/WEB-INF/validation.xml") {
6
+ struts_validation_writeFile
7
+ }
8
+ end
9
+
10
+ def struts_validation_writeFile
11
+
12
+ # CAUTION no CR befor <?xml> instruction
13
+ write <<END
14
+ <?xml version="1.0" encoding="ISO-8859-1" ?>
15
+ <!DOCTYPE form-validation PUBLIC
16
+ "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN"
17
+ "http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">
18
+
19
+ <!-- Generated by XMDA -->
20
+
21
+ <form-validation>
22
+
23
+ <!--
24
+ This is a minimal Validator form file with a couple of examples.
25
+ -->
26
+ END
27
+
28
+ struts_write_validation_formset
29
+ write %{</form-validation>\n}
30
+ end
31
+
32
+ def struts_write_validation_formset
33
+ write %{ <formset>\n}
34
+ eachStrutsFormset { |b|
35
+ b.struts_write_validation_config_formset
36
+ }
37
+ write %{ </formset>\n}
38
+ end
39
+
40
+ end
41
+
42
+ module Muml_Class
43
+
44
+ def struts_write_validation_config_formset
45
+ return if struts_actionForm.empty?
46
+ write %{<form name="#{self.struts_actionForm_one.java_uniqueName}">\n}
47
+ struts_validation_writeFields
48
+ write %{</form>\n}
49
+ end
50
+
51
+ def struts_validation_writeFields
52
+ struts_formAttribute.each { |a|
53
+ a.struts_validation_writeField
54
+ }
55
+ end
56
+ end
57
+
58
+ module Muml_Property
59
+ def struts_validation_writeField
60
+ self.uml_type_one.struts_validation_writeField(self)
61
+ end
62
+ end
63
+
64
+ module Muml_DataType
65
+ def java_isInteger?
66
+ a=self
67
+ return a.kind_of?(Muml_DataType) && (a.java_qualifiedName.downcase=="java.lang.Integer" || a.java_qualifiedName=="int")
68
+ end
69
+ def struts_validation_writeField(field)
70
+
71
+ #return if self.kind_of?(Muml_Enumeration)
72
+ re=JavaMapping.instance.getTemplate(field.uml_type_one).getValidationRegexp
73
+ return if re.nil?
74
+ #re=STRUTS_PRIMITIVE_TYPE_REGEXP[self.uml_name_one]
75
+ #n=java_qualifiedName.downcase
76
+ #n=n.gsub("_","") if "_".include?(n[0,1])
77
+ #if self.kind_of?(Muml_Enumeration)
78
+ # # validation is not necessary
79
+ #elsif !re.nil?
80
+ write %{
81
+ <field property="#{field.java_Name}" depends="mask">
82
+ <arg key="defaultForm.string.displayname" />
83
+ <var><var-name>mask</var-name><var-value>#{re.source}</var-value></var>
84
+ </field>
85
+ }
86
+ #elsif java_isInteger?
87
+ # n="integer"
88
+ # log.error("struts validator #{n} is not registered.") unless rdf_model.struts_validatorExists?(n)
89
+ # write %{
90
+ # <field property="#{field.java_Name}" depends="required,#{n}">
91
+ # <arg key="defaultForm.#{n}.displayname" />
92
+ # </field>
93
+ #}
94
+ #else
95
+ # log.warn{ "no validation for field: #{field}" }
96
+ #end
97
+ #if n=="long"
98
+ #write %{
99
+ # <field property="#{field.java_Name}" depends="required,#{n}">
100
+ # <arg key="defaultForm.#{n}.displayname" />
101
+ # </field>
102
+ #}
103
+ # end
104
+ end
105
+ end
106
+
107
+ module Muml_Class
108
+ def struts_validation_writeField(field)
109
+ write "<!-- TODO -->"
110
+ end
111
+ end
112
+ module Muml_Interface
113
+ def struts_validation_writeField(field)
114
+ write "<!-- TODO -->"
115
+ end
116
+ end