ontomde-uml2-java 1.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.
- data/History.txt +8 -0
- data/Manifest.txt +24 -0
- data/README.txt +98 -0
- data/Rakefile +21 -0
- data/lib/ontomde-uml2-java/accessorCode.rb +496 -0
- data/lib/ontomde-uml2-java/accessorSignature.rb +304 -0
- data/lib/ontomde-uml2-java/build.rb +80 -0
- data/lib/ontomde-uml2-java/collectionMapping.rb +98 -0
- data/lib/ontomde-uml2-java/enumAssignable.rb +67 -0
- data/lib/ontomde-uml2-java/enumCompatibilityLayer.rb +188 -0
- data/lib/ontomde-uml2-java/equals.rb +91 -0
- data/lib/ontomde-uml2-java/groovy.rb +56 -0
- data/lib/ontomde-uml2-java/java.rb +1252 -0
- data/lib/ontomde-uml2-java/java.rdoc +78 -0
- data/lib/ontomde-uml2-java/javaHelper.rb +25 -0
- data/lib/ontomde-uml2-java/javaMapping.rb +420 -0
- data/lib/ontomde-uml2-java/java_todo.rdoc +3 -0
- data/lib/ontomde-uml2-java/javadoc.rb +217 -0
- data/lib/ontomde-uml2-java/meta.rb +26 -0
- data/lib/ontomde-uml2-java/operationAsClass.rb +130 -0
- data/lib/ontomde-uml2-java/security.rb +232 -0
- data/lib/ontomde-uml2-java/version.rb +7 -0
- data/lib/ontomde-uml2-java.rb +37 -0
- data/test/test_ontomde-uml2-java.rb +0 -0
- metadata +96 -0
@@ -0,0 +1,1252 @@
|
|
1
|
+
#:include: java.rdoc
|
2
|
+
#:include: java_todo.rdoc
|
3
|
+
|
4
|
+
module Mjava_Annotation
|
5
|
+
rdf_safe_attr_reader_many :java_annotation
|
6
|
+
def java_writeAnnotation
|
7
|
+
mtk_protected(Mrdf_Resource::NOREVERSE,"annotations") {
|
8
|
+
java_annotation.each {|a|
|
9
|
+
write(a)
|
10
|
+
write("\n")
|
11
|
+
}
|
12
|
+
write("@Override\n") if (self.kind_of?(Muml_Operation) && !umlx_redefinesMethod.empty? && !umlx_redefinesMethod_one.umlx_owner_one.kind_of?(Muml_Interface) )
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module Muml_Classifier
|
18
|
+
rdf_safe_attr_reader_many :java_import
|
19
|
+
rdf_safe_attr_reader_many :java_implements
|
20
|
+
rdf_safe_attr_reader_many :java_extends
|
21
|
+
rdf_safe_attr_reader_many :java_isATestFile
|
22
|
+
include Mjava_Annotation
|
23
|
+
end
|
24
|
+
module Muml_Operation
|
25
|
+
rdf_safe_attr_reader_many :java_getter_property
|
26
|
+
rdf_safe_attr_reader_many :java_setter_property
|
27
|
+
include Mjava_Annotation
|
28
|
+
end
|
29
|
+
module Muml_Property
|
30
|
+
include Mjava_Annotation
|
31
|
+
rdf_safe_attr_reader_many :java_AttributeGlobalSetter
|
32
|
+
rdf_safe_attr_reader_many :java_AttributeGlobalGetter
|
33
|
+
|
34
|
+
#Attribut pouvant contenir la valeur initiale.
|
35
|
+
#Utilise lorsque le java_code est calcul? automatiquement.
|
36
|
+
rdf_safe_attr_reader_many :java_code
|
37
|
+
|
38
|
+
#Transient attribute
|
39
|
+
rdf_safe_attr_reader_many :java_isTransient
|
40
|
+
|
41
|
+
#is persistent (in database)
|
42
|
+
rdf_safe_attr_reader_many :db_isTransient
|
43
|
+
|
44
|
+
#property is final
|
45
|
+
rdf_safe_attr_reader_many :java_isFinal
|
46
|
+
end
|
47
|
+
|
48
|
+
module Muml_EnumerationLiteral
|
49
|
+
#List of initialisation parameter for this literal.
|
50
|
+
rdf_safe_attr_reader_many :java_initParameterValue
|
51
|
+
end
|
52
|
+
|
53
|
+
module Muml_Operation
|
54
|
+
#Attribut pouvant contenir le code java de la methode.
|
55
|
+
#Utilise lorsque le java_code est calcul? automatiquement.
|
56
|
+
rdf_safe_attr_reader_many :java_code
|
57
|
+
|
58
|
+
#is operation synchronised
|
59
|
+
rdf_safe_attr_reader_many :java_isSynchronised
|
60
|
+
end
|
61
|
+
|
62
|
+
module Muml_Parameter
|
63
|
+
# extension metamodele
|
64
|
+
rdf_safe_attr_reader_many :uml_qualifier
|
65
|
+
#rdf_safe_attr_reader_many :umlx_qualifier
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
module Muml_Stereotype
|
70
|
+
def getRubyStereotypeName
|
71
|
+
return uml_name.to_s.tr('^a-zA-Z0-9','_')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
module Mrdf_Model
|
75
|
+
|
76
|
+
# Example
|
77
|
+
# java_addJavaFilePathMapping(/\.example/,"src/main/example/" ])
|
78
|
+
#TODO: add helping error if jfp.nil?
|
79
|
+
def java_addContextJavaFilePathMapping(qualifiedNameRegexp,relativePath)
|
80
|
+
jfp=context[:javaFilePathRegexp]
|
81
|
+
jfp[qualifiedNameRegexp,relativePath]
|
82
|
+
end
|
83
|
+
|
84
|
+
def umlx_processStereotypes!
|
85
|
+
return
|
86
|
+
each { |k,c|
|
87
|
+
next unless c.kind_of?(Muml_Stereotype)
|
88
|
+
#log.debug "Registering stereotype #{c.getRubyStereotypeName}"
|
89
|
+
eval %{
|
90
|
+
module ::Muml_Stereotype_#{c.getRubyStereotypeName}
|
91
|
+
end
|
92
|
+
}
|
93
|
+
}
|
94
|
+
each {|k,c|
|
95
|
+
next unless c.kind_of?(Muml_Element)
|
96
|
+
next if c.appliedStereotype.empty?
|
97
|
+
appliedStereotype.each { |s|
|
98
|
+
c.class_eval %{
|
99
|
+
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
#trigger Muml_Classifier java_transform! for every class element
|
107
|
+
def java_transform!
|
108
|
+
#must copy before transformation (hash modified runtime error)
|
109
|
+
a=Array.new
|
110
|
+
each { |k,c|
|
111
|
+
next if c.kind_of?(Muml_Stereotype)
|
112
|
+
next unless c.kind_of?(Muml_Class) || c.kind_of?(Muml_Interface)||c.kind_of?(Muml_Enumeration)
|
113
|
+
a << c
|
114
|
+
}
|
115
|
+
a.each {|c|
|
116
|
+
c.java_transform! unless c.java_ignoreMe?
|
117
|
+
}
|
118
|
+
|
119
|
+
#java_addPersistence!
|
120
|
+
umlx_processStereotypes!
|
121
|
+
end
|
122
|
+
|
123
|
+
#Main java generator entry point.
|
124
|
+
#Triggers the generation of every Java file for the model.
|
125
|
+
def java_generate
|
126
|
+
uml_Model_all.each {|m|
|
127
|
+
m.java_generate
|
128
|
+
}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
module Muml_Model
|
133
|
+
def java_generate
|
134
|
+
mtk_default_context(:java_generateSetAttributeInitializer=>true) {
|
135
|
+
uml_Class_all.each {|c|
|
136
|
+
#next if c.kind_of?(Muml_Stereotype)
|
137
|
+
next unless c.kind_of?(Muml_Class) || c.kind_of?(Muml_Interface)||c.kind_of?(Muml_Enumeration)
|
138
|
+
# only generate if requested to do so
|
139
|
+
# usefull for generating separtely tests dans model
|
140
|
+
next if c.java_isATestFile? && !context[:includeTestFiles]
|
141
|
+
next if (!c.java_isATestFile?) && context[:excludeNonTestFiles]
|
142
|
+
c.java_generate
|
143
|
+
}
|
144
|
+
}
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
#module Muml_Property
|
149
|
+
# def java_Name
|
150
|
+
# return uml_isStatic? ? super.upcase : super
|
151
|
+
# end
|
152
|
+
#end
|
153
|
+
|
154
|
+
module Muml_NamedElement
|
155
|
+
# true if name contains a generic.
|
156
|
+
rdf_safe_attr_reader_many :java_isGeneric
|
157
|
+
|
158
|
+
JAVA_RESERVED_WORD=["abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "do", "double", "else", "enum", "extends", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "try", "void", "volatile", "while"]
|
159
|
+
JAVA_NUMBERS=["0","1","2","3","4","5","6","7","8","9"]
|
160
|
+
#returns a valid java symbol computed from str
|
161
|
+
#
|
162
|
+
#NOTE:
|
163
|
+
#
|
164
|
+
# display a warning an return /*TODO ...*/ if str is empty
|
165
|
+
#
|
166
|
+
#Examples:
|
167
|
+
# java_safeName("number") returns number
|
168
|
+
# java_safeName("8number") returns _number
|
169
|
+
def java_safeName(str)
|
170
|
+
if str.empty?
|
171
|
+
log.warn "WARNING: blank name detected for obj type #{self.class.name} identified by uri=#{uri}"
|
172
|
+
return "/*TODO: ERROR:blank name found in uml model:*/"
|
173
|
+
end
|
174
|
+
#TODO A g?rer globalement pour la gestion des g?n?riques
|
175
|
+
if java_isGeneric?
|
176
|
+
# a generic may contain names such as xyz<org.myname>
|
177
|
+
ret=str.to_s.tr('^a-zA-Z0-9_<?>.,',"")
|
178
|
+
else
|
179
|
+
ret=str.to_s.tr('^a-zA-Z0-9_',"")
|
180
|
+
end
|
181
|
+
ret="_"+ret if JAVA_NUMBERS.include?(ret[0,1])
|
182
|
+
ret="_"+ret if JAVA_RESERVED_WORD.include?(ret)
|
183
|
+
return ret
|
184
|
+
end
|
185
|
+
|
186
|
+
#java unique name enforcement variable
|
187
|
+
JAVA_UNIQUE_NAME=Hash.new
|
188
|
+
|
189
|
+
#return a unique name for this element.
|
190
|
+
#Logs an error messge is uniqueness is not verified.
|
191
|
+
def java_uniqueName
|
192
|
+
ret=java_Name.to_s
|
193
|
+
k=JAVA_UNIQUE_NAME[ret]
|
194
|
+
if k.nil?
|
195
|
+
JAVA_UNIQUE_NAME[ret]=rdf_uri
|
196
|
+
elsif k!=rdf_uri
|
197
|
+
log_error_unique_name
|
198
|
+
end
|
199
|
+
return ret
|
200
|
+
end
|
201
|
+
|
202
|
+
def log_error_unique_name
|
203
|
+
#return if log_already_displayed?("#{rdf_uri}__uniqueName")
|
204
|
+
log.error {
|
205
|
+
<<END
|
206
|
+
non unique name detected
|
207
|
+
********* INVALID DATA DETECTED **********
|
208
|
+
** This software expects uml names to be globaly unique.
|
209
|
+
** The following item has been detected to be an homonym
|
210
|
+
** of a previously processed model element.
|
211
|
+
** #{mtk_object_message}
|
212
|
+
**
|
213
|
+
** Check your model and make sure names are unique.
|
214
|
+
**
|
215
|
+
** This model element is related to these other model elements:
|
216
|
+
#{mtk_related_message}
|
217
|
+
********* INVALID DATA DETECTED **********
|
218
|
+
END
|
219
|
+
}
|
220
|
+
if context[:java_failIfNonUniqueName]
|
221
|
+
raise Warning.new(),"unique name assertion failed"
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
#Returns this element uml_name after applying java_safeName on it.
|
227
|
+
@java_Name_cache=nil
|
228
|
+
def java_Name
|
229
|
+
return @java_Name_cache unless @java_Name_cache.nil?
|
230
|
+
s=java_safeName(uml_name.to_s)
|
231
|
+
b=context[:java_fixNameCase,true]
|
232
|
+
if !b
|
233
|
+
# do nothing
|
234
|
+
elsif kind_of?(Muml_Package) || kind_of?(Muml_Property) || kind_of?(Muml_Parameter) || kind_of?(Muml_Operation)
|
235
|
+
if s[0..0].downcase!=s[0..0]
|
236
|
+
s="#{s[0..0].downcase}#{s[1,s.length]}"
|
237
|
+
display_java_Name_case_error(true)
|
238
|
+
end
|
239
|
+
elsif (kind_of?(Muml_Class) || kind_of?(Muml_Interface) || kind_of?(Muml_Enumeration) ) && ! kind_of?(Muml_PrimitiveType)
|
240
|
+
if s[0..0].capitalize!=s[0..0]
|
241
|
+
s="#{s[0..0].capitalize}#{s[1,s.length]}"
|
242
|
+
display_java_Name_case_error(false)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
@java_Name_cache=s
|
246
|
+
return @java_Name_cache
|
247
|
+
end
|
248
|
+
#DISPLAY_JAVA_NAME_CASE_ERROR=Set.new()
|
249
|
+
def display_java_Name_case_error(isDowncase)
|
250
|
+
return unless context[:java_display_case_errors,false]
|
251
|
+
#next if DISPLAY_JAVA_NAME_CASE_ERROR.include?(self)
|
252
|
+
#DISPLAY_JAVA_NAME_CASE_ERROR<< self
|
253
|
+
log.error { %{***** INVALID MODEL DETECTED *****
|
254
|
+
***** INVALID MODEL DETECTED *****
|
255
|
+
Model element name:
|
256
|
+
uml_class=#{self.class.name}
|
257
|
+
rdf_uri=#{rdf_uri}
|
258
|
+
uml_name=#{uml_name}
|
259
|
+
uml_owner=#{umlx_owner_one}
|
260
|
+
should begin with a #{isDowncase ? "downcase": "upcase"} character.
|
261
|
+
***** INVALID MODEL DETECTED *****
|
262
|
+
}}
|
263
|
+
end
|
264
|
+
|
265
|
+
|
266
|
+
#Returns this element java_Name after applying a simplified java bean case convention.
|
267
|
+
#http://java.sun.com/products/javabeans/docs/spec.html
|
268
|
+
#anIntAttribute --> AnIntAttribute
|
269
|
+
#aBooleanAttribute --> aBooleanAttribute
|
270
|
+
def java_NameBean
|
271
|
+
return java_toNameBean(java_Name.to_s)
|
272
|
+
end
|
273
|
+
def java_toNameBean(name)
|
274
|
+
#special case handling introduced for struts
|
275
|
+
return name if name[1,1].upcase==name[1,1]
|
276
|
+
name=String.new(name)
|
277
|
+
name[0] = name[0, 1].upcase
|
278
|
+
return name
|
279
|
+
end
|
280
|
+
|
281
|
+
#Returns this element java_Name after applying a simplified java bean property case convention.
|
282
|
+
def java_NameProperty
|
283
|
+
return java_Name
|
284
|
+
#return java_toNameProperty(java_Name)
|
285
|
+
end
|
286
|
+
|
287
|
+
#Converts string name to a property name and returns its value.
|
288
|
+
#
|
289
|
+
#Example:
|
290
|
+
# java_toNameProperty("Xyz") return "xyz"
|
291
|
+
# java_toNameProperty("XYZ") return "xYZ"
|
292
|
+
def java_toNameProperty(name)
|
293
|
+
result = String.new(name)
|
294
|
+
if !result.empty?
|
295
|
+
result[0] = result[0, 1].downcase
|
296
|
+
end
|
297
|
+
return result
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
module Muml_Namespace
|
302
|
+
|
303
|
+
def java_getContextJavaFilePath(default=nil)
|
304
|
+
n=java_qualifiedName.to_s
|
305
|
+
jfp=context[:javaFilePathRegexp,nil]
|
306
|
+
return default if jfp.nil?
|
307
|
+
jfp.each { |mapping|
|
308
|
+
if n =~ mapping[0]
|
309
|
+
return context[:targetDir]+"/"+mapping[1]
|
310
|
+
end
|
311
|
+
}
|
312
|
+
return default
|
313
|
+
end
|
314
|
+
# Returns the path where to generate file for this object.
|
315
|
+
#
|
316
|
+
# NOTE:
|
317
|
+
# * Root directory is taken from context[:javaDir] (cf: mtk_context)
|
318
|
+
#
|
319
|
+
# Examples (with context[:build] equals to "build/":
|
320
|
+
# * build/package1/package2
|
321
|
+
# * build/package1/package2/UneClasse.java
|
322
|
+
def java_FilePath
|
323
|
+
return java_getContextJavaFilePath(context[:javaDir])+java_InternalFilePath
|
324
|
+
end
|
325
|
+
|
326
|
+
# Returns the internal path where to generate file for this object.
|
327
|
+
#
|
328
|
+
# NOTE:
|
329
|
+
#
|
330
|
+
# Examples
|
331
|
+
# *package1/package2
|
332
|
+
# *package1/package2/UneClasse.java
|
333
|
+
def java_InternalFilePath
|
334
|
+
r=""
|
335
|
+
umlx_sub_hierarchy.each { |n|
|
336
|
+
r+=n.java_Name
|
337
|
+
r+="/"
|
338
|
+
}
|
339
|
+
return r
|
340
|
+
end
|
341
|
+
|
342
|
+
|
343
|
+
end
|
344
|
+
|
345
|
+
|
346
|
+
module Muml_VisibilityKind
|
347
|
+
#returns java visibility modifiers (public/protected/private/package)
|
348
|
+
def java_visibilityModifiers
|
349
|
+
return "public " if isPublic?
|
350
|
+
return "protected " if isProtected?
|
351
|
+
return "private " if isPrivate?
|
352
|
+
return "" if isPackage?
|
353
|
+
return " !! error : unknown visibility #{uri}!! "
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
module Muml_UML
|
362
|
+
#write java class modifiers if needed (abstract, public, ...)
|
363
|
+
#Example: public abstract
|
364
|
+
def java_writeClassModifiers
|
365
|
+
uml_visibility.each { |v|
|
366
|
+
write(v.java_visibilityModifiers)
|
367
|
+
}
|
368
|
+
write "abstract " if uml_isAbstract?
|
369
|
+
end
|
370
|
+
|
371
|
+
#write java static modifier if needed
|
372
|
+
def java_writeStaticModifier
|
373
|
+
write("static ") if uml_isStatic?
|
374
|
+
end
|
375
|
+
|
376
|
+
end
|
377
|
+
#module Muml_EnumerationLiteral
|
378
|
+
# def java_Name
|
379
|
+
# end
|
380
|
+
#end
|
381
|
+
module Muml_Enumeration
|
382
|
+
|
383
|
+
#writes java5 enum keyword and enum class name
|
384
|
+
#
|
385
|
+
#Example:
|
386
|
+
#* enum Colors
|
387
|
+
def java_writeMetaClassName
|
388
|
+
write("enum #{java_Name}")
|
389
|
+
end
|
390
|
+
|
391
|
+
#write enum body (list of litterals) using java_writeClassComment, java_writeClassModifiers, java_writeMetaClassName.
|
392
|
+
#
|
393
|
+
#Example:
|
394
|
+
#* { red,blue,green }
|
395
|
+
def java_writeClassBody
|
396
|
+
java_writeClassComment
|
397
|
+
java_writeJavadoc
|
398
|
+
java_writeAnnotation
|
399
|
+
java_writeClassModifiers
|
400
|
+
java_writeMetaClassName
|
401
|
+
java_writeImplements
|
402
|
+
write("{\n")
|
403
|
+
sep=""
|
404
|
+
uml_ownedLiteral.each {|c|
|
405
|
+
write(sep);
|
406
|
+
c.java_writeJavadoc
|
407
|
+
write(c.java_Name)
|
408
|
+
if !c.java_initParameterValue.empty?
|
409
|
+
sep=("(")
|
410
|
+
c.java_initParameterValue.each {|v|
|
411
|
+
write(sep) ; sep=","
|
412
|
+
write(v)
|
413
|
+
}
|
414
|
+
write(")")
|
415
|
+
end
|
416
|
+
sep=",\n"
|
417
|
+
}
|
418
|
+
write(";\n") # literal/code separator
|
419
|
+
|
420
|
+
#java_writeDeclarationSpecificOnBegin
|
421
|
+
java_writeAttributes
|
422
|
+
write("\n\n")
|
423
|
+
#java_writeConstructors
|
424
|
+
write("\n\n")
|
425
|
+
java_writeOperations
|
426
|
+
java_writeCustomCode
|
427
|
+
#java_writeDeclarationSpecificOnEnd
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
write("\n}");
|
432
|
+
end
|
433
|
+
|
434
|
+
#write java implements declaration clause if needed.
|
435
|
+
#
|
436
|
+
#Example:
|
437
|
+
#* implements interface1, interface2
|
438
|
+
def java_writeImplements
|
439
|
+
imp=Set.new
|
440
|
+
uml_implementation.each { |g|
|
441
|
+
imp.add(g.uml_supplier_one.java_qualifiedName)
|
442
|
+
}
|
443
|
+
java_implements.each { |g|
|
444
|
+
imp.add(g)
|
445
|
+
}
|
446
|
+
|
447
|
+
sep="\nimplements "
|
448
|
+
imp.sort{ |a,b| a <=> b}.each { |g|
|
449
|
+
write(sep)
|
450
|
+
write(g)
|
451
|
+
sep=","
|
452
|
+
}
|
453
|
+
end
|
454
|
+
|
455
|
+
end
|
456
|
+
|
457
|
+
module Muml_Interface
|
458
|
+
|
459
|
+
#does nothing
|
460
|
+
def java_writeImplements
|
461
|
+
end
|
462
|
+
|
463
|
+
#write java interface keyword and interface name
|
464
|
+
#
|
465
|
+
#Example:
|
466
|
+
#* interface Interface1
|
467
|
+
def java_writeMetaClassName
|
468
|
+
write("interface #{java_Name}")
|
469
|
+
end
|
470
|
+
end
|
471
|
+
|
472
|
+
module Muml_Class
|
473
|
+
|
474
|
+
#write java class keyword and class name
|
475
|
+
#
|
476
|
+
#Example:
|
477
|
+
#* classe Class1
|
478
|
+
def java_writeMetaClassName
|
479
|
+
write(" class #{java_Name}")
|
480
|
+
end
|
481
|
+
|
482
|
+
#write java implements declaration clause if needed.
|
483
|
+
#
|
484
|
+
#Example:
|
485
|
+
#* implements interface1, interface2
|
486
|
+
def java_writeImplements
|
487
|
+
imp=Set.new
|
488
|
+
uml_implementation.each { |g|
|
489
|
+
imp.add(g.uml_supplier_one.java_qualifiedName)
|
490
|
+
}
|
491
|
+
java_implements.each { |g|
|
492
|
+
imp.add(g)
|
493
|
+
}
|
494
|
+
|
495
|
+
sep="\nimplements "
|
496
|
+
imp.sort{ |a,b| a <=> b}.each { |g|
|
497
|
+
write(sep)
|
498
|
+
write(g)
|
499
|
+
sep=","
|
500
|
+
}
|
501
|
+
end
|
502
|
+
|
503
|
+
#Adds a constructor with paramter
|
504
|
+
#
|
505
|
+
#NOTE:
|
506
|
+
#* EXPERIMENTAL
|
507
|
+
#
|
508
|
+
#TODO: associations, et filtrer attributs static
|
509
|
+
def java_writeConstructors
|
510
|
+
write(" public #{java_Name}() {\n")
|
511
|
+
write(" }\n")
|
512
|
+
#TODO: associations ??, filtrer static
|
513
|
+
if (!uml_ownedAttribute.empty?)
|
514
|
+
parameters = ""
|
515
|
+
uml_ownedAttribute.each { |o|
|
516
|
+
if o.umlx_isAttribute?
|
517
|
+
parameters << ", "
|
518
|
+
parameters << o.java_propertyRoleType.to_s
|
519
|
+
parameters << " "
|
520
|
+
parameters << o.java_NameProperty
|
521
|
+
end
|
522
|
+
}
|
523
|
+
if (!parameters.empty?)
|
524
|
+
write("\n")
|
525
|
+
parameters = parameters.slice(1, parameters.length)
|
526
|
+
write(" public #{java_Name}(#{parameters}) {\n")
|
527
|
+
uml_ownedAttribute.each { |o|
|
528
|
+
if o.umlx_isAttribute?
|
529
|
+
write(" set#{o.java_NameBean}(#{o.java_NameProperty});\n")
|
530
|
+
end
|
531
|
+
}
|
532
|
+
write(" }\n")
|
533
|
+
end
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|
537
|
+
|
538
|
+
module Muml_Classifier
|
539
|
+
#true if this classifier is transient
|
540
|
+
rdf_safe_attr_reader_many :java_isTransient
|
541
|
+
rdf_safe_attr_reader_many :db_isTransient
|
542
|
+
rdf_safe_attr_reader_many :db_isDAO
|
543
|
+
|
544
|
+
|
545
|
+
#Returns the full java file name for this element
|
546
|
+
# (Uses: Java_FilePath and java_Name.)
|
547
|
+
#Example:
|
548
|
+
#* build/package1/package2/NomDeLaClasse.java
|
549
|
+
def java_FileName
|
550
|
+
return "#{java_FilePath}#{java_Name}.java"
|
551
|
+
end
|
552
|
+
|
553
|
+
#Opens java_FileName for writing
|
554
|
+
#
|
555
|
+
#Example usage:
|
556
|
+
#java_openOutStream {
|
557
|
+
# write ("this text goes in java file")
|
558
|
+
# }
|
559
|
+
def java_openOutStream(&block)
|
560
|
+
mtk_writeSession(java_FileName) {
|
561
|
+
yield
|
562
|
+
if (context[:protectedReverse].protectedMode?)
|
563
|
+
write <<NOTICE
|
564
|
+
\/\/**********************************************************************
|
565
|
+
\/\/** This file is in REVERSE MODE. Text between tags will be saved
|
566
|
+
\/\/** upon next generation if reverse="yes"
|
567
|
+
\/\/** Element between tags are not stored in model, so this file should
|
568
|
+
\/\/** manage in a version management tool.#{%{
|
569
|
+
/\/\**
|
570
|
+
/\/\** This file was generated with option --skipNoReverseMarker
|
571
|
+
\/\/** Please set --no-skipNoReverseMarker if you wish to add a
|
572
|
+
\/\/** reverse="yes" section.} if context[:skipNoReverseMarker] }
|
573
|
+
\/\/**********************************************************************
|
574
|
+
\/\/** Generated with ontoMDE (ORANGE-FT/RD/BIZZ/CIL/SAM 2006-2007)
|
575
|
+
\/\/**********************************************************************
|
576
|
+
NOTICE
|
577
|
+
|
578
|
+
|
579
|
+
else
|
580
|
+
write <<NOTICE
|
581
|
+
\/\/**********************************************************************
|
582
|
+
\/\/** This file is in NOREVERSE MODE and was totaly generated from
|
583
|
+
/\/\** model informations.
|
584
|
+
/\/\** It is not mandatory to use a
|
585
|
+
/\/\** version management tool for this file
|
586
|
+
\/\/**********************************************************************
|
587
|
+
\/\/** Generated with ontoMDE (ORANGE-FT/RD/BIZZ/CIL/SAM 2006-2007
|
588
|
+
\/\/**********************************************************************
|
589
|
+
NOTICE
|
590
|
+
end
|
591
|
+
}
|
592
|
+
end
|
593
|
+
|
594
|
+
#opens java file for writing with java_openOutStream and calls java_write
|
595
|
+
def java_generate
|
596
|
+
return if @java_already_generated
|
597
|
+
return if java_ignoreMe?
|
598
|
+
|
599
|
+
return unless self.umlx_owner_one.kind_of?(Muml_Package)
|
600
|
+
@java_already_generated=true
|
601
|
+
|
602
|
+
java_openOutStream {
|
603
|
+
mtk_context(:innerClass=> false,
|
604
|
+
:java_interface => kind_of?(Muml_Interface)) {
|
605
|
+
java_write
|
606
|
+
}
|
607
|
+
}
|
608
|
+
end
|
609
|
+
|
610
|
+
# write java code for class.
|
611
|
+
# (Uses java_writeClassHeader, java_writeClassBody)
|
612
|
+
# NOTE
|
613
|
+
# * also used for inner classes
|
614
|
+
def java_write
|
615
|
+
java_writeClassHeader {
|
616
|
+
java_writeClassBody
|
617
|
+
}
|
618
|
+
end
|
619
|
+
|
620
|
+
# write java header.
|
621
|
+
# (Uses java_writePackageDeclaration, java_writeImports)
|
622
|
+
#Exemple:
|
623
|
+
# package pack1;
|
624
|
+
# import xyz;
|
625
|
+
def java_writeClassHeader(&block)
|
626
|
+
return if context[:innerClass]
|
627
|
+
java_writePackageDeclaration {
|
628
|
+
java_writeImports
|
629
|
+
yield
|
630
|
+
}
|
631
|
+
end
|
632
|
+
|
633
|
+
#java custom code overide to be
|
634
|
+
#inserted in custom code section
|
635
|
+
rdf_safe_attr_reader_many :java_customCode
|
636
|
+
|
637
|
+
# write class body.
|
638
|
+
# (Uses java_writeClassComment, java_writeClassModifiers, java_writeMetaClassName, java_writeExtends, java_writeImplements, java_writeDeclarationSpecificOnBegin, java_writeAttributes, java_writeConstructors, java_writeOperations, java_writeDeclarationSpecificOnEnd)
|
639
|
+
def java_writeClassBody
|
640
|
+
java_writeClassComment
|
641
|
+
java_writeJavadoc
|
642
|
+
java_writeAnnotation
|
643
|
+
java_writeClassModifiers
|
644
|
+
java_writeMetaClassName
|
645
|
+
java_writeExtends
|
646
|
+
java_writeImplements # class seulement
|
647
|
+
write("{\n")
|
648
|
+
java_writeCustomCode
|
649
|
+
|
650
|
+
java_writeDeclarationSpecificOnBegin
|
651
|
+
java_writeAttributes
|
652
|
+
write("\n\n")
|
653
|
+
#java_writeConstructors
|
654
|
+
write("\n\n")
|
655
|
+
java_writeOperations
|
656
|
+
java_writeDeclarationSpecificOnEnd
|
657
|
+
|
658
|
+
mtk_context(:innerClass=>true) {
|
659
|
+
uml_nestedClassifier.each { |c|
|
660
|
+
c.java_write
|
661
|
+
}
|
662
|
+
}
|
663
|
+
write("}\n")
|
664
|
+
end
|
665
|
+
|
666
|
+
#add add a custom code zone
|
667
|
+
#that is usefull for out of model code.
|
668
|
+
def java_writeCustomCode
|
669
|
+
mtk_protected(Mrdf_Resource::NOREVERSE,"custom_code") {
|
670
|
+
write !java_customCode.empty? ? java_customCode : <<END
|
671
|
+
// ***********************************************
|
672
|
+
// This area is provided to insert special code
|
673
|
+
// that cannot be handled by generator.
|
674
|
+
// Please, don't use custom method to avoid
|
675
|
+
// keeping source models up to date.
|
676
|
+
// ***********************************************
|
677
|
+
END
|
678
|
+
}
|
679
|
+
end
|
680
|
+
|
681
|
+
#Does nothing.
|
682
|
+
def java_writeClassComment
|
683
|
+
end
|
684
|
+
|
685
|
+
#Does nothing.
|
686
|
+
def java_writeDeclarationSpecificOnBegin
|
687
|
+
end
|
688
|
+
|
689
|
+
#Does nothing.
|
690
|
+
def java_writeDeclarationSpecificOnEnd
|
691
|
+
end
|
692
|
+
|
693
|
+
#Does nothing.
|
694
|
+
def java_writeConstructors
|
695
|
+
end
|
696
|
+
|
697
|
+
#write java package declaration
|
698
|
+
# (Uses java_qualifiedName)
|
699
|
+
#
|
700
|
+
#Example:
|
701
|
+
#* package aPackage;
|
702
|
+
#* package aPackage.aPackage2;
|
703
|
+
#* //package --none--
|
704
|
+
def java_writePackageDeclaration(&block)
|
705
|
+
p = umlx_package
|
706
|
+
if p.nil?
|
707
|
+
write("//package --none--;\n")
|
708
|
+
else
|
709
|
+
write("package #{p.java_qualifiedName};\n")
|
710
|
+
end
|
711
|
+
yield
|
712
|
+
end
|
713
|
+
|
714
|
+
#write java extends instructions is necessary
|
715
|
+
# (Uses java_qualifiedName)
|
716
|
+
#
|
717
|
+
#Example:
|
718
|
+
# extends Class2,Class3
|
719
|
+
def java_writeExtends
|
720
|
+
ext=Set.new
|
721
|
+
nbrInterface=0;
|
722
|
+
|
723
|
+
uml_generalization.each { |g|
|
724
|
+
nbrInterface+=1
|
725
|
+
if (nbrInterface>1) && !kind_of?(Muml_Interface)
|
726
|
+
write("\n/*TODO: UML model defines multiple inheritance (#{g.uml_general_one.java_qualifiedName})*/")
|
727
|
+
else
|
728
|
+
ext.add(g.uml_general_one.java_qualifiedName)
|
729
|
+
end
|
730
|
+
}
|
731
|
+
java_extends.each { |g|
|
732
|
+
nbrInterface+=1
|
733
|
+
if nbrInterface>1
|
734
|
+
write("\n/*TODO: UML model defines multiple inheritance (#{g})*/")
|
735
|
+
else
|
736
|
+
ext.add(g)
|
737
|
+
end
|
738
|
+
}
|
739
|
+
sep="\nextends "
|
740
|
+
ext.sort{ |a,b| a <=> b}.each { |g|
|
741
|
+
write(sep)
|
742
|
+
write(g)
|
743
|
+
sep=","
|
744
|
+
}
|
745
|
+
|
746
|
+
end
|
747
|
+
|
748
|
+
# if true, generator will compute depencies and add imports
|
749
|
+
# NOTE !!
|
750
|
+
# This feature was added for derived generators.
|
751
|
+
# It's use is **not** recommended for **java**.
|
752
|
+
# Problems will occur if model manipulate classes
|
753
|
+
# such as java.sql.Date and java.lang.Date simultaneously.
|
754
|
+
JAVA_IMPORT_COMPUTED_DEPENDENCIES=false
|
755
|
+
|
756
|
+
#write import instructions
|
757
|
+
#
|
758
|
+
#NOTE:
|
759
|
+
# The generator always uses qualified names, thus imports are not used by the generator.
|
760
|
+
# Using short names leads to name clash. (different Date class, ...)
|
761
|
+
#
|
762
|
+
# Letting eclipse handle imports is a the best solution.
|
763
|
+
#
|
764
|
+
# Eclipse offers a highly convenient organize imports feature.
|
765
|
+
# Developer should generate java code squeleton and fill it with their code eventually
|
766
|
+
# using ECLIPSE organize import features.
|
767
|
+
def java_writeImports
|
768
|
+
setOfImport=Set.new
|
769
|
+
java_import.each { |imp|
|
770
|
+
setOfImport<< imp
|
771
|
+
}
|
772
|
+
JAVA_DEFAULT_IMPORTS.each { |c|
|
773
|
+
setOfImport<< c
|
774
|
+
}
|
775
|
+
if(JAVA_IMPORT_COMPUTED_DEPENDENCIES)
|
776
|
+
umlx_computeDirectDepencies().each { |c|
|
777
|
+
m=c.java_qualifiedName
|
778
|
+
#Concrete type may come from a datatype mapping definition and be either a class or a language datatype.
|
779
|
+
next unless m.index(".")
|
780
|
+
setOfImport<< m
|
781
|
+
}
|
782
|
+
end
|
783
|
+
|
784
|
+
if (setOfImport.empty?)
|
785
|
+
# adds a useless import so eclipse
|
786
|
+
# will place imports in the right area (between ontomde reverse marquers)
|
787
|
+
# when using "organize import" eclipse feature.
|
788
|
+
if umlx_owner_one.kind_of?(Muml_Model)
|
789
|
+
#import of class in root package is invalid
|
790
|
+
setOfImport<<"java.lang.Object"
|
791
|
+
else
|
792
|
+
#we import something
|
793
|
+
setOfImport<< self.java_qualifiedName;
|
794
|
+
end
|
795
|
+
end
|
796
|
+
|
797
|
+
mtk_protected(Mrdf_Resource::NOREVERSE,"imports") {
|
798
|
+
setOfImport.sort { |a,b| a <=> b}.each {|imp|
|
799
|
+
write("import #{imp};\n");
|
800
|
+
}
|
801
|
+
}
|
802
|
+
end
|
803
|
+
|
804
|
+
#default java imports
|
805
|
+
JAVA_DEFAULT_IMPORTS=[ ];
|
806
|
+
|
807
|
+
#iterate java_write on operations
|
808
|
+
def java_writeOperations
|
809
|
+
#sort has been added because ownedOperation order is random
|
810
|
+
#which is cause false change detection on versionned file
|
811
|
+
uml_ownedOperation.sort { |a,b| a.java_Name.to_s <=> b.java_Name.to_s }.each { |o| o.java_write}
|
812
|
+
end
|
813
|
+
|
814
|
+
#iterate java_write on attributes
|
815
|
+
#
|
816
|
+
#NOTE
|
817
|
+
#* no attribute is generated for an interface
|
818
|
+
#* getter/setter// are not handled here (see java_transform!).
|
819
|
+
def java_writeAttributes
|
820
|
+
return if kind_of?(Muml_Interface)
|
821
|
+
#sort has been added because ownedAttribute order is random
|
822
|
+
#which is cause false change detection on versionned file
|
823
|
+
uml_ownedAttribute.sort { |a,b| a.java_Name.to_s <=> b.java_Name.to_s }.each { |o| o.java_write}
|
824
|
+
end
|
825
|
+
end
|
826
|
+
|
827
|
+
module Muml_Stereotype_Create
|
828
|
+
def java_write
|
829
|
+
write("\n")
|
830
|
+
java_writeAnnotation
|
831
|
+
java_writeMethodModifiers
|
832
|
+
|
833
|
+
#write("#{uml_class_one.java_Name}")
|
834
|
+
write("#{uml_ownedOperation_inv_one.java_Name}")
|
835
|
+
|
836
|
+
java_writeMethodParameters
|
837
|
+
java_writeMethodThrows
|
838
|
+
java_writeMethodBody
|
839
|
+
end
|
840
|
+
end
|
841
|
+
|
842
|
+
|
843
|
+
|
844
|
+
module Muml_Operation
|
845
|
+
#write java operation skeleton.
|
846
|
+
# (Uses java_writeMethodModifiers, java_writeMethodReturnType, java_writeMethodParameters, java_writeMethodThrows, java_writeMethodBody)
|
847
|
+
def java_write
|
848
|
+
write("\n")
|
849
|
+
java_writeJavadoc
|
850
|
+
java_writeAnnotation
|
851
|
+
java_writeMethodModifiers
|
852
|
+
|
853
|
+
if(umlx_isConstructor?)
|
854
|
+
write("#{umlx_class_one.java_Name}")
|
855
|
+
else
|
856
|
+
java_writeMethodReturnType
|
857
|
+
write("#{java_Name}")
|
858
|
+
end
|
859
|
+
java_writeMethodParameters
|
860
|
+
java_writeMethodThrows
|
861
|
+
java_writeMethodBody
|
862
|
+
end
|
863
|
+
|
864
|
+
#write java method modifiers.
|
865
|
+
# (Uses java_writeAbstract, java_visibilityModifiers, java_writeStaticModifiers)
|
866
|
+
# Visibility is not generated for interfaces (to make checkstyle happy)
|
867
|
+
#Example:
|
868
|
+
#* abstract public
|
869
|
+
#* public static
|
870
|
+
def java_writeMethodModifiers
|
871
|
+
|
872
|
+
|
873
|
+
if !umlx_class_one.kind_of?(Muml_Interface)
|
874
|
+
uml_visibility.each { |v|
|
875
|
+
write(v.java_visibilityModifiers)
|
876
|
+
}
|
877
|
+
end
|
878
|
+
java_writeStaticModifier
|
879
|
+
java_writeAbstract
|
880
|
+
write "synchronized "if java_isSynchronised?
|
881
|
+
|
882
|
+
#java_writeModifiers
|
883
|
+
#abstract synchronized ...
|
884
|
+
#TODO uml_classifier_isAbstract
|
885
|
+
end
|
886
|
+
|
887
|
+
#write abstract keyword if necessary.
|
888
|
+
def java_writeAbstract
|
889
|
+
write("abstract ") if uml_isAbstract?
|
890
|
+
end
|
891
|
+
|
892
|
+
#write method return type
|
893
|
+
# (Uses java_writeParameterType)
|
894
|
+
def java_writeMethodReturnType
|
895
|
+
java_writeParameterType(umlx_returnResult_one0)
|
896
|
+
end
|
897
|
+
|
898
|
+
#write java type parameter (without the name)
|
899
|
+
#
|
900
|
+
#Example:
|
901
|
+
#* void
|
902
|
+
#* int
|
903
|
+
#* pack1.Class1
|
904
|
+
def java_writeParameterType(fp)
|
905
|
+
if (fp.nil?)
|
906
|
+
write("void ")
|
907
|
+
else
|
908
|
+
fp.java_write
|
909
|
+
#uml_isException (!! a ne pas confondre avec une exception)
|
910
|
+
#uml_isOrdered
|
911
|
+
#uml_isStream
|
912
|
+
#uml_isUnique
|
913
|
+
end
|
914
|
+
end
|
915
|
+
#Write the body of a java method.
|
916
|
+
#
|
917
|
+
#NOTE:
|
918
|
+
#* The default generated operation throws a RuntimeException
|
919
|
+
#* mtk_protected is used to allow inline java code modification (with Eclipse)
|
920
|
+
def java_writeMethodBody
|
921
|
+
if uml_isAbstract? || context[:java_interface]
|
922
|
+
write(";\n")
|
923
|
+
else
|
924
|
+
write("{");
|
925
|
+
mtk_protected(Mrdf_Resource::NOREVERSE) {
|
926
|
+
if ! java_code_one0.nil?
|
927
|
+
write java_code
|
928
|
+
else
|
929
|
+
java_writeMethodBodyNotImplemented
|
930
|
+
end
|
931
|
+
}
|
932
|
+
write("}\n");
|
933
|
+
end
|
934
|
+
end
|
935
|
+
|
936
|
+
#writes default code for a method not implemented
|
937
|
+
def java_writeMethodBodyNotImplemented
|
938
|
+
write <<END
|
939
|
+
//TODO: implement method body
|
940
|
+
throw new java.lang.RuntimeException("[operation \\"#{java_Name}\\"not implemented]");
|
941
|
+
END
|
942
|
+
end
|
943
|
+
|
944
|
+
# write method throw clause.
|
945
|
+
# (Uses java_qualifiedName )
|
946
|
+
#
|
947
|
+
# Example:
|
948
|
+
# * throws java.lang.Exception
|
949
|
+
def java_writeMethodThrows
|
950
|
+
sep=" throws "
|
951
|
+
|
952
|
+
uml_raisedException.each { |exception|
|
953
|
+
write(sep);
|
954
|
+
write(exception.java_qualifiedName)
|
955
|
+
sep=","
|
956
|
+
}
|
957
|
+
end
|
958
|
+
|
959
|
+
#write method parameters
|
960
|
+
#
|
961
|
+
#Example:
|
962
|
+
#* ()
|
963
|
+
#* (int x)
|
964
|
+
#* (pack1.Class1 xyz, String z)
|
965
|
+
def java_writeMethodParameters
|
966
|
+
write("(")
|
967
|
+
sep=""
|
968
|
+
uml_ownedParameter.each { |op|
|
969
|
+
next if op.uml_direction_one.isReturn?
|
970
|
+
write(sep)
|
971
|
+
sep=","
|
972
|
+
op.java_write
|
973
|
+
}
|
974
|
+
write(")")
|
975
|
+
end
|
976
|
+
end
|
977
|
+
|
978
|
+
module Muml_Property
|
979
|
+
|
980
|
+
#Methode vide
|
981
|
+
def java_writePropertyComment
|
982
|
+
end
|
983
|
+
#Methode vide
|
984
|
+
def java_writeGetterComment
|
985
|
+
end
|
986
|
+
#Methode vide
|
987
|
+
def java_writeSetterComment
|
988
|
+
end
|
989
|
+
|
990
|
+
#write java attribute variable
|
991
|
+
# (Uses java_writePropertyComment, java_writePropertyModifiers ,java_propertyRoleType,java_NameProperty)
|
992
|
+
#
|
993
|
+
#NOTE:
|
994
|
+
#* getter/setter/... methods are handled by model transformation
|
995
|
+
def java_write
|
996
|
+
if !uml_isDerived?
|
997
|
+
java_writePropertyComment
|
998
|
+
java_writeAnnotation
|
999
|
+
write(" ");
|
1000
|
+
java_writePropertyModifiers
|
1001
|
+
write("#{java_propertyAssociationType}")
|
1002
|
+
write(" #{java_NameProperty}")
|
1003
|
+
|
1004
|
+
if !java_code.empty?
|
1005
|
+
write"= #{java_code}"
|
1006
|
+
elsif(context[:java_generateSetAttributeInitializer])
|
1007
|
+
if (!umlx_upperValueIsOne?) && uml_qualifier.empty? && java_use_Arrays?
|
1008
|
+
write("= new ");
|
1009
|
+
write(uml_type_one.java_qualifiedName)
|
1010
|
+
write("[1]")
|
1011
|
+
elsif (!umlx_upperValueIsOne?) && uml_qualifier.empty?
|
1012
|
+
write("= new ");
|
1013
|
+
write(java_propertyAssociationConcreteType)
|
1014
|
+
write("()")
|
1015
|
+
elsif umlx_upperValueIsOne? && !uml_qualifier.empty?
|
1016
|
+
write("= new ");
|
1017
|
+
write(java_propertyAssociationConcreteType)
|
1018
|
+
write("()")
|
1019
|
+
elsif !umlx_upperValueIsOne? && !uml_qualifier.empty?
|
1020
|
+
#write("= new ");
|
1021
|
+
#write(java_propertyAssociationConcreteType)
|
1022
|
+
#write("()")
|
1023
|
+
end
|
1024
|
+
end
|
1025
|
+
write(";\n")
|
1026
|
+
end
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
#write java modifiers if needed (public, static, ...)
|
1030
|
+
# (Uses java_visibilityModifiers, java_writeStaticModifier)
|
1031
|
+
# example: private static final transient long
|
1032
|
+
def java_writePropertyModifiers
|
1033
|
+
uml_visibility.each { |v|
|
1034
|
+
write(v.java_visibilityModifiers)
|
1035
|
+
}
|
1036
|
+
java_writeStaticModifier
|
1037
|
+
java_writeFinalModifier
|
1038
|
+
java_writeTransient
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
def java_writeFinalModifier
|
1042
|
+
return unless java_isFinal?
|
1043
|
+
write "final "
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
#write java transient modifier if needed.
|
1047
|
+
def java_writeTransient
|
1048
|
+
return unless java_isTransient?
|
1049
|
+
write("transient ")
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
module Muml_Parameter
|
1055
|
+
#write java parameter declaration
|
1056
|
+
# (Uses java_propertyRoleType, java_Name)
|
1057
|
+
# parameter is declared final if direction is in (not out, not inOut)
|
1058
|
+
#Example:
|
1059
|
+
#* int x
|
1060
|
+
#* final int x
|
1061
|
+
#* String z
|
1062
|
+
def java_write
|
1063
|
+
write("final ") if uml_direction_one.isIn? # the best we can do with java
|
1064
|
+
write("#{java_propertyAssociationType} ")
|
1065
|
+
#write(" /* #{uml_lowerValue}..#{uml_upperValue}*/ ")
|
1066
|
+
write(" #{java_Name}") unless uml_direction_one.isReturn?
|
1067
|
+
end
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
module Muml_TypedElement
|
1071
|
+
rdf_safe_attr_reader_many :java_use_Arrays
|
1072
|
+
|
1073
|
+
#return java property type.
|
1074
|
+
# (Uses java_qualifiedName)
|
1075
|
+
#
|
1076
|
+
#NOTE
|
1077
|
+
#* used for UML Parameter and UML Property
|
1078
|
+
#* return "int" and a TODO comment if uml_type is undefined.
|
1079
|
+
#
|
1080
|
+
#Example:
|
1081
|
+
#* String
|
1082
|
+
#* Set<String>
|
1083
|
+
def java_propertyRoleConcreteType
|
1084
|
+
return java_getCollectionMapping.addCollectionImplem(
|
1085
|
+
uml_type.empty? ? "Integer /* TODO: FIX:undefined type in uml model */ " : uml_type_one.java_qualifiedName )
|
1086
|
+
end
|
1087
|
+
|
1088
|
+
def java_propertyRoleType
|
1089
|
+
return java_getCollectionMapping.addCollectionInterface(
|
1090
|
+
uml_type.empty? ? "Integer /* TODO: FIX:undefined type in uml model */ " : uml_type_one.java_qualifiedName )
|
1091
|
+
end
|
1092
|
+
|
1093
|
+
def java_propertyAssociationConcreteType
|
1094
|
+
return java_propertyRoleConcreteType if uml_qualifier.empty?
|
1095
|
+
j="java.util.Hashtable<"
|
1096
|
+
sep_next=""
|
1097
|
+
uml_qualifier.each { |key|
|
1098
|
+
j=j+sep_next+key.java_propertyRoleConcreteType
|
1099
|
+
sep_next=","
|
1100
|
+
}
|
1101
|
+
j=j+","+java_propertyRoleConcreteType+">"
|
1102
|
+
return j
|
1103
|
+
end
|
1104
|
+
def java_propertyAssociationType
|
1105
|
+
return java_propertyRoleType if uml_qualifier.empty?
|
1106
|
+
j="java.util.Hashtable<"
|
1107
|
+
sep_next=""
|
1108
|
+
uml_qualifier.each { |key|
|
1109
|
+
j=j+sep_next+key.java_propertyRoleType
|
1110
|
+
sep_next=","
|
1111
|
+
}
|
1112
|
+
j=j+","+java_propertyRoleType+">"
|
1113
|
+
return j
|
1114
|
+
end
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
module Muml_Namespace
|
1118
|
+
#Returns this element java qualified name
|
1119
|
+
#
|
1120
|
+
#Example:
|
1121
|
+
# package1.package2.AClassClasse
|
1122
|
+
# AClassInRootDefaultPackage
|
1123
|
+
# package1.package2
|
1124
|
+
def java_qualifiedName
|
1125
|
+
r=sep=""
|
1126
|
+
umlx_hierarchy.each { |n|
|
1127
|
+
r+=sep
|
1128
|
+
r+=n.java_Name
|
1129
|
+
sep="."
|
1130
|
+
}
|
1131
|
+
return r
|
1132
|
+
end
|
1133
|
+
end
|
1134
|
+
|
1135
|
+
module Muml_DataType
|
1136
|
+
#Predefined UML datatype to Java type mapping.
|
1137
|
+
#Note: A string is used for Calendar.
|
1138
|
+
#UML_TO_JAVA_PRIMITIVE_TYPE_MAPPING={"byte"=>"byte","short"=>"short","long"=>"long","Boolean"=>"boolean","boolean"=>"boolean","int"=>"int","integer"=>"int","Integer"=>"int", "String"=>"String","string"=>"String","date"=>"java.util.Date","double"=>"double","char"=>"char","Calendar"=>"String","TimeStamp"=>"java.util.Date"}
|
1139
|
+
|
1140
|
+
# returns datatype qualified name.
|
1141
|
+
#
|
1142
|
+
# NOTE:
|
1143
|
+
# * A predefined mapping is defined UML_TO_JAVA_PRIMTIVE_TYPE_MAPPING
|
1144
|
+
# * MagicDraw handles primtive types as DataType
|
1145
|
+
# * RSM handles primtive types as PrimitiveType
|
1146
|
+
def java_qualifiedName
|
1147
|
+
return super if kind_of?(Muml_Enumeration)
|
1148
|
+
|
1149
|
+
return JavaMapping.instance.getTemplate(self).getJavaType
|
1150
|
+
|
1151
|
+
|
1152
|
+
ot=uml_name_one
|
1153
|
+
mt=::Muml_PrimitiveType::UML_TO_JAVA_PRIMITIVE_TYPE_MAPPING[ot]
|
1154
|
+
return mt unless mt.nil? || mt.to_s==""
|
1155
|
+
#avoid multiple messages
|
1156
|
+
::Muml_PrimitiveType::UML_TO_JAVA_PRIMITIVE_TYPE_MAPPING[ot]="String"
|
1157
|
+
log.error %{
|
1158
|
+
WARN: A default java mapping has been created for DataType #{ot}
|
1159
|
+
HELP:
|
1160
|
+
HELP: To declare a new mapping, create a new entry as shown bellow:
|
1161
|
+
HELP: module Muml_DataType
|
1162
|
+
HELP: UML_TO_JAVA_PRIMITIVE_TYPE_MAPPING["#{ot}"]="your target java type"
|
1163
|
+
HELP: end
|
1164
|
+
} #(not useful here) unless log_already_displayed?("#{rdf_uri}__datatype")
|
1165
|
+
return java_qualifiedName # retry
|
1166
|
+
end
|
1167
|
+
end
|
1168
|
+
|
1169
|
+
module Mrdf_Resource
|
1170
|
+
#return true if java generator should totaly ignore this element.
|
1171
|
+
#
|
1172
|
+
#NOTE:
|
1173
|
+
#* Default implementation returns false
|
1174
|
+
def java_ignoreMe?
|
1175
|
+
return false
|
1176
|
+
end
|
1177
|
+
end
|
1178
|
+
|
1179
|
+
#module Muml_ClassifierTemplateParameter
|
1180
|
+
# def umlx_hierarchy
|
1181
|
+
# return nil
|
1182
|
+
# end
|
1183
|
+
# def java_ignoreMe?
|
1184
|
+
# return true
|
1185
|
+
# end
|
1186
|
+
#end
|
1187
|
+
|
1188
|
+
module Muml_Namespace
|
1189
|
+
#List of namespaces to be ignored by generator.
|
1190
|
+
#
|
1191
|
+
#NOTE:
|
1192
|
+
#* user may add its own item int the list.
|
1193
|
+
#* list may contain package or class qualified names.
|
1194
|
+
#
|
1195
|
+
#EXAMPLE:
|
1196
|
+
#* "org.xyz" will ignore every item under org.xyz
|
1197
|
+
#* "org.xyz.ClassZ" will ignore only ClassZ
|
1198
|
+
JAVA_IGNORE_NAMESPACE=["java.", "javax.", "xmda.bpm.api", "ontomde.bpm", "xmda.common","org.acegi"]
|
1199
|
+
|
1200
|
+
#return true if java generator should totaly ignore this element.
|
1201
|
+
#
|
1202
|
+
#NOTE:
|
1203
|
+
#* returns true if this class name is in JAVA_IGNORE_ROOT_PACKAGE_NAME
|
1204
|
+
def java_ignoreMe?(ignoreExternal=true)
|
1205
|
+
#puts "ignore=#{self.class} #{self.uml_name}"
|
1206
|
+
qn=java_qualifiedName
|
1207
|
+
return true if umlx_external? && ignoreExternal
|
1208
|
+
JAVA_IGNORE_NAMESPACE.each { |ns|
|
1209
|
+
return true if qn.index(ns)==0
|
1210
|
+
}
|
1211
|
+
return false;
|
1212
|
+
end
|
1213
|
+
end
|
1214
|
+
module Muml_Stereotype
|
1215
|
+
#return true if java generator should totaly ignore this element.
|
1216
|
+
#
|
1217
|
+
#NOTE:
|
1218
|
+
#* Always returns true
|
1219
|
+
def java_ignoreMe?
|
1220
|
+
return true;
|
1221
|
+
end
|
1222
|
+
end
|
1223
|
+
|
1224
|
+
module Muml_Interface
|
1225
|
+
def java_makeSerializable!
|
1226
|
+
#java_implements_add("java.io.Serializable");
|
1227
|
+
s=umlx_getOrCreateClass("java.io.Serializable")
|
1228
|
+
umlx_createAndAddGeneralization(s)
|
1229
|
+
end
|
1230
|
+
end
|
1231
|
+
module Muml_Class
|
1232
|
+
|
1233
|
+
#Mark this java class as serializable.
|
1234
|
+
#* adds implements java.io.Serializable
|
1235
|
+
#* adds serialVersionUID variable
|
1236
|
+
#Example:
|
1237
|
+
# private static final long serialVersionUID = 1L;
|
1238
|
+
def java_makeSerializable!
|
1239
|
+
#java_implements_add("java.io.Serializable");
|
1240
|
+
s=umlx_getOrCreateClass("java.io.Serializable")
|
1241
|
+
umlx_createAndAddImplementation(s)
|
1242
|
+
|
1243
|
+
p=umlx_createAndAddProperty(rdf_uri+"_serialVersionUID","serialVersionUID");
|
1244
|
+
p.uml_visibility=::Cuml_VisibilityKind::Private
|
1245
|
+
p.uml_isStatic=RDF_TRUE
|
1246
|
+
p.java_isFinal=RDF_TRUE
|
1247
|
+
p.java_isTransient=RDF_TRUE
|
1248
|
+
p.uml_type=umlx_dataType_long
|
1249
|
+
p.java_code="1L"
|
1250
|
+
p.java_noAccessors=RDF_TRUE
|
1251
|
+
end
|
1252
|
+
end
|