Module: Muml_Operation

Includes:
Mjava_Annotation, Mxsd_Annotation
Defined in:
lib/ontomde-java/java/groovy.rb,
lib/ontomde-java/java/xsd.rb,
lib/ontomde-java/flex/main.rb,
lib/ontomde-java/java/java.rb,
lib/ontomde-java/vmware/vso.rb,
lib/ontomde-java/jpa/mapping.rb,
lib/ontomde-java/struts/form.rb,
lib/ontomde-java/java/javadoc.rb,
lib/ontomde-java/java/security.rb,
lib/ontomde-java/struts/jsp_edit.rb,
lib/ontomde-java/java/operationAsClass.rb,
lib/ontomde-java/jpa/simulationAutoImplement.rb,
lib/ontomde-java/jpdl/processOperationToClass.rb,
lib/ontomde-java/jpdl/processOperationToClass.rb

Overview

module Muml_Classifier

STRUTS_APPLY_TO_PARAM="applyTo"
STRUTS_APPLY_TO_PROP="ApplyTo"

end

Constant Summary collapse

JPA_ANNOTATE_GETTER =

true puts annotation on getter false puts annotation on attribute

false
JPA_TEST_CODE_TOP =
%{
//TODO: replace this test code by real implementation
//log.error("test method called");\n}

Instance Method Summary collapse

Methods included from Mjava_Annotation

#java_writeAnnotation, #java_writeMdatkAnno, #java_writeParamAnnotation

Methods included from Mxsd_Annotation

#xsd_writeAnnotation

Instance Method Details

#as_NameObject

Hack



120
121
122
123
124
125
126
127
128
129
# File 'lib/ontomde-java/flex/main.rb', line 120

def as_Name
	s=super
	if  !self.as_getter_property.empty?
		return "get #{s[3,s.length]}"
	end
	if  !self.as_setter_property.empty?
		return "set #{s[3,s.length]}"
	end
	return s
end

#as_writeObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/ontomde-java/flex/main.rb', line 131

def as_write
	#TODO: decide what to do with functions in actionscript
	#write("\/\/IGNORED: function #{as_Name}\n")
	#return

	write("\n")
	as_writeAnnotation
	as_writeMethodModifiers
	write("function ");

	if umlx_isConstructor?
		write("#{umlx_class_one.as_Name}")
	else
		write("#{as_Name}")
	end
	as_writeMethodParameters
	as_writeMethodThrows


	as_writeMethodReturnType unless umlx_isConstructor?

	as_writeMethodBody
end

#as_writeMethodBodyNotImplementedObject

writes default code for a method not implemented



175
176
177
178
179
180
181
182
# File 'lib/ontomde-java/flex/main.rb', line 175

def as_writeMethodBodyNotImplemented
	write <<END
{
 //TODO: implement method body
 throw new Error("[operation \\"#{as_Name}\\"not implemented]");
}
END
end

#as_writeParameterType(fp) ⇒ Object

write java type parameter (without the name)

Example:

  • void

  • int

  • pack1.Class1



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/ontomde-java/flex/main.rb', line 161

def as_writeParameterType(fp)
	if (fp.nil?)
		# fp.write("void ");
	else
		write(" : ")
		fp.as_write
		#uml_isException (!! a ne pas confondre avec une exception)
		#uml_isOrdered
		#uml_isStream
		#uml_isUnique
	end
end

#bpm_callbackTypeObject



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/ontomde-java/jpdl/processOperationToClass.rb', line 219

def bpm_callbackType
  fp=nil
  uml_ownedParameter.each { |p|
    next if p.uml_direction_one.isReturn?
    if !fp.nil?
      log.error("Method #{self.uml_name} : Should not define Callback method with multiple parameters")
      raise Warning.new(),"Method #{self.uml_name} : Should not define Callback method with multiple parameters"
    else
      fp=p
    end

  }
  if !fp
    return "#{BPM::NullReturn}"
  else
    return "#{fp.uml_type}"
  end
end

#bpm_returnTypeObject



210
211
212
213
214
215
216
217
# File 'lib/ontomde-java/jpdl/processOperationToClass.rb', line 210

def bpm_returnType
  fp = uml_getReturnParameter
  if !fp
    return "#{BPM::NullReturn}"
  else
    return "#{fp.uml_type}"
  end
end

returns a javadoc link suitable for @see and @link.



86
87
88
89
90
91
92
93
94
95
# File 'lib/ontomde-java/java/javadoc.rb', line 86

def java_javadocLink(location=nil)
  o=umlx_owner_one
  if location==o
    #same class
    return "##{java_Name}"
  else
    #different class
    return "#{o.java_qualifiedName}##{java_Name}"
  end
end

#java_writeObject

write java operation skeleton. (Uses java_writeMethodModifiers, java_writeMethodReturnType, java_writeMethodParameters, java_writeMethodThrows, java_writeMethodBody)



1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
# File 'lib/ontomde-java/java/java.rb', line 1045

def java_write
  write("\n")
  return java_writeStaticInitializer if umlx_isConstructor? && uml_isStatic?

  java_writeJavadoc
  java_writeAnnotation
  java_writeMdatkAnno(!(uml_isAbstract? || context[:java_interface])?['javadoc','annotations','annoparam0','0']:['javadoc','annotations','annoparam0']) if context[:hasGlobalReverse]
  write("\t")
  java_writeMethodModifiers

  if( umlx_isConstructor?)
    write("#{umlx_class_one.java_Name}")
  else
    java_writeMethodReturnType
    write("#{java_Name}")
  end
  java_writeMethodParameters 
  java_writeMethodThrows 
  java_writeMethodBody
end

#java_writeAbstractObject

write abstract keyword if necessary.



1088
1089
1090
# File 'lib/ontomde-java/java/java.rb', line 1088

def java_writeAbstract
  write("abstract ") if uml_isAbstract?
end

#java_writeJavadocObject

write operation javadoc comment.



99
100
101
102
103
104
# File 'lib/ontomde-java/java/javadoc.rb', line 99

def java_writeJavadoc
  return unless context[:javadoc]
  mtk_protected(Mrdf_Resource::NOREVERSE,"javadoc",context[:hasGlobalReverse]||context[:hideJavadocReverseTag]) {
    java_writeJavadoc_internal
  }
end

#java_writeJavadoc_internalObject

internal write javadoc



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/ontomde-java/java/javadoc.rb', line 107

def java_writeJavadoc_internal
  hasDoc=false

  #	if !java_getter_property.empty? && !java_getter_property_one.uml_isDerived?
  #		"getter for property {@link #{java_getter_property_one.java_javadocLink}}".java_writeJavadoc(self)
  #	end
  #	if !java_setter_property.empty? && !java_setter_property_one.uml_isDerived?
  #		"setter for property {@link #{java_setter_property_one.java_javadocLink}}".java_writeJavadoc(self)
  #	end
  s=mtk_stss {
  p=java_getter_property_one0
  if !p.nil?
    oe=p.umlx_otherEnd
    if !oe.nil? && oe.umlx_isNavigable?
      g=oe.java_AttributeGlobalGetter_one0
      if !g.nil?
        "This property is part of a bi-navigable association {@link #{g.java_javadocLink(self)}}<br/>".java_writeJavadoc(self)
      end
    end
  end


  umlx_autoImplementedBy.each {|x|
%{@see #{x.java_javadocLink(self)}}.java_writeJavadoc(self)
  }

  if !uml_ownedComment.empty?
    #write("* @return the \n");
    uml_ownedComment.each { |comment|
      hasDoc=true
      comment.uml_body_one.java_writeJavadoc(self)
    }

  elsif !java_getter_property.empty?
    java_getter_property_one.uml_ownedComment.each { |comment|
      hasDoc=true
      comment.uml_body_one.java_writeJavadoc(self)
    }
  else
    #nop
  end
  #if(!hasDoc)
  #	"TODO: document this element in source UML model".java_writeJavadoc(self)
  #end
  
  if !java_setter_property.empty?
    hasDoc=true
    p=java_setter_property_one
    if !p.java_AttributeGlobalGetter.empty?
      "@see #{p.java_AttributeGlobalGetter_one.java_javadocLink}".java_writeJavadoc(self)
    end
  end

  }
  if(!s.nil? && !s.empty?) 
   write("\t/**\n");
   write(s)
 uml_ownedParameter.each { |p|
    c=""
    p.uml_ownedComment.each { |comment|
      c="#{c} #{comment.uml_body_one}"
    }
    c=" self-explanatory"
    #next if c.empty? &&  p.uml_direction_one.isReturn?
    "#{p.uml_direction_one.isReturn? ? %{@return}: %{@param }}#{p.java_Name unless p.uml_direction_one.isReturn?}#{c}".java_writeJavadoc(self)
  }
   write("\t */\n")
  end

end

#java_writeMethodBody(skipNotImplemented = false) ⇒ Object

Write the body of a java method.

NOTE:

  • The default generated operation throws a RuntimeException

  • mtk_protected is used to allow inline java code modification (with Eclipse)



1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
# File 'lib/ontomde-java/java/java.rb', line 1120

def java_writeMethodBody(skipNotImplemented=false)
  if uml_isAbstract? || context[:java_interface]
    write(";\n")
  else
    write(" {\n");
    mtk_protected(Mrdf_Resource::NOREVERSE,'0',context[:hasGlobalReverse]) {
      if ! java_code_one0.nil?
        write java_code
      else
        java_writeMethodBodyNotImplemented unless skipNotImplemented
      end
      write("\n")
    }
    write("\t}\n");
  end
end

#java_writeMethodBodyNotImplementedObject

writes default code for a method not implemented



1138
1139
1140
1141
1142
1143
# File 'lib/ontomde-java/java/java.rb', line 1138

def java_writeMethodBodyNotImplemented
  write <<END
\t\t//TODO: implement method body
\t\tthrow new java.lang.RuntimeException("[operation \\"#{java_Name}\\"not implemented]");
END
end

#java_writeMethodModifiersObject

write java method modifiers. (Uses java_writeAbstract, java_visibilityModifiers, java_writeStaticModifiers) Visibility is not generated for interfaces (to make checkstyle happy) Example:

  • abstract public

  • public static



1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
# File 'lib/ontomde-java/java/java.rb', line 1072

def java_writeMethodModifiers
  if !umlx_class_one.kind_of?(Muml_Interface)
    uml_visibility.each { |v|
      write(v.java_visibilityModifiers)
    }
  end
  java_writeStaticModifier
  java_writeAbstract
  write "synchronized "if java_isSynchronised?

  #java_writeModifiers
  #abstract synchronized ...
  #TODO uml_classifier_isAbstract
end

#java_writeMethodParametersObject

write method parameters

Example:

  • ()

  • (int x)

  • (pack1.Class1 xyz, String z)



1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
# File 'lib/ontomde-java/java/java.rb', line 1166

def java_writeMethodParameters
  write("(")
  sep=""
  i = 0
  uml_ownedParameter.each { |op|
    next if op.uml_direction_one.isReturn?
    write(sep)
    sep=","
    op.java_writeParamAnnotation i.to_s
    op.java_write
    i = i + 1
  }
  write(")")
end

#java_writeMethodReturnTypeObject

write method return type (Uses java_writeParameterType)



1094
1095
1096
# File 'lib/ontomde-java/java/java.rb', line 1094

def java_writeMethodReturnType
  java_writeParameterType(umlx_returnResult_one0)
end

#java_writeMethodThrowsObject

write method throw clause.

(Uses java_qualifiedName )

Example:

  • throws java.lang.Exception



1150
1151
1152
1153
1154
1155
1156
1157
1158
# File 'lib/ontomde-java/java/java.rb', line 1150

def java_writeMethodThrows
  sep=" throws "

  uml_raisedException.each { |exception|
    write(sep);
    write(exception.java_qualifiedName)
    sep=","
  }
end

#java_writeOperationMapping(tab) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/ontomde-java/vmware/vso.rb', line 267

def java_writeOperationMapping(tab)
	tab2=tab.tab
	params=""
	rt=umlx_returnResult_one0
	params=%{return-type="#{rt.vso_TypeName}"} unless rt.nil?
	before=%{#{tab}<method script-name="#{java_Name}" java-name="#{java_Name}"#{" " unless params.empty?}#{params}#{%{ static="true"} if uml_isStatic?}>\n} 
	after=%{#{tab}</method>\n}
	encloseWrite(before,after) {
		vso_writeJavadoc(tab2)
		vso_writeOperationParameters(tab2)
	}

end

#java_writeParameterType(fp) ⇒ Object

write java type parameter (without the name)

Example:

  • void

  • int

  • pack1.Class1



1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
# File 'lib/ontomde-java/java/java.rb', line 1104

def java_writeParameterType(fp)
  if (fp.nil?)
    write("void ")
  else
    fp.java_write
    #uml_isException (!! a ne pas confondre avec une exception)
    #uml_isOrdered
    #uml_isStream
    #uml_isUnique
  end
end

#java_writeStaticInitializerObject

writes a static initializer bloc from eclipse



1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
# File 'lib/ontomde-java/java/java.rb', line 1029

def java_writeStaticInitializer
   #java_writeJavadoc
   #java_writeAnnotation
   #java_writeMethodParameters 
   #java_writeMethodModifiers (do not want public to popup)
   java_writeStaticModifier
   #write("static ")
   #java_writeMethodThrows 
   mtk_protected(Mrdf_Resource::NOREVERSE,'static_init') {
   	java_writeMethodBody(true)
   }
end

#jpa_addPersistence!Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ontomde-java/jpa/mapping.rb', line 30

def jpa_addPersistence!
  # java_AttributeGlobalSetter
  # java_getter_property
  if java_getter_property.empty?
    return if(umlx_hasStereotype?('Create'))
    #java_annotation_add('@Transient')
    return
  end

  p=java_getter_property_one
  return unless p.jpa_isPersistent?

  if p.uml_type_one.kind_of?(Cuml_Class) && !p.uml_type_one.jpa_isPersistent?
    p.java_annotation_add('/* not persistent */')
    return
  end

  if(JPA_ANNOTATE_GETTER)
    p.jpa_addPersistenceTo!(self)
    # HACK
    p.jpa_addPersistenceTo!(p) #TODO: remove
    #p.java_annotation_add('@Transient')
  else
    p.jpa_addPersistenceTo!(p)
  end
end

#jpa_addTestImplementation!Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ontomde-java/jpa/simulationAutoImplement.rb', line 22

def jpa_addTestImplementation!
  return unless java_code.empty?
  owner=umlx_owner_one
  return if owner.kind_of?(Muml_Interface)
  return if owner.uml_isAbstract?
  #log.debug { "adding test implementation for #{self.umlx_owner_one}.#{self}" }
  fp=nil
  (uml_returnResult+uml_ownedParameter).each { |p|
    next unless p.uml_direction_one.isReturn?
    fp=p
  }
  if fp.nil?
    self.java_code=JPA_TEST_CODE_TOP
    return
  elsif fp.uml_type_one.kind_of?(Muml_DataType)
    #TODO: create test code
    return
  elsif (!fp.uml_type_one.jpa_isPersistent?) || (fp.uml_type_one.db_isTransient?) || (fp.uml_type_one.java_ignoreMe?)
    #not a persistent class
    return
  elsif fp.umlx_oneSide?
    self.java_code=%{#{JPA_TEST_CODE_TOP}\nreturn #{fp.uml_type_one.db_getFindAllCall}.isEmpty() ? null : #{fp.uml_type_one.db_getFindAllCall}.get(0);}
  elsif fp.uml_isOrdered?
    self.java_code=%{#{JPA_TEST_CODE_TOP}\nreturn #{fp.uml_type_one.db_getFindAllCall};}
  else
    self.java_code=%{
#{JPA_TEST_CODE_TOP}
#{fp.java_propertyAssociationConcreteType} ret=new #{fp.java_propertyAssociationConcreteType}();
ret.addAll(#{fp.uml_type_one.db_getFindAllCall});
return ret;}
  end
end

#js_NameObject

add _js to prevent javascript reserved name clash. example: “delete”



22
23
24
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 22

def js_Name
	return "#{java_Name}_js"
end

#uml_getReturnParameterObject



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/ontomde-java/jpdl/processOperationToClass.rb', line 196

def uml_getReturnParameter
  fp=nil
  uml_returnResult.each { |p|
    #pour RSM (non conformite de l'export)
    next unless p.uml_direction_one.isReturn?
    fp=p
  }
  uml_ownedParameter.each { |p|
    next unless p.uml_direction_one.isReturn?
    fp=p
  }
  return fp
end

#umlx_isScripted?Boolean

returns true if element is marked as scripted.

Returns:

  • (Boolean)


7
8
9
# File 'lib/ontomde-java/java/groovy.rb', line 7

def umlx_isScripted?
  return umlx_hasStereotype?("Script")
end

#umlx_isSecured?Boolean

returns true if element is marked as secured.

Returns:

  • (Boolean)


13
14
15
# File 'lib/ontomde-java/java/security.rb', line 13

def umlx_isSecured?
  return umlx_hasStereotype?("Secured")
end

#vso_writeOperationParameters(tab) ⇒ Object



280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/ontomde-java/vmware/vso.rb', line 280

def vso_writeOperationParameters(tab)
	tab2=tab.tab
	before="#{tab}<parameters>\n"
	after="#{tab}</parameters>\n"
	notEmpty=encloseWrite(before,after,true) {
		uml_ownedParameter.each { |p|
				next if p.uml_direction_one.isReturn?
				#array
				write(%{#{tab2}<parameter type="#{p.vso_TypeName}" name="#{p.java_Name}"/>\n})
		}
	}
	write("#{tab}<parameters/>\n") unless notEmpty 
end

#xsd_writeObject

write java operation skeleton. (Uses xsd_writeMethodModifiers, xsd_writeMethodReturnType, xsd_writeMethodParameters, xsd_writeMethodThrows, xsd_writeMethodBody)



993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
# File 'lib/ontomde-java/java/xsd.rb', line 993

def xsd_write
  write("\n")
  #xsd_writeJavadoc
  xsd_writeAnnotation
  xsd_writeMethodModifiers

  if(umlx_isConstructor?)
    write("#{umlx_class_one.xsd_Name}")
  else
    xsd_writeMethodReturnType
    write("#{xsd_Name}")
  end
  xsd_writeMethodParameters
  xsd_writeMethodThrows
  xsd_writeMethodBody
end

#xsd_writeAbstractObject

write abstract keyword if necessary.



1034
1035
1036
# File 'lib/ontomde-java/java/xsd.rb', line 1034

def xsd_writeAbstract
  write("abstract ") if uml_isAbstract?
end

#xsd_writeMethodBodyObject

Write the body of a java method.

NOTE:

  • The default generated operation throws a RuntimeException

  • mtk_protected is used to allow inline java code modification (with Eclipse)



1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
# File 'lib/ontomde-java/java/xsd.rb', line 1066

def xsd_writeMethodBody
  if uml_isAbstract? || context[:xsd_interface]
    write(";\n")
  else
    write("{");
    mtk_protected(Mrdf_Resource::NOREVERSE) {
      if ! xsd_code_one0.nil?
        write xsd_code
      else
        xsd_writeMethodBodyNotImplemented
      end
    }
    write("}\n");
  end
end

#xsd_writeMethodBodyNotImplementedObject

writes default code for a method not implemented



1083
1084
1085
1086
1087
1088
# File 'lib/ontomde-java/java/xsd.rb', line 1083

def xsd_writeMethodBodyNotImplemented
  write <<END
//TODO: implement method body
throw new java.lang.RuntimeException("[operation \\"#{xsd_Name}\\"not implemented]");
END
end

#xsd_writeMethodModifiersObject

write java method modifiers. (Uses xsd_writeAbstract, xsd_visibilityModifiers, xsd_writeStaticModifiers) Visibility is not generated for interfaces (to make checkstyle happy) Example:

  • abstract public

  • public static



1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
# File 'lib/ontomde-java/java/xsd.rb', line 1016

def xsd_writeMethodModifiers


  if !umlx_class_one.kind_of?(Muml_Interface)
    uml_visibility.each { |v|
      write(v.xsd_visibilityModifiers)
    }
  end
  xsd_writeStaticModifier
  xsd_writeAbstract
  write "synchronized "if xsd_isSynchronised?

  #xsd_writeModifiers
  #abstract synchronized ...
  #TODO uml_classifier_isAbstract
end

#xsd_writeMethodParametersObject

write method parameters

Example:

  • ()

  • (int x)

  • (pack1.Class1 xyz, String z)



1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
# File 'lib/ontomde-java/java/xsd.rb', line 1111

def xsd_writeMethodParameters
  write("(")
  sep=""
  uml_ownedParameter.each { |op|
    next if op.uml_direction_one.isReturn?
    write(sep)
    sep=","
    op.xsd_write
  }
  write(")")
end

#xsd_writeMethodReturnTypeObject

write method return type (Uses xsd_writeParameterType)



1040
1041
1042
# File 'lib/ontomde-java/java/xsd.rb', line 1040

def xsd_writeMethodReturnType
  xsd_writeParameterType(umlx_returnResult_one0)
end

#xsd_writeMethodThrowsObject

write method throw clause.

(Uses xsd_qualifiedName )

Example:

  • throws java.lang.Exception



1095
1096
1097
1098
1099
1100
1101
1102
1103
# File 'lib/ontomde-java/java/xsd.rb', line 1095

def xsd_writeMethodThrows
  sep=" throws "

  uml_raisedException.each { |exception|
    write(sep);
    write(exception.xsd_qualifiedName)
    sep=","
  }
end

#xsd_writeParameterType(fp) ⇒ Object

write java type parameter (without the name)

Example:

  • void

  • int

  • pack1.Class1



1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
# File 'lib/ontomde-java/java/xsd.rb', line 1050

def xsd_writeParameterType(fp)
  if (fp.nil?)
    write("void ")
  else
    fp.xsd_write
    #uml_isException (!! a ne pas confondre avec une exception)
    #uml_isOrdered
    #uml_isStream
    #uml_isUnique
  end
end