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