ontomde-uml2-java 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,8 @@
1
+ == /2007-12-13
2
+ * javadoc comment generation
3
+
4
+ == 1.0.0 / 2007-10-28
5
+
6
+ * 1 major enhancement
7
+ * Birthday!
8
+
data/Manifest.txt ADDED
@@ -0,0 +1,24 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/ontomde-uml2-java.rb
6
+ lib/ontomde-uml2-java/version.rb
7
+ lib/ontomde-uml2-java/java.rb
8
+ lib/ontomde-uml2-java/operationAsClass.rb
9
+ lib/ontomde-uml2-java/javaHelper.rb
10
+ lib/ontomde-uml2-java/collectionMapping.rb
11
+ lib/ontomde-uml2-java/build.rb
12
+ lib/ontomde-uml2-java/enumCompatibilityLayer.rb
13
+ lib/ontomde-uml2-java/javaMapping.rb
14
+ lib/ontomde-uml2-java/accessorCode.rb
15
+ lib/ontomde-uml2-java/meta.rb
16
+ lib/ontomde-uml2-java/java_todo.rdoc
17
+ lib/ontomde-uml2-java/java.rdoc
18
+ lib/ontomde-uml2-java/javadoc.rb
19
+ lib/ontomde-uml2-java/accessorSignature.rb
20
+ lib/ontomde-uml2-java/enumAssignable.rb
21
+ lib/ontomde-uml2-java/security.rb
22
+ lib/ontomde-uml2-java/groovy.rb
23
+ lib/ontomde-uml2-java/equals.rb
24
+ test/test_ontomde-uml2-java.rb
data/README.txt ADDED
@@ -0,0 +1,98 @@
1
+ ontomde-uml2-java
2
+ by stephane (Pierre) Carrie
3
+ http://ontomde.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ ontomde-uml2-java is a full-featured UML2 to Java5 code generator library. This library is meant to be used trough a command line wrapper available in ontomde-uml2-javaFrontEnd gem.
8
+
9
+ A sample raw UML2 source model is available here: http://ontomde.rubyforge.org/website/demo/java5/index.html. This model is included in a running demonstration available from this page: http://ontomde.rubyforge.org/website/demonstration.html
10
+
11
+
12
+ == FEATURES/PROBLEMS:
13
+
14
+ Managed class modifiers
15
+ * interface implements
16
+ * single class inheritance
17
+ * attribute
18
+ * association
19
+ * method
20
+ * inner class
21
+
22
+ Managed interface modifiers
23
+ * interface inheritance
24
+ * method
25
+ * attribute accessors
26
+
27
+ Managed attribute modifiers
28
+ * Cardinality (0, *)
29
+ * visibility (public, ..)
30
+ * static
31
+ * derived
32
+ * read-only
33
+ * ordered
34
+
35
+ Managed association modifiers
36
+ * Cardinality (0, *)
37
+ * static
38
+ * derived
39
+ * read-only
40
+ * single navigability
41
+ * bi-navigability (automatic handling)
42
+ * composition
43
+
44
+ Managed method modifier
45
+ * static
46
+ * abstract
47
+ * visibility
48
+ * exception thrown
49
+ * parameters
50
+ * return parameter
51
+
52
+ Managed method parameter modifiers
53
+ * cardinality (0, *)
54
+ * ordered
55
+
56
+ Special featureds
57
+ * Multiple class inheritance handling
58
+ * Abstract method auto-implement
59
+ * Interface operation auto-implement
60
+ * Interface attribute auto-implement
61
+
62
+ Non managed elements
63
+ * Class association
64
+
65
+
66
+ == SYNOPSIS:
67
+
68
+ use commande line provided in ontomde-uml2-javaFrontEnd.
69
+
70
+ == REQUIREMENTS:
71
+
72
+ * requires ontomde-uml2
73
+
74
+ == INSTALL:
75
+
76
+ * (UNIX) sudo gem install ontomde-uml2-java
77
+ * (WIN) gem install ontomde-uml2-java
78
+
79
+ Additional information is available on ontoMDE web site :
80
+ http://ontomde.rubyforge.org/website/download.html
81
+ == LICENSE:
82
+
83
+ Copyright (C) 2008 Orange-labs
84
+ 38 rue General Leclerc
85
+ 92130 ISSY LES MOULINEAUX, France
86
+
87
+ This program is free software: you can redistribute it and/or modify
88
+ it under the terms of the GNU Affero General Public License as
89
+ published by the Free Software Foundation, either version 3 of the
90
+ License, or (at your option) any later version.
91
+
92
+ This program is distributed in the hope that it will be useful,
93
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
94
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95
+ GNU Affero General Public License for more details.
96
+
97
+ You should have received a copy of the GNU Affero General Public License
98
+ along with this program. If not, see http://www.gnu.org/licenses/.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/ontomde-uml2-java/version.rb'
6
+
7
+ Hoe.new('ontomde-uml2-java', Ontomde::Uml2::Java::VERSION) do |p|
8
+ p.rubyforge_name = 'ontomde'
9
+ p.author = 'Stephane (Pierre) Carrie'
10
+ p.email = 'stephanepierre.carrie -nospam- @orange-ftgroup.com'
11
+ p.summary = 'OntoMDE Java5 language cartridge'
12
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
13
+ p.url="http://ontomde.rubyforge.org"
14
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
15
+ p.extra_deps=[
16
+ ['ontomde-uml2',"= #{Ontomde::Uml2::Java::VERSION}"]
17
+ ]
18
+ p.spec_extras={ :required_ruby_version => '>=1.8.6' ,:required_rubygems_version => '>=1.0.0'}
19
+ end
20
+
21
+ # vim: syntax=Ruby
@@ -0,0 +1,496 @@
1
+ module Muml_Classifier
2
+ #java_this(oa)="#{java_this(oa)}"
3
+ def java_this(oa)
4
+ return "" if oa.uml_isStatic?
5
+ return "this."
6
+ end
7
+ def java_writeSuggesterBody(oa)
8
+ #TODO: recherche du composite commun
9
+ write("/* TPL:0001 */ return null;\n")
10
+ end
11
+
12
+ #Write code for a composition createAndAdd suggester
13
+ def java_writeSuggesterTypeBodyEnum(oa,isCreateAndAdd=false)
14
+ java_writeSuggesterBodyEnumWithType(oa,oa.uml_type_one.java_enumAssignableDataType_one,isCreateAndAdd)
15
+ end
16
+
17
+ #Write code for a suggester for a parameter enum
18
+ def java_writeSuggesterBodyEnum(oa)
19
+ java_writeSuggesterBodyEnumWithType(oa,oa.uml_type_one)
20
+ end
21
+ #Write code for a suggester returning enum given has parameter
22
+ #if lowerValue is zero, null is also added (except if createAndAdd)
23
+ def java_writeSuggesterBodyEnumWithType(oa,enum,isCreateAndAddSuggester=false)
24
+ write <<END
25
+ /* TPL:0002 */
26
+ java.util.ArrayList<#{enum.java_qualifiedName}> ret=new java.util.ArrayList<#{enum.java_qualifiedName}>();
27
+ #{ (oa.umlx_lowerValueIsZero? && (!isCreateAndAddSuggester)) ? %{ret.add(null);} : %{} } /* TPL:0002i */
28
+ for(int i=java.lang.reflect.Array.getLength(#{enum.java_qualifiedName}.values())-1; i>=0 ; i--){
29
+ ret.add(#{enum.java_qualifiedName}.values()[i]);
30
+ }
31
+ return ret;
32
+ END
33
+ end
34
+
35
+ def umlx_literal(val)
36
+ r=Cuml_LiteralInteger.new(rdf_model,nil)
37
+ r.uml_value=val
38
+ return r
39
+ end
40
+
41
+ #Adds a remover for parameter oa using a model transformation.
42
+ #
43
+ #NOTE:
44
+ #* A new operation is added to the UML model. The operation then generated using standard operation generator.
45
+ #* Remover is only generated for multi-valued property
46
+ #* If property is part of a *bidirectional* association, code is generated to update automaticaly the other side of the association.
47
+ def java_addRemover!(oa)
48
+ return unless context[:java_addRemover,true]
49
+ return if oa.umlx_upperValueIsOne?
50
+ return if oa.java_isSuggester?
51
+ return if oa.uml_isReadOnly?
52
+ set=java_createAndAddMethodFromProperty(oa,"remove",true)
53
+
54
+ if oa.uml_qualifier.empty?
55
+ qualCall=""
56
+ qualInit=""
57
+ qualCheckRemove=""
58
+ else
59
+ qualCall=".get(#{oa.uml_qualifier_one.java_Name})"
60
+ qualInit="//#{java_this(oa)}#{oa.java_NameProperty}.put(#{oa.uml_qualifier_one.java_Name},new java.util.HashSet<#{oa.uml_qualifier_one.uml_type_one}>);"
61
+ qualCheckRemove="==null"
62
+ end
63
+
64
+ ip=Cuml_Parameter.new(rdf_model,set.rdf_uri+"_in")
65
+ ip.uml_name=getterParameterName(oa)
66
+ ip.uml_direction=Cuml_ParameterDirectionKind::In
67
+ ip.uml_upperValue=umlx_literal(1)
68
+ ip.uml_lowerValue=umlx_literal(1)
69
+ ip.uml_type=oa.uml_type
70
+ set.uml_ownedParameter_add(ip)
71
+ oe=oa.umlx_otherEnd
72
+ if oa.uml_isDerived?
73
+ #no code when derived
74
+ elsif oe.nil? || !oe.umlx_isNavigable?
75
+ set.java_code=<<END
76
+ /* TPL:0003 */
77
+ #{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)});
78
+ END
79
+ elsif oe.umlx_upperValueIsOne?
80
+ set.java_code=<<END
81
+ /* TPL:0004 */
82
+ #{qualInit}
83
+ if(#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)})#{qualCheckRemove}) {
84
+ #{getterParameterName(oa)}#{qualCall}.set#{oe.java_NameBean}(null);
85
+ }
86
+ END
87
+ else
88
+ set.java_code=<<END
89
+ /* TPL:0005 */
90
+ if(#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)})) {
91
+ #{getterParameterName(oa)}#{qualCall}.remove#{oe.java_NameBean}(this);
92
+ }
93
+ END
94
+ end
95
+
96
+ if set.java_use_Arrays?
97
+ set.java_code=nil # TODO: implement
98
+ end
99
+
100
+ end
101
+
102
+ #return a warning text to be included in java method if incorrect model is found.
103
+ def java_qualifierNavigabilityWarning(oa)
104
+ oe=oa.umlx_otherEnd
105
+ return "" if oe.nil?
106
+ return "" if oe.umlx_isNavigable?
107
+ return <<END
108
+ /*TODO: association other end is navigable (#{oe.uml_name}).
109
+ Because extrinsic qualifier key is not computable, there is no way a computer program can guess it.
110
+ Check your model !
111
+ If your key is intrisic, you should reconsider your model as it is a redundant functional qualifier.
112
+ You should take appropriate action or your data model could be corrupted
113
+ as association other end will not be updated.
114
+ */
115
+ END
116
+ end
117
+
118
+ def java_addQualifiedRemover!(oa)
119
+ end
120
+
121
+ def java_addQualifiedAppender!(oa)
122
+ end
123
+
124
+
125
+
126
+ def java_writeQualifiedPutterBody(oa)
127
+ j=""
128
+ sep=""
129
+ oa.uml_qualifier.each { |key|
130
+ j=j+sep+key.java_Name
131
+ sep=","
132
+ }
133
+ write <<END
134
+ {
135
+ #{java_qualifierNavigabilityWarning(oa)}
136
+ if(#{getterParameterName(oa)}==null) {
137
+ #{java_this(oa)}#{oa.java_NameProperty}.remove(#{j});
138
+ } else {
139
+ #{java_this(oa)}#{oa.java_NameProperty}.put(#{j},#{getterParameterName(oa)});
140
+ }
141
+ }
142
+ END
143
+ end
144
+
145
+
146
+
147
+ def java_addAppenderQualifier!(oa)
148
+ return unless context[:java_addAppenderQualifier,true]
149
+ return if oa.umlx_upperValueIsOne?
150
+ return if oa.uml_qualifier.empty?
151
+ return if oa.umlx_isComposite?
152
+ return if oa.uml_isReadOnly?
153
+ add=java_createAndAddMethodFromProperty(oa,"add",true)
154
+
155
+ ip=Cuml_Parameter.new(rdf_model,add.rdf_uri+"_in")
156
+ ip.uml_name=getterParameterName(oa)
157
+ ip.uml_direction=Cuml_ParameterDirectionKind::In
158
+ ip.uml_upperValue=umlx_literal(1);
159
+ ip.uml_lowerValue=umlx_literal(1);
160
+ ip.uml_type=oa.uml_type
161
+ add.uml_ownedParameter_add(ip)
162
+ oe=oa.umlx_otherEnd
163
+
164
+ qualCall=".get(#{oa.uml_qualifier_one.java_Name})"
165
+ qualInit="//#{java_this(oa)}#{oa.java_NameProperty}.put(#{oa.uml_qualifier_one.java_Name},new java.util.HashSet<#{oa.uml_qualifier_one.uml_type_one}>);"
166
+
167
+ if oa.uml_isDerived?
168
+ # no code when derived
169
+ elsif true #TODO:remetre le test oe.nil? || !oe.umlx_isNavigable?
170
+ add.java_code=<<END
171
+ /* TPL:0006 */
172
+ //TODO:
173
+ if(#{ip.java_Name}==null) { return; }
174
+ #{qualInit}
175
+ #{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name});
176
+ END
177
+ elsif oe.umlx_upperValueIsOne?
178
+ #*-1
179
+ add.java_code=<<END
180
+ /* TPL:0007 */
181
+ if(#{ip.java_Name}==null) { return; }
182
+ if(#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name})){
183
+ #{ip.java_Name}.set#{oe.java_NameBean}(this);
184
+ }
185
+ END
186
+ else
187
+ #*-*
188
+ add.java_code=<<END
189
+ /* TPL:0008 */
190
+ if(#{ip.java_Name}==null) { return; }
191
+ if(#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name})) {
192
+ #{ip.java_Name}.remove#{oe.java_NameBean}(this);
193
+ }
194
+ END
195
+ end
196
+ end
197
+
198
+ #Adds a creater for parameter oa using a model transformation.
199
+ #
200
+ #NOTE:
201
+ #* A new operation is added to the UML model. The operation then generated using standard operation generator.
202
+ #--
203
+ #TODO: implementer methodes
204
+ def java_addCreater!(oa)
205
+ return unless context[:java_addCreater,true]
206
+ return if oa.umlx_upperValueIsOne?
207
+ #return unless oa.uml_qualifier.empty?
208
+ return unless oa.umlx_isComposite?
209
+ get=java_createAndAddMethodFromProperty(oa,"create",false)
210
+
211
+ rp=Cuml_Parameter.new(rdf_model,get.rdf_uri+"_p1")
212
+ rp.uml_name="return"
213
+ rp.uml_direction=Cuml_ParameterDirectionKind::Return
214
+ rp.uml_upperValue=oa.uml_upperValue
215
+ rp.uml_lowerValue=oa.uml_lowerValue
216
+ rp.uml_type=oa.uml_type
217
+ rp.uml_qualifier=oa.uml_qualifier
218
+ get.uml_ownedParameter_add(rp)
219
+ if oa.umlx_upperValueIsOne? || !oa.uml_qualifier.empty?
220
+ j="{ new return #{oa.java_NameProperty}"
221
+ sep_next=".get("
222
+ sep_end=""
223
+ j=j+sep_end +";}"
224
+ #get.java_code=j
225
+ else
226
+ #on ne peut pas permetre la modification de la liste en direct
227
+ #get.java_code="{ return new java.util.HashSet<#{oa.uml_type_one.java_qualifiedName}>(#{oa.java_NameProperty}); }"
228
+ end
229
+ end
230
+
231
+ #Adds a createAndAdd method for parameter oa using a model transformation.
232
+ #
233
+ #NOTE:
234
+ #* A new operation is added to the UML model. The operation then generated using standard operation generator.
235
+ #* operation is only generated for multi-valued property
236
+ #* operation is only generated for a composite association end.
237
+ def java_addCreateAndAppender!(oa)
238
+ #method cannot be generated if required enum assignable is not on.
239
+ return unless context[:withEnumAssignable]
240
+ return unless context[:java_addAppender,true]
241
+ #return if oa.umlx_upperValueIsOne?
242
+ return unless oa.uml_qualifier.empty?
243
+ return unless oa.umlx_isComposite?
244
+ return if oa.java_isSuggester?
245
+
246
+ add=umlx_createAndAddOperation(rdf_uri+"_createAndAdd#{oa.java_NameBean}","createAndAdd#{oa.java_NameBean}")
247
+
248
+ rp=add.umlx_createAndAddReturnParameter(add.rdf_uri+"_ret")
249
+ rp.uml_upperValue=umlx_literal(1);
250
+ rp.uml_lowerValue=umlx_literal(1);
251
+ rp.uml_type=oa.uml_type
252
+
253
+ #ip=add.umlx_createAndAddParameter(add.rdf_uri+"_type")
254
+ #ip.uml_name="type"
255
+ #ip.uml_upperValue=umlx_literal(1);
256
+ #ip.uml_lowerValue=umlx_literal(1);
257
+ #ip.uml_type=oa.uml_type
258
+
259
+
260
+ tp=add.umlx_createAndAddParameter(oa.rdf_uri+"_reqType","requestedType")
261
+ tp.uml_type=oa.uml_type_one.java_enumAssignableDataType_one
262
+
263
+ #if oa.uml_type_one.uml_isAbstract?
264
+ # ******************************
265
+ # TODO: implement type selector
266
+ # ******************************
267
+ # no java code generated
268
+
269
+ #TODO: factorize in helper class
270
+ add.java_code=%{ /* TPL:0020b */
271
+ if (requestedType==null) {
272
+ return null;
273
+ }
274
+ String qname=requestedType.name().replaceAll("#{JAVA_MAGIC_DOT_STRING}",".");
275
+ try {
276
+ // c=#{java_this(oa)}getClass().getClassLoader().loadClass(requestedType.name());
277
+ Class<?> t = Class.forName(qname);
278
+ Class<?>[] p = new Class[0];
279
+ Object[]initArgs =new Object[0];
280
+ java.lang.reflect.Constructor<?> c=t.getConstructor(p);
281
+ #{oa.uml_type_one.java_qualifiedName} ret=(#{oa.uml_type_one.java_qualifiedName})c.newInstance(initArgs);
282
+ #{oa.umlx_upperValueIsOne? ? "set" : "add"}#{oa.java_NameBean}(ret);
283
+ return ret;
284
+ } catch (ClassNotFoundException e) {
285
+ e.printStackTrace();
286
+ throw new RuntimeException("Missing type "+qname,e);
287
+ } catch (NoSuchMethodException e) {
288
+ e.printStackTrace();
289
+ throw new RuntimeException("Missing default constructor for"+qname,e);
290
+ } catch (IllegalAccessException e) {
291
+ e.printStackTrace();
292
+ throw new RuntimeException("Illegal access Exception on "+qname,e);
293
+ } catch (InstantiationException e) {
294
+ e.printStackTrace();
295
+ throw new RuntimeException("Instantiation exception on "+qname,e);
296
+ } catch (java.lang.reflect.InvocationTargetException e) {
297
+ e.printStackTrace();
298
+ throw new RuntimeException("Invocation Target Exception on "+qname,e);
299
+ }}
300
+ end
301
+
302
+ #Adds an appender for parameter oa using a model transformation.
303
+ #
304
+ #NOTE:
305
+ #* A new operation is added to the UML model. The operation then generated using standard operation generator.
306
+ #* operation is only generated for multi-valued property
307
+ #* If property is part of a *bidirectional* association, code is generated to update automaticaly the other side of the association.
308
+ def java_addAppender!(oa)
309
+ return unless context[:java_addAppender,true]
310
+ return if oa.umlx_upperValueIsOne?
311
+ return unless oa.uml_qualifier.empty?
312
+ return if oa.java_isSuggester?
313
+ #return if oa.umlx_isComposite?
314
+ return if oa.uml_isReadOnly?
315
+ add=java_createAndAddMethodFromProperty(oa,"add",true)
316
+
317
+ ip=Cuml_Parameter.new(rdf_model,add.rdf_uri+"_in")
318
+ ip.uml_name=getterParameterName(oa)
319
+ ip.uml_direction=Cuml_ParameterDirectionKind::In
320
+ ip.uml_upperValue=umlx_literal(1);
321
+ ip.uml_lowerValue=umlx_literal(1);
322
+ ip.uml_type=oa.uml_type
323
+ add.uml_ownedParameter_add(ip)
324
+ oe=oa.umlx_otherEnd
325
+
326
+ if oa.uml_isDerived?
327
+ # no code generated
328
+ elsif (oe.nil? || !oe.umlx_isNavigable?) && !oa.java_use_Arrays?
329
+ add.java_code=<<END
330
+ /* TPL:0009b */
331
+ if(#{getterParameterName(oa)}==null) { return; }
332
+ #{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)});
333
+ END
334
+ elsif (oe.nil? || !oe.umlx_isNavigable?) && oa.java_use_Arrays?
335
+ add.java_code=<<END
336
+ /* TPL:0009a */
337
+ if(#{getterParameterName(oa)}==null) { return; }
338
+ #{oa.uml_type_one.java_qualifiedName}[] newArray=null;
339
+ if (#{java_this(oa)}#{oa.java_NameProperty}==null) {
340
+ newArray=new String[1];
341
+ newArray[0]=#{getterParameterName(oa)};
342
+ } else {
343
+ newArray=new String[1+#{java_this(oa)}#{oa.java_NameProperty}.length];
344
+ System.arraycopy(#{java_this(oa)}#{oa.java_NameProperty}, 0, newArray,0, #{java_this(oa)}#{oa.java_NameProperty}.length);
345
+ newArray[#{java_this(oa)}#{oa.java_NameProperty}.length]=#{getterParameterName(oa)};
346
+ }
347
+ #{java_this(oa)}#{oa.java_NameProperty}=newArray;
348
+ END
349
+
350
+
351
+ elsif oe.umlx_upperValueIsOne?
352
+ #*-1
353
+ add.java_code=<<END
354
+ /* TPL:0010 */
355
+ if(#{getterParameterName(oa)}==null) { return; }
356
+ if(#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)})){
357
+ #{getterParameterName(oa)}.set#{oe.java_NameBean}(this);
358
+ }
359
+ END
360
+ else
361
+ #*-*
362
+ # second test avoids loop
363
+ add.java_code=<<END
364
+ /* TPL:0011 */
365
+ if(#{getterParameterName(oa)}==null) { return; }
366
+ if(#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)})) {
367
+ #{getterParameterName(oa)}.add#{oe.java_NameBean}(this);
368
+ }
369
+ END
370
+ end
371
+
372
+ end
373
+
374
+
375
+ def java_addWithIndexAppenderBody(oa,oe,ip,ip2)
376
+ if oe.nil? || !oe.umlx_isNavigable?
377
+ write <<END
378
+ /* TPL:0019 */
379
+ if(#{getterParameterName(oa)}==null) { return; }
380
+ #{oa.java_NameProperty}.add(#{ip2.java_Name}, #{ip.java_Name});
381
+ END
382
+ end
383
+ end
384
+
385
+ def java_writeGlobalGetterBody(oa)
386
+ return if oa.uml_isDerived? && oa.umlx_stringMappingForEnum.empty?
387
+
388
+ if java_isEnumStringMapping?(oa)
389
+ java_writeEnumStringMappingGetterCode(oa)
390
+
391
+ elsif oa.umlx_upperValueIsOne? || !oa.uml_qualifier.empty?
392
+ j="/* TPL:0012 */ return #{oa.java_NameProperty}"
393
+ sep_next=".get("
394
+ sep_end=""
395
+ #oa.uml_qualifier.each { |key|
396
+ # j=j+sep_next+key.uml_name_one
397
+ # sep_next=","
398
+ # sep_end=")"
399
+ #}
400
+ j=j+sep_end +";"
401
+ write j
402
+ else
403
+ #on ne peut pas permettre la modification de la liste en direct
404
+ write %{
405
+ if(#{oa.java_NameProperty}!=null){ /* TPL:0013 */
406
+ return #{oa.java_NameProperty};
407
+ } else {
408
+ return #{oa.java_getCollectionMapping.addNew(oa.uml_type_one.java_qualifiedName)};
409
+ }}
410
+ end
411
+ end
412
+
413
+ def java_writeGlobalSetterBody(oa)
414
+ return if oa.uml_isDerived? && oa.umlx_stringMappingForEnum.empty?
415
+
416
+ oe=oa.umlx_otherEnd
417
+ if java_isEnumStringMapping?(oa)
418
+ java_writeEnumStringMappingSetterCode(oa)
419
+ elsif !oa.uml_qualifier.empty? || (!oe.nil? && oe.umlx_isNavigable? && !oe.uml_qualifier.empty?)
420
+ #TODO: gerer bi-nav et qualifier
421
+ write "/* TPL:0014 */ //TODO: bi-navigability\n #{oa.java_NameProperty}=#{getterParameterName(oa)};"
422
+ elsif (oe.nil?) || (!oe.umlx_isNavigable?)
423
+ # Autre extr�mit� non navigable.
424
+ #begin
425
+ #if oa.uml_qualifier.empty?
426
+ write "#{java_this(oa)}#{oa.java_NameProperty}=#{getterParameterName(oa)}; /* TPL:0014d*/"
427
+ #else
428
+ # j="{ #{oa.java_NameProperty}.put("
429
+ # sep=""
430
+ # oa.uml_qualifier.each { |qual|
431
+ # j=j+sep+qual.java_NameProperty
432
+ # sep=","
433
+ # }
434
+ # j=j+sep+"#{ip.uml_name});}"
435
+ # set.java_code=j
436
+ #end
437
+ #end
438
+ elsif oa.umlx_upperValueIsOne? && oe.umlx_upperValueIsOne?
439
+ # 1<->1
440
+ #Ne pas enlver le =null (bloque la recursion)
441
+ write <<END
442
+ /* TPL:0015 */
443
+ if(#{java_this(oa)}#{oa.java_NameProperty}==#{getterParameterName(oa)}) { return ;}
444
+ #{oa.uml_type_one.java_qualifiedName} previous=#{java_this(oa)}#{oa.java_NameProperty};
445
+
446
+ #{java_this(oa)}#{oa.java_NameProperty}=null;
447
+ if(previous!=null) { previous.set#{oe.java_NameBean}(null); }
448
+
449
+ #{java_this(oa)}#{oa.java_NameProperty}=#{getterParameterName(oa)};
450
+ if(#{getterParameterName(oa)}!=null) { #{getterParameterName(oa)}.set#{oe.java_NameBean}(this); }
451
+ END
452
+
453
+ elsif oa.umlx_upperValueIsOne? && (!oe.umlx_upperValueIsOne?)
454
+ # 1<->*
455
+ write <<END
456
+ /* TPL:0016 */
457
+ if(#{java_this(oa)}#{oa.java_NameProperty}==#{getterParameterName(oa)}) { return ;}
458
+ #{oa.uml_type_one.java_qualifiedName} previous=#{java_this(oa)}#{oa.java_NameProperty};
459
+
460
+ #{java_this(oa)}#{oa.java_NameProperty}=null;
461
+ if(previous!=null) { previous.remove#{oe.java_NameBean}(this); }
462
+
463
+ #{java_this(oa)}#{oa.java_NameProperty}=#{getterParameterName(oa)};
464
+ if(#{getterParameterName(oa)}!=null) { #{getterParameterName(oa)}.add#{oe.java_NameBean}(this); }
465
+ END
466
+ else # *<->1 and *<->*
467
+ write <<END
468
+ /* TPL:0017 */
469
+ #{oa.java_propertyAssociationType} toBeRemoved=new #{oa.java_propertyAssociationConcreteType}();
470
+ for(#{oa.uml_type_one.java_qualifiedName} item:#{oa.java_NameProperty}) {
471
+ if(#{getterParameterName(oa)}!=null && #{getterParameterName(oa)}.contains(item)) { continue;}
472
+ toBeRemoved.add(item);
473
+ }
474
+ for(#{oa.uml_type_one.java_qualifiedName} item:toBeRemoved) {
475
+ #{java_this(oa)}remove#{oa.java_NameBean}(item);
476
+ }
477
+ if(#{getterParameterName(oa)}==null) { return ; }
478
+ for(#{oa.uml_type_one.java_qualifiedName} item:#{getterParameterName(oa)}) {
479
+ #{java_this(oa)}add#{oa.java_NameBean}(item);
480
+ }
481
+ END
482
+ end
483
+ end
484
+
485
+ def java_writeQualifiedGetterBody(oa)
486
+ write("/* TPL:0018 */\n")
487
+ write("return #{oa.java_NameProperty}.get(")
488
+ sep=""
489
+ oa.uml_qualifier.each { |key|
490
+ write(sep)
491
+ sep=","
492
+ write(key.java_Name)
493
+ }
494
+ write(");\n")
495
+ end
496
+ end