ontomde-java 2.0.0 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. data/History.txt +11 -0
  2. data/Manifest.txt +1 -51
  3. data/lib/ontomde-java.rb +2 -0
  4. data/lib/ontomde-java/crank.rb +8 -8
  5. data/lib/ontomde-java/crank/crankJpa.rb +58 -8
  6. data/lib/ontomde-java/crank/main.rb +38 -21
  7. data/lib/ontomde-java/frontend/command.rb +7 -7
  8. data/lib/ontomde-java/frontend/command.rdoc +0 -583
  9. data/lib/ontomde-java/frontend/defaultOptions.rb +12 -7
  10. data/lib/ontomde-java/frontend/options.rb +19 -2
  11. data/lib/ontomde-java/frontend/steps.rb +36 -5
  12. data/lib/ontomde-java/java/accessorCode.rb +250 -94
  13. data/lib/ontomde-java/java/accessorSignature.rb +50 -4
  14. data/lib/ontomde-java/java/annotationOntoMDE.rb +38 -27
  15. data/lib/ontomde-java/java/component.rb +141 -68
  16. data/lib/ontomde-java/java/enumAssignable.rb +46 -5
  17. data/lib/ontomde-java/java/java.rb +111 -40
  18. data/lib/ontomde-java/java/javaDatatypeMapping.rb +35 -1
  19. data/lib/ontomde-java/java/javadoc.rb +35 -22
  20. data/lib/ontomde-java/java/operationAsClass.rb +13 -0
  21. data/lib/ontomde-java/java/security.rb +10 -2
  22. data/lib/ontomde-java/java/stateMachine.rb +137 -74
  23. data/lib/ontomde-java/java/tenant.rb +1 -0
  24. data/lib/ontomde-java/java/xsd.rb +1 -1
  25. data/lib/ontomde-java/jpa/configuration.rb +25 -1
  26. data/lib/ontomde-java/jpa/finder.rb +48 -13
  27. data/lib/ontomde-java/jpa/jpa.rb +30 -14
  28. data/lib/ontomde-java/jpa/mapping.rb +114 -60
  29. data/lib/ontomde-java/jpa/redefined.rb +21 -5
  30. data/lib/ontomde-java/jpa/simulationAutoImplement.rb +1 -1
  31. data/lib/ontomde-java/jpdl/processOperationToClass.rb +1 -2
  32. data/lib/ontomde-java/kbjava/rdfToJava.rb +25 -16
  33. data/lib/ontomde-java/struts.rb +1 -1
  34. data/lib/ontomde-java/struts/MessageResources.rb +15 -6
  35. data/lib/ontomde-java/struts/action.rb +37 -13
  36. data/lib/ontomde-java/struts/form.rb +97 -7
  37. data/lib/ontomde-java/struts/header.rb +7 -3
  38. data/lib/ontomde-java/struts/jsp_edit.rb +54 -24
  39. data/lib/ontomde-java/struts/jsp_edit_js.rb +1 -1
  40. data/lib/ontomde-java/struts/jsp_index.rb +6 -4
  41. data/lib/ontomde-java/struts/mappingForJsp.rb +11 -7
  42. data/lib/ontomde-java/struts/mappingToJavaHierarchy.rb +16 -2
  43. data/lib/ontomde-java/version.rb +1 -1
  44. data/lib/ontomde-java/vmware/vso.rb +329 -0
  45. data/test/test_export_ea7_1_829.rb +5 -0
  46. data/test/test_export_ea7_1_833.rb +5 -0
  47. data/test/test_export_ea7_5_843.rb +5 -0
  48. data/test/test_export_magicDraw.rb +4 -0
  49. data/test/test_export_oe530.rb +1 -1
  50. data/test/test_export_oe600.rb +1 -1
  51. data/test/test_export_rsm60.rb +1 -1
  52. data/test/{uml_test.rb → test_export_unitTests.rb} +6 -1
  53. metadata +9 -56
  54. data/generateRdocFile.sh +0 -16
  55. data/profiling.xls +0 -0
  56. data/test/.classpath +0 -14
  57. data/test/.project +0 -17
  58. data/test/.settings/org.eclipse.jdt.core.prefs +0 -23
  59. data/test/Rakefile +0 -71
  60. data/test/build.xml +0 -34
  61. data/test/classpath.rb +0 -15
  62. data/test/lib/junit-4.1.jar +0 -0
  63. data/test/load1.rb +0 -3
  64. data/test/load2.rb +0 -3
  65. data/test/log4j.properties +0 -46
  66. data/test/model/.project +0 -11
  67. data/test/model/BigProject.mdzip +0 -0
  68. data/test/model/BigProject.mdzip.nt +0 -102866
  69. data/test/model/ClassDiagram.EntArch.gif +0 -0
  70. data/test/model/ClassDiagram.emx.gif +0 -0
  71. data/test/model/ClassDiagram.mdzip.gif +0 -0
  72. data/test/model/model_ea71.bis.ea.xmi +0 -149
  73. data/test/model/model_ea71.ea.xmi +0 -4470
  74. data/test/model/model_ea71.eap +0 -0
  75. data/test/model/model_ea71_README.txt +0 -8
  76. data/test/model/multipleInheritance.emx +0 -466
  77. data/test/model/multipleInheritance.emx.nt +0 -2428
  78. data/test/model/simple1-530.ofp +0 -0
  79. data/test/model/simple1-includedAsReference.emx +0 -169
  80. data/test/model/simple1.emx +0 -3729
  81. data/test/model/simple1.emx.fragments.nt +0 -81
  82. data/test/model/simple1.emx.nt +0 -5760
  83. data/test/model/simple1.mdzip +0 -0
  84. data/test/model/simple1.mdzip.nt +0 -11500
  85. data/test/model/simple1.oe530.nt +0 -1986
  86. data/test/model/simple1.oe600.nt +0 -1627
  87. data/test/src/RuntimeTest.java +0 -656
  88. data/test/src/testsLevel1.java +0 -174
  89. data/test/src/testsLevel2.java +0 -29
  90. data/test/src/testsLevel3.java +0 -40
  91. data/test/test-ea7.sh +0 -15
  92. data/test/test-magicDraw.sh +0 -10
  93. data/test/test-mi.sh +0 -9
  94. data/test/test-oe530.sh +0 -10
  95. data/test/test-oe600.sh +0 -11
  96. data/test/test-rsm.sh +0 -11
  97. data/test/test_export_ea71.rb +0 -5
  98. data/test/trace +0 -419
  99. data/test/uml_test.xls +0 -0
  100. data/test/unit_test.rb +0 -6
@@ -2,16 +2,22 @@
2
2
  # return an option array field with default values
3
3
  def getDefaultOptions(options={})
4
4
  #options = {}
5
+ options[:dbSchemaName] = 'testschema'
5
6
  options[:multiTenant] = false
6
- options[:testRelativeDir]="src/test/java"
7
7
  options[:jspUseXmdaTaglib]=true
8
8
  options[:backTrace] = false
9
9
  options[:selfTestAndExit] = false
10
10
  options[:verbose]=false
11
- options[:targetDir]="."
12
- options[:javaRelativeDir]="src/main/java/"
13
- options[:flexRelativeDir]="webapp/src/main/flex/"
11
+
12
+ # Path related defaults
13
+ options[:targetDir]='.'
14
+ options[:defaultRootDir ]='' # examples: domain or webapp
15
+ options[:testRelativeDir]='src/test/java/'
16
+ options[:javaRelativeDir]='src/main/java/'
17
+ options[:flexRelativeDir]='webapp/src/main/flex/'
14
18
  options[:webResourcesDir]=options[:javaRelativeDir]
19
+ options[:webContentRelativeDir]='./WebContent/'
20
+
15
21
  options[:flex]=false
16
22
  options[:mysql]=false
17
23
  options[:nt]=[]
@@ -30,7 +36,7 @@ def getDefaultOptions(options={})
30
36
  options[:withGenerateMethodForm]=false
31
37
  options[:makeCompositionBiNavigable]=false
32
38
  options[:salvage]=false
33
- options[:useUnzip]=false
39
+ #options[:useUnzip]=false
34
40
  options[:messageCheck]=true
35
41
  options[:struts]=false
36
42
  options[:crank]=false
@@ -43,7 +49,6 @@ def getDefaultOptions(options={})
43
49
  #options[:installRessources]=true
44
50
  options[:target_ejbconf] = nil
45
51
  options[:autoNewFileCreation]=true
46
- options[:webContentRelativeDir]="./WebContent/"
47
52
  options[:javaClassRelDir]=nil
48
53
  options[:generateAntBuildFile]=false
49
54
  options[:silentlyForceUnknownDatatypeToString]=false
@@ -104,7 +109,7 @@ def getDefaultOptions(options={})
104
109
  options[:globalReverseFile]=nil
105
110
  options[:hasGlobalReverse]=false
106
111
  options[:dataModel]=nil
107
-
112
+ options[:vsoTargetFile]=nil
108
113
  # options[:hib_dialect]="org.hibernate.dialect.MySQL5InnoDBDialect"
109
114
  #
110
115
  #
@@ -115,6 +115,12 @@ def populateSourceAndTarget(opts,options)
115
115
  options[:javaRelativeDir] = v
116
116
  end
117
117
 
118
+ opts.on("--defaultRootDir ROOT_DIR_NAME",": Default root dir used for package without a root dir (a package stereotyped root). (examples: webapp, domain, ...)","default: --defaultRootDir #{options[:defaultRootDir]}") do |v|
119
+ options[:defaultRootDir] = v
120
+ end
121
+
122
+
123
+
118
124
  opts.on("--webResourcesDir DIRECTORY",": Relative destination directory for generated Web Resources properties, ...","relative to --targetDir","default: --webResourcesDir #{options[:webResourcesDir]}") do |v|
119
125
  options[:webResourcesDir] = v
120
126
  end
@@ -271,6 +277,7 @@ def populateCrank(opts,options)
271
277
  opts.on("--[no-]crank","Enable crank generation.","default: --#{options[:crank]?'':'no-'}crank") do |v|
272
278
  options[:crank] = v
273
279
  options[:java_addJavaEnumInterface]=true
280
+ #options[:db_autonomousDAO] = v
274
281
  end
275
282
  end
276
283
  def populateFlex(opts,options)
@@ -307,6 +314,10 @@ def populatePersistence(opts,options)
307
314
  options[:ddl_mode] = v
308
315
  end
309
316
 
317
+ opts.on("--dbSchemaName [SCHEMA_NAME]",": Name of the schema used in configuration files",%{default: --dbSchemaName #{options[:dbSchemaName]}}) do |v|
318
+ options[:dbSchemaName] = v
319
+ end
320
+
310
321
  opts.on("-s","--[no-]simulateNotImplementedMethods",": Replace unimplemeted method with a simulation method.",%{default: --#{options[:simulateNotImplementedMethods]?"":"no-"}simulateNotImplementedMethods}) do |v|
311
322
  options[:simulateNotImplementedMethods] = v
312
323
  end
@@ -348,7 +359,8 @@ def populateStruts(opts,options)
348
359
  options[:java_addJavaEnumInterface] = v
349
360
  end
350
361
  opts.on("-u","--[no-]useUnzip",": Use unzip to install resources.","default: --#{options[:useUnzip]?'':'no-'}useUnzip") do |v|
351
- options[:useUnzip] = v
362
+ puts "#WARNING --useUnzip option deprecated. Please remove from your setup file"
363
+ #options[:useUnzip] = v
352
364
  end
353
365
 
354
366
  opts.on("-c","--[no-]message-check",": Check message ressources consistency.","default: --#{options[:messageCheck]?'':'no-'}message-check") do |v|
@@ -424,6 +436,11 @@ def populateMisc(opts,options)
424
436
  opts.on("--[no-]generateDebugLauncher",": generates ruby script helper for launching ontomde-java from a ruby debugger. (netbeans, ruby, ...)",%{default: --#{options[:generateDebugLauncher]?"":"no-"}generateDebugLauncher}) do |v|
425
437
  options[:generateDebugLauncher] = v
426
438
  end
439
+
440
+ opts.on("--vsoTargetFile VSO_TARGET_FILE",": if sets, generate a file containing VmWare VSO file mapping for inclusion into VMO","default: -- #{options[:vsoTargetFile]}") do |v|
441
+ options[:vsoTargetFile] = v
442
+ end
443
+
427
444
  end
428
445
 
429
446
  def populateDocumentation(opts,options)
@@ -463,7 +480,7 @@ def populateDebug(opts,options)
463
480
  options[:allowAutomaticCodeDeletion] = v
464
481
  end
465
482
 
466
- opts.on("-s","--[no-]dry-run",": Do a dry run without executing actions..","No file will be changed neither created on disk",%{default: --#{options[:dryRun]?"":"no-"}dry-run}) do |v|
483
+ opts.on("-s","--[no-]dryRun",": Do a dry run without executing actions..","No file will be changed neither created on disk",%{default: --#{options[:dryRun]?"":"no-"}dryRun}) do |v|
467
484
  options[:dryRun] = v
468
485
  end
469
486
 
@@ -7,14 +7,17 @@
7
7
  # #step_generate_struts, #step_generate_crank, #step_generate_misc, #step_generate_flex, #step_clean
8
8
  DEFAULT_GENERATION_CHAIN=[
9
9
  [:load , :step_load],
10
+ [:nocode, :step_removeNoCode],
10
11
  [:tenant , :step_addTenant],
11
12
  [:kb , :step_generateKb],
12
13
  [:bpm , :step_bpm],
13
14
  [:tests , :step_generate_tests],
15
+ [:dto1 , :step_generateCustomDTO_step1 ],
16
+ [:dto2 , :step_generateCustomDTO_step2 ],
14
17
  [:mda1 , :step_transform10],
15
18
  [:mda2 , :step_transform20],
19
+ [:vso ,:step_vso ],
16
20
  [:initComponent, :step_initComponent],
17
- [:dto , :step_generateCustomDTO ],
18
21
  [:mda3 , :step_transform30],
19
22
  [:mda4 , :step_transform40],
20
23
  [:java , :step_generate_java],
@@ -95,8 +98,24 @@ def step_generateKb(model)
95
98
  say "loading KB project data"
96
99
  ignoreheader=true
97
100
  data_model=Crdf_ProtegeDataModel.new
98
- data_model.loadMetaModelFromFile(model.context[:testDataRDFS],ignoreheader)
99
- data_model.loadModelFromFile(model.context[:testDataRDF],ignoreheader)
101
+ begin
102
+ failOnWarn=true
103
+ data_model.loadMetaModelFromFile(model.context[:testDataRDFS],ignoreheader,failOnWarn)
104
+ #data_model.loadFail_on_warn=true
105
+ data_model.loadModelFromFile(model.context[:testDataRDF],ignoreheader,failOnWarn)
106
+ rescue Exception => z
107
+ puts <<END
108
+
109
+ * PLEASE READ: An error occured while reading tests data.
110
+ * PLEASE READ: This is most likely caused by tests data out of sync
111
+ * PLEASE READ: with model due to a change in source model.
112
+ * PLEASE READ: You should open test project with Protege/2000
113
+ * PLEASE READ: (.pprj file associated to: #{model.context[:testDataRDFS]})
114
+ * PLEASE READ: remove offending data, save and rerun generation.
115
+
116
+ END
117
+ raise z
118
+ end
100
119
  data_model.kbjava_umlSourceModel = model
101
120
  model[:dataModel]=data_model
102
121
  end
@@ -114,8 +133,12 @@ end
114
133
 
115
134
  # generate custom DTO based on business objects
116
135
  # and setup from protege.
117
- def step_generateCustomDTO(model)
118
- model.dto_generateCustomDTO()
136
+ def step_generateCustomDTO_step1(model)
137
+ model.dto_generateCustomDTO_step1()
138
+ end
139
+
140
+ def step_generateCustomDTO_step2(model)
141
+ model.dto_generateCustomDTO_step2()
119
142
  end
120
143
 
121
144
  # Enhance UML model
@@ -275,6 +298,10 @@ def step_generate_crank(model)
275
298
  end
276
299
  end
277
300
 
301
+ def step_removeNoCode(model)
302
+ model.umlx_removeNoCode!()
303
+ end
304
+
278
305
  def step_initComponent(model)
279
306
  model.java_autoGenerateCrudComponents! if model.context[:webservice]
280
307
  model.umlx_autoCreateImplicitComponent! if model.context[:withGenerateImplicitComponent]
@@ -285,3 +312,7 @@ def step_clean(model)
285
312
  mtk_deleteTempFiles
286
313
  end
287
314
 
315
+ def step_vso(model)
316
+ model.vso_generateMapping
317
+ end
318
+
@@ -11,7 +11,7 @@ module Muml_Classifier
11
11
  # (this method is often overwritten, especially by persistence module).
12
12
  def java_writeSuggesterBody(oa)
13
13
  #TODO: recherche du composite commun
14
- write("return null;\n")
14
+ write("\t\treturn null;\n")
15
15
  end
16
16
 
17
17
  # Write code for a composition createAndAdd suggester
@@ -29,14 +29,21 @@ module Muml_Classifier
29
29
  # Write code for a suggester returning enum given has parameter
30
30
  #Note: if lowerValue is zero, null is also added (except if createAndAdd)
31
31
  def java_writeSuggesterBodyEnumWithType(oa,enum,isCreateAndAddSuggester=false)
32
+ if(true)
32
33
  write <<END
33
- java.util.ArrayList<#{enum.java_qualifiedName}> ret=new java.util.ArrayList<#{enum.java_qualifiedName}>();
34
- #{ (oa.umlx_lowerValueIsZero? && (!isCreateAndAddSuggester)) ? %{ret.add(null);} : %{} }
35
- for(int i=java.lang.reflect.Array.getLength(#{enum.java_qualifiedName}.values())-1; i>=0 ; i--){
36
- ret.add(#{enum.java_qualifiedName}.values()[i]);
34
+ return xmda.crud.Helper.arrayToList#{%{PlusNull} if (oa.umlx_lowerValueIsZero? && (!isCreateAndAddSuggester))}(#{enum.java_qualifiedName}\n\t\t\t\t\t\t.values());
35
+ END
36
+ else
37
+ write <<END
38
+ ret=new java.util.ArrayList<#{enum.java_qualifiedName}>();
39
+ #{ (oa.umlx_lowerValueIsZero? && (!isCreateAndAddSuggester)) ? %{ret.add(null);} : %{} }
40
+ for (int i = java.lang.reflect.Array
41
+ .getLength(#{enum.java_qualifiedName}\n\t\t\t\t\t\t.values()) - 1; i >= 0; i--) {
42
+ ret.add(#{enum.java_qualifiedName}\n\t\t\t\t\t.values()[i]);
37
43
  }
38
- return ret;
44
+ return ret;
39
45
  END
46
+ end
40
47
  end
41
48
 
42
49
  # Returns an UML LiteralInteger initialized with val value.
@@ -85,20 +92,20 @@ END
85
92
  #no code when derived
86
93
  elsif oe.nil? || !oe.umlx_isNavigable?
87
94
  set.java_code=<<END
88
- #{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)});
95
+ \t\t#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)});
89
96
  END
90
97
  elsif oe.umlx_upperValueIsOne?
91
98
  set.java_code=<<END
92
- #{qualInit}
93
- if(#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)})#{qualCheckRemove}) {
94
- #{getterParameterName(oa)}#{qualCall}.set#{oe.java_NameBean}(null);
99
+ \t\t#{qualInit}
100
+ \tif(#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)})#{qualCheckRemove}) {
101
+ \t\t\t#{getterParameterName(oa)}#{qualCall}.set#{oe.java_NameBean}(null);
95
102
  }
96
103
  END
97
104
  else
98
105
  set.java_code=<<END
99
- if(#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)})) {
100
- #{getterParameterName(oa)}#{qualCall}.remove#{oe.java_NameBean}(this);
101
- }
106
+ \t\tif(#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)})) {
107
+ \t\t\t#{getterParameterName(oa)}#{qualCall}.remove#{oe.java_NameBean}(this);
108
+ \t\t}
102
109
  END
103
110
  end
104
111
 
@@ -185,18 +192,22 @@ END
185
192
  elsif oe.umlx_upperValueIsOne?
186
193
  #*-1
187
194
  add.java_code=<<END
188
- if(#{ip.java_Name}==null) { return; }
189
- if(#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name})){
190
- #{ip.java_Name}.set#{oe.java_NameBean}(this);
191
- }
195
+ \t\tif (#{ip.java_Name} == null) {
196
+ \t\t\treturn;
197
+ \t\t}
198
+ \t\tif (#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name})) {
199
+ \t\t\t#{ip.java_Name}.set#{oe.java_NameBean}(this);
200
+ \t\t}
192
201
  END
193
202
  else
194
203
  #*-*
195
204
  add.java_code=<<END
196
- if(#{ip.java_Name}==null) { return; }
197
- if(#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name})) {
198
- #{ip.java_Name}.remove#{oe.java_NameBean}(this);
199
- }
205
+ \t\tif (#{ip.java_Name} == null) {
206
+ \t\t\treturn;
207
+ \t\t}
208
+ \t\tif (#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name})) {
209
+ \t\t\t#{ip.java_Name}.remove#{oe.java_NameBean}(this);
210
+ \t\t}
200
211
  END
201
212
  end
202
213
  end
@@ -217,11 +228,11 @@ END
217
228
  tenantClause=""
218
229
  if context[:multiTenant]
219
230
  #call constructor with tenant
220
- tenantClause="(#{TENANT_FIELD_NAME})"
231
+ tenantClause="(get#{TENANT_FIELD_BEAN_NAME}())"
221
232
  end
222
233
 
223
234
  rp=Cuml_Parameter.new(rdf_Repository,get.rdf_uri+"_p1")
224
- rp.uml_name="return"
235
+ rp.uml_name="\t\treturn"
225
236
  rp.uml_direction=Cuml_ParameterDirectionKind::Return
226
237
  rp.uml_upperValue=oa.uml_upperValue
227
238
  rp.uml_lowerValue=oa.uml_lowerValue
@@ -240,6 +251,134 @@ END
240
251
  end
241
252
  end
242
253
 
254
+ def java_getCrudHelperClass!
255
+ helper=umlx_getOrCreateClass('xmda.crud.Helper')
256
+ return helper unless helper.uml_ownedOperation.empty?
257
+ helper.db_isTransient=RDF_TRUE
258
+ helper.umlx_external=RDF_FALSE
259
+ helper.java_customCode=<<END
260
+
261
+ public static Object createFromEnum(#{java_getJavaEnumAssignInterface.java_qualifiedName} requestedType) {
262
+ if (requestedType == null) {
263
+ return null;
264
+ }
265
+
266
+ Class<?> t = requestedType.getType();
267
+ try {
268
+ Class<?>[] p = new Class[0];
269
+ Object[]initArgs =new Object[0];
270
+ java.lang.reflect.Constructor<?> c=t.getConstructor(p);
271
+ Object ret=c.newInstance(initArgs);
272
+ return ret;
273
+ } catch (NoSuchMethodException e) {
274
+ e.printStackTrace();
275
+ throw new RuntimeException("Missing default constructor for"+t.getName(),e);
276
+ } catch (IllegalAccessException e) {
277
+ e.printStackTrace();
278
+ throw new RuntimeException("Illegal access Exception on "+t.getName(),e);
279
+ } catch (InstantiationException e) {
280
+ e.printStackTrace();
281
+ throw new RuntimeException("Instantiation exception on "+t.getName(),e);
282
+ } catch (java.lang.reflect.InvocationTargetException e) {
283
+ e.printStackTrace();
284
+ throw new RuntimeException("Invocation Target Exception on "+t.getName(),e);
285
+ }
286
+ }
287
+
288
+ /*
289
+ * Helper for compacting code in add operations
290
+ */
291
+ @SuppressWarnings("unchecked")
292
+ public static <T> T[] genericUnidirAdd(final T t, T[] oldVal) {
293
+ T[] newArray = null;
294
+ if (oldVal == null) {
295
+ newArray = (T[]) new Object[1];
296
+ newArray[0] = t;
297
+ } else {
298
+ newArray = (T[]) new Object[1 + oldVal.length];
299
+ System.arraycopy(oldVal, 0, newArray, 0, oldVal.length);
300
+ newArray[oldVal.length] = t;
301
+ }
302
+ return newArray;
303
+ }
304
+
305
+ public static <T> java.util.List<T> arrayToList(T[] t) {
306
+ java.util.List<T> ret = null;
307
+ if (t == null) {
308
+ ret=new java.util.ArrayList<T>();
309
+ } else {
310
+ ret=java.util.Arrays.asList(t);
311
+ //if RW: ret=new java.util.ArrayList<T>(ret);
312
+ }
313
+ return ret;
314
+ }
315
+
316
+ public static <T> java.util.List<T> arrayToListPlusNull(T[] t) {
317
+ java.util.List<T> ret = null;
318
+ if (t == null) {
319
+ ret=new java.util.ArrayList<T>();
320
+ } else {
321
+ ret=java.util.Arrays.asList(t);
322
+ ret=new java.util.ArrayList<T>(ret);
323
+ }
324
+ ret.add(0,null);
325
+ return ret;
326
+ }
327
+
328
+ public static <T> boolean genericAddIgnoreNull(java.util.Collection<T> lst,
329
+ T elt) {
330
+ if (elt != null) {
331
+ return lst.add(elt);
332
+ }
333
+ return false; // no change
334
+ }
335
+
336
+ /**
337
+ * replace null Long by 0 Long
338
+ * Method used by jpa module.
339
+ */
340
+ public static Long longObjZeroForNull(Long id) {
341
+ if (id == null) {
342
+ return Long.valueOf(0);
343
+ } else {
344
+ return id;
345
+ }
346
+ }
347
+
348
+ /* method to be used by jpa */
349
+ public static<T> java.util.List<T> addMissingItems(java.util.List<T> lstInOut,java.util.Collection<T> missings) {
350
+ for (java.util.Iterator<T> iterator = missings.iterator(); iterator.hasNext();) {
351
+ T item = (T) iterator.next();
352
+ if (!lstInOut.contains(item)) {
353
+ lstInOut.add(item);
354
+ }
355
+ }
356
+ return lstInOut;
357
+ }
358
+
359
+ /* returns lst if no null, or a newly created set otherwise */
360
+ public static <T> java.util.Set<T> emptyNewCollectionIfNull(java.util.Set<T> lst) {
361
+ if (lst != null) {
362
+ return lst;
363
+ } else {
364
+ return new java.util.HashSet<T>();
365
+ }
366
+ }
367
+
368
+ /* returns lst if no null, or a newly created List otherwise */
369
+ public static <T> java.util.List<T> emptyNewCollectionIfNull(java.util.List<T> lst) {
370
+ if (lst != null) {
371
+ return lst;
372
+ } else {
373
+ return new java.util.ArrayList<T>();
374
+ }
375
+ }
376
+
377
+ END
378
+
379
+ return helper
380
+ end
381
+
243
382
  #Adds a createAndAdd method for parameter oa using a model transformation.
244
383
  #
245
384
  #NOTE:
@@ -279,38 +418,17 @@ END
279
418
  # no java code generated
280
419
 
281
420
  #TODO: factorize in helper class
282
- add.java_code=%{
283
- if (requestedType==null) {
284
- return null;
285
- }
286
- String qname=requestedType.name().replaceAll("#{JAVA_MAGIC_DOT_STRING}",".");
287
- try {
288
- // c=#{java_this(oa)}getClass().getClassLoader().loadClass(requestedType.name());
289
- Class<?> t = Class.forName(qname);
290
- Class<?>[] p = new Class[0];
291
- Object[]initArgs =new Object[0];
292
- java.lang.reflect.Constructor<?> c=t.getConstructor(p);
293
- #{oa.uml_type_one.java_qualifiedName} ret=(#{oa.uml_type_one.java_qualifiedName})c.newInstance(initArgs);
294
- #{%{ret.setTenantOwner(getTenantOwner());} if context[:multiTenant]}
295
- #{oa.umlx_upperValueIsOne? ? "set" : "add"}#{oa.java_NameBean}(ret);
296
- return ret;
297
- } catch (ClassNotFoundException e) {
298
- e.printStackTrace();
299
- throw new RuntimeException("Missing type "+qname,e);
300
- } catch (NoSuchMethodException e) {
301
- e.printStackTrace();
302
- throw new RuntimeException("Missing default constructor for"+qname,e);
303
- } catch (IllegalAccessException e) {
304
- e.printStackTrace();
305
- throw new RuntimeException("Illegal access Exception on "+qname,e);
306
- } catch (InstantiationException e) {
307
- e.printStackTrace();
308
- throw new RuntimeException("Instantiation exception on "+qname,e);
309
- } catch (java.lang.reflect.InvocationTargetException e) {
310
- e.printStackTrace();
311
- throw new RuntimeException("Invocation Target Exception on "+qname,e);
312
- }}
421
+
422
+
423
+
424
+ add.java_code=%{\t\t#{oa.uml_type_one.java_qualifiedName} ret = (#{oa.uml_type_one.java_qualifiedName})#{java_getCrudHelperClass!.java_qualifiedName}.createFromEnum(requestedType);#{%{
425
+ \t\tret.setTenantOwner(getTenantOwner());} if context[:multiTenant]}
426
+ \t\t#{oa.umlx_upperValueIsOne? ? "set" : "add"}#{oa.java_NameBean}(ret);
427
+ \t\treturn ret;}
313
428
  end
429
+
430
+ # generate add/... using helper instead of inlining
431
+ USE_HELPER_FOR_ACCESSORS=true
314
432
 
315
433
  # Adds an appender for parameter oa using a model transformation.
316
434
  #
@@ -340,41 +458,58 @@ END
340
458
  # no code generated
341
459
  elsif (oe.nil? || !oe.umlx_isNavigable?) && !oa.java_use_Arrays?
342
460
  add.java_code=<<END
343
- if(#{getterParameterName(oa)}==null) { return; }
344
- #{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)});
461
+ \t\txmda.crud.Helper.genericAddIgnoreNull(#{java_this(oa)}#{oa.java_NameProperty},#{getterParameterName(oa)} );
345
462
  END
463
+ # add.java_code=<<END
464
+ #\t\tif (#{getterParameterName(oa)} == null) {
465
+ #\t\t\treturn;
466
+ #\t\t}
467
+ #\t\t#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)});
468
+ #END
346
469
  elsif (oe.nil? || !oe.umlx_isNavigable?) && oa.java_use_Arrays?
347
470
  add.java_code=<<END
348
- if(#{getterParameterName(oa)}==null) { return; }
349
- #{oa.uml_type_one.java_qualifiedName}[] newArray=null;
350
- if (#{java_this(oa)}#{oa.java_NameProperty}==null) {
351
- newArray=new #{oa.uml_type_one.java_qualifiedName}[1];
352
- newArray[0]=#{getterParameterName(oa)};
353
- } else {
354
- newArray=new #{oa.uml_type_one.java_qualifiedName}[1+#{java_this(oa)}#{oa.java_NameProperty}.length];
355
- System.arraycopy(#{java_this(oa)}#{oa.java_NameProperty}, 0, newArray,0, #{java_this(oa)}#{oa.java_NameProperty}.length);
356
- newArray[#{java_this(oa)}#{oa.java_NameProperty}.length]=#{getterParameterName(oa)};
357
- }
358
- #{java_this(oa)}#{oa.java_NameProperty}=newArray;
471
+ \t\tif (#{getterParameterName(oa)} == null) {
472
+ \t\t\treturn;
473
+ \t\t}
474
+ \t\t#{oa.uml_type_one.java_qualifiedName}[] newArray = null;
475
+ \t\tif (#{java_this(oa)}#{oa.java_NameProperty} == null) {
476
+ \t\t\tnewArray = new #{oa.uml_type_one.java_qualifiedName}[1];
477
+ \t\t\tnewArray[0] = #{getterParameterName(oa)};
478
+ \t\t} else {
479
+ \t\t\tnewArray = new #{oa.uml_type_one.java_qualifiedName}[1+#{java_this(oa)}#{oa.java_NameProperty}.length];
480
+ \t\t\tSystem.arraycopy(#{java_this(oa)}#{oa.java_NameProperty}, 0, newArray,0, #{java_this(oa)}#{oa.java_NameProperty}.length);
481
+ \t\t\tnewArray[#{java_this(oa)}#{oa.java_NameProperty}.length] = #{getterParameterName(oa)};
482
+ \t\t}
483
+ \t\t#{java_this(oa)}#{oa.java_NameProperty} = newArray;
359
484
  END
360
485
 
361
486
 
362
487
  elsif oe.umlx_upperValueIsOne?
363
488
  #*-1
364
489
  add.java_code=<<END
365
- if(#{getterParameterName(oa)}==null) { return; }
366
- if(#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)})){
367
- #{getterParameterName(oa)}.set#{oe.java_NameBean}(this);
368
- }
490
+ \t\tif (xmda.crud.Helper.genericAddIgnoreNull(#{java_this(oa)}#{oa.java_NameProperty},#{getterParameterName(oa)} )) {
491
+ \t\t\t#{getterParameterName(oa)}.set#{oe.java_NameBean}(this);
492
+ \t\t}
369
493
  END
494
+
495
+ # add.java_code= <<END
496
+ #\t\tif (#{getterParameterName(oa)} == null) {
497
+ #\t\t\treturn;
498
+ #\t\t}
499
+ #\t\tif (#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)})){
500
+ #\t\t\t#{getterParameterName(oa)}.set#{oe.java_NameBean}(this);
501
+ #\t\t}
502
+ #END
370
503
  else
371
504
  #*-*
372
505
  # second test avoids loop
373
506
  add.java_code=<<END
374
- if(#{getterParameterName(oa)}==null) { return; }
375
- if(#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)})) {
376
- #{getterParameterName(oa)}.add#{oe.java_NameBean}(this);
377
- }
507
+ \t\tif (#{getterParameterName(oa)} == null) {
508
+ \t\t\treturn;
509
+ \t\t}
510
+ \t\tif (#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)})) {
511
+ \t\t\t#{getterParameterName(oa)}.add#{oe.java_NameBean}(this);
512
+ \t\t}
378
513
  END
379
514
  end
380
515
 
@@ -400,13 +535,22 @@ END
400
535
  # * #java_writeEnumStringMappingGetterCode
401
536
  # * #java_getCollectionMapping
402
537
  def java_writeGlobalGetterBody(oa)
403
- return if oa.uml_isDerived? && oa.umlx_stringMappingForEnum.empty?
404
-
405
- if java_isEnumStringMapping?(oa)
538
+ if oa.uml_isDerived? && oa.umlx_stringMappingForEnum.empty?
539
+ # provide an implementation because a getter
540
+ # should never throw an exception.
541
+ write ("\t\t//TODO: implement this derived attribute\n")
542
+ if oa.umlx_oneSide?
543
+ v=DatatypeMapping.instance.getMapping(oa.uml_type_one)
544
+ write ("\t\treturn #{v.java_getUndefinedValue};");
545
+ else
546
+ cm=oa.java_getCollectionMapping
547
+ write ("\t\treturn #{cm.addNew(oa.uml_type_one.java_qualifiedName)};");
548
+ end
549
+ elsif java_isEnumStringMapping?(oa)
406
550
  java_writeEnumStringMappingGetterCode(oa)
407
551
 
408
552
  elsif oa.umlx_upperValueIsOne? || !oa.uml_qualifier.empty?
409
- j="return #{oa.java_NameProperty}"
553
+ j="\t\treturn #{oa.java_NameProperty}"
410
554
  sep_next=".get("
411
555
  sep_end=""
412
556
  #oa.uml_qualifier.each { |key|
@@ -416,14 +560,20 @@ END
416
560
  #}
417
561
  j=j+sep_end +";"
418
562
  write j
419
- else
563
+ elsif ! oa.java_use_Arrays?
420
564
  #on ne peut pas permettre la modification de la liste en direct
421
565
  write %{
422
- if(#{oa.java_NameProperty}!=null){
423
- return #{oa.java_NameProperty};
424
- } else {
425
- return #{oa.java_getCollectionMapping.addNew(oa.uml_type_one.java_qualifiedName)};
426
- }}
566
+ return xmda.crud.Helper.emptyNewCollectionIfNull(#{oa.java_NameProperty});
567
+ }
568
+ else
569
+ # code same as above bu could not get it to work with generic Array
570
+ write %{
571
+ if(#{oa.java_NameProperty}!=null){
572
+ return #{oa.java_NameProperty};
573
+ } else {
574
+ return #{oa.java_getCollectionMapping.addNew(oa.uml_type_one.java_qualifiedName)};
575
+ }}
576
+
427
577
  end
428
578
  end
429
579
 
@@ -449,7 +599,7 @@ if(#{oa.java_NameProperty}!=null){
449
599
  # other end is non navigable.
450
600
  #begin
451
601
  #if oa.uml_qualifier.empty?
452
- write "#{java_this(oa)}#{oa.java_NameProperty}=#{getterParameterName(oa)};"
602
+ write "\t\t#{java_this(oa)}#{oa.java_NameProperty} = #{getterParameterName(oa)};"
453
603
  #else
454
604
  # j="{ #{oa.java_NameProperty}.put("
455
605
  # sep=""
@@ -478,19 +628,25 @@ END
478
628
  elsif oa.umlx_upperValueIsOne? && (!oe.umlx_upperValueIsOne?)
479
629
  # 1<->*
480
630
  write <<END
481
- if(#{oa.java_NameProperty}!=null && #{oa.java_NameProperty}.equals(#{getterParameterName(oa)})) { return ;}
482
- #{oa.uml_type_one.java_qualifiedName} previous=#{oa.java_NameProperty};
631
+ if (#{oa.java_NameProperty} != null && #{oa.java_NameProperty}.equals(#{getterParameterName(oa)})) {
632
+ return;
633
+ }
634
+ #{oa.uml_type_one.java_qualifiedName} previous = #{oa.java_NameProperty};
483
635
 
484
- #{oa.java_NameProperty}=null;
485
- if(previous!=null) { previous.remove#{oe.java_NameBean}(this); }
636
+ #{oa.java_NameProperty} = null;
637
+ if (previous != null) {
638
+ previous.remove#{oe.java_NameBean}(this);
639
+ }
486
640
 
487
- #{java_this(oa)}#{oa.java_NameProperty}=#{getterParameterName(oa)};
488
- if(#{getterParameterName(oa)}!=null) { #{getterParameterName(oa)}.add#{oe.java_NameBean}(this); }
641
+ #{java_this(oa)}#{oa.java_NameProperty} = #{getterParameterName(oa)};
642
+ if (#{getterParameterName(oa)} != null) {
643
+ #{getterParameterName(oa)}.add#{oe.java_NameBean}(this);
644
+ }
489
645
  END
490
646
  else # *<->1 and *<->*
491
647
  write <<END
492
648
  #{oa.java_propertyAssociationType} toBeRemoved=new #{oa.java_propertyAssociationConcreteType}();
493
- for(#{oa.uml_type_one.java_qualifiedName} item:#{oa.java_NameProperty}) {
649
+ for(#{oa.uml_type_one.java_qualifiedName} item:this.#{oa.java_NameProperty}) {
494
650
  if(#{getterParameterName(oa)}!=null && #{getterParameterName(oa)}.contains(item)) { continue;}
495
651
  toBeRemoved.add(item);
496
652
  }
@@ -516,7 +672,7 @@ END
516
672
  # * #java_writeEnumStringMappingSetterCode
517
673
  # * #java_getCollectionMapping
518
674
  def java_writeQualifiedGetterBody(oa)
519
- write("return #{oa.java_NameProperty}.get(")
675
+ write("\t\treturn #{oa.java_NameProperty}.get(")
520
676
  sep=""
521
677
  oa.uml_qualifier.each { |key|
522
678
  write(sep)