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

Overview


Different widgets


OAS (Object Association Single) OAM (Object Association Multiple) OCS (Object Composition Single) OCM (Object Composition Multiple)

EPS (Enumeration Property Single) EPM (Enumeration Property Multiple)

BPS (Boolean Property Single) CPS (Calendar Property Single) FPS (Float Property Single) IPS (Integer Property Single) SPS (String Property Single) TPS (Timestamp Property Single)

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 "{\n //TODO: implement method body\n throw new Error(\"[operation \\\\\"\#{as_Name}\\\\\"not implemented]\");\n}\n"
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

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)



1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
# File 'lib/ontomde-java/java/java.rb', line 1038

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.



1081
1082
1083
# File 'lib/ontomde-java/java/java.rb', line 1081

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)



1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'lib/ontomde-java/java/java.rb', line 1113

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



1131
1132
1133
1134
1135
1136
# File 'lib/ontomde-java/java/java.rb', line 1131

def java_writeMethodBodyNotImplemented
  write "\\t\\t//TODO: implement method body\n\\t\\tthrow new java.lang.RuntimeException(\"[operation \\\\\"\#{java_Name}\\\\\"not implemented]\");\n"
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



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

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)



1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
# File 'lib/ontomde-java/java/java.rb', line 1159

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)



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

def java_writeMethodReturnType
  java_writeParameterType(umlx_returnResult_one0)
end

#java_writeMethodThrowsObject

write method throw clause.

(Uses java_qualifiedName )

Example:

  • throws java.lang.Exception



1143
1144
1145
1146
1147
1148
1149
1150
1151
# File 'lib/ontomde-java/java/java.rb', line 1143

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



1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
# File 'lib/ontomde-java/java/java.rb', line 1097

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



1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
# File 'lib/ontomde-java/java/java.rb', line 1022

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

#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)



982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
# File 'lib/ontomde-java/java/xsd.rb', line 982

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.



1023
1024
1025
# File 'lib/ontomde-java/java/xsd.rb', line 1023

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)



1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
# File 'lib/ontomde-java/java/xsd.rb', line 1055

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



1072
1073
1074
1075
1076
1077
# File 'lib/ontomde-java/java/xsd.rb', line 1072

def xsd_writeMethodBodyNotImplemented
  write "//TODO: implement method body\nthrow new java.lang.RuntimeException(\"[operation \\\\\"\#{xsd_Name}\\\\\"not implemented]\");\n"
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



1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
# File 'lib/ontomde-java/java/xsd.rb', line 1005

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)



1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
# File 'lib/ontomde-java/java/xsd.rb', line 1100

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)



1029
1030
1031
# File 'lib/ontomde-java/java/xsd.rb', line 1029

def xsd_writeMethodReturnType
  xsd_writeParameterType(umlx_returnResult_one0)
end

#xsd_writeMethodThrowsObject

write method throw clause.

(Uses xsd_qualifiedName )

Example:

  • throws java.lang.Exception



1084
1085
1086
1087
1088
1089
1090
1091
1092
# File 'lib/ontomde-java/java/xsd.rb', line 1084

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



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'lib/ontomde-java/java/xsd.rb', line 1039

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