Module: Muml_NamedElement

Defined in:
lib/ontomde-uml2-java/java.rb

Overview

module Muml_Property def java_Name return uml_isStatic? ? super.upcase : super end end

Constant Summary collapse

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"]
JAVA_NUMBERS =
["0","1","2","3","4","5","6","7","8","9"]
JAVA_UNIQUE_NAME =

java unique name enforcement variable

Hash.new

Instance Method Summary collapse

Instance Method Details

#display_java_Name_case_error(isDowncase) ⇒ Object

DISPLAY_JAVA_NAME_CASE_ERROR=Set.new()



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/ontomde-uml2-java/java.rb', line 249

def display_java_Name_case_error(isDowncase)
  return unless context[:java_display_case_errors,false]
  #next if DISPLAY_JAVA_NAME_CASE_ERROR.include?(self)
  #DISPLAY_JAVA_NAME_CASE_ERROR<< self
  log.error { %{***** INVALID MODEL DETECTED *****
***** INVALID MODEL DETECTED *****
Model element name:
	uml_class=#{self.class.name}
	rdf_uri=#{rdf_uri}
	uml_name=#{uml_name}
	uml_owner=#{umlx_owner_one}
should begin with a #{isDowncase ? "downcase": "upcase"} character.
***** INVALID MODEL DETECTED *****
    }}
end

#java_NameObject



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/ontomde-uml2-java/java.rb', line 228

def java_Name
  return @java_Name_cache unless @java_Name_cache.nil?
  s=java_safeName(uml_name.to_s)
  b=context[:java_fixNameCase,true]
  if !b
    # do nothing
  elsif kind_of?(Muml_Package) || kind_of?(Muml_Property) || kind_of?(Muml_Parameter) || kind_of?(Muml_Operation)
    if s[0..0].downcase!=s[0..0]
      s="#{s[0..0].downcase}#{s[1,s.length]}"
      display_java_Name_case_error(true)
    end
  elsif (kind_of?(Muml_Class) || kind_of?(Muml_Interface) || kind_of?(Muml_Enumeration) ) && ! kind_of?(Muml_PrimitiveType)
    if s[0..0].capitalize!=s[0..0]
      s="#{s[0..0].capitalize}#{s[1,s.length]}"
      display_java_Name_case_error(false)
    end
  end
  @java_Name_cache=s
  return @java_Name_cache
end

#java_NameBeanObject

Returns this element java_Name after applying a simplified java bean case convention. java.sun.com/products/javabeans/docs/spec.html anIntAttribute –> AnIntAttribute aBooleanAttribute –> aBooleanAttribute



270
271
272
# File 'lib/ontomde-uml2-java/java.rb', line 270

def java_NameBean
  return java_toNameBean(java_Name.to_s)
end

#java_NamePropertyObject

Returns this element java_Name after applying a simplified java bean property case convention.



282
283
284
285
# File 'lib/ontomde-uml2-java/java.rb', line 282

def java_NameProperty
  return java_Name
  #return java_toNameProperty(java_Name)
end

#java_safeName(str) ⇒ Object

returns a valid java symbol computed from str

NOTE:

display a warning an return /*TODO …*/ if str is empty

Examples: java_safeName(“number”) returns number java_safeName(“8number”) returns _number



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/ontomde-uml2-java/java.rb', line 169

def java_safeName(str)
  if str.empty?
    log.warn "WARNING: blank name detected for obj type #{self.class.name} identified by uri=#{uri}"
    return "/*TODO: ERROR:blank name found in uml model:*/"
  end
  #TODO A g?rer globalement pour la gestion des g?n?riques
  if java_isGeneric?
    # a generic may contain names such as xyz<org.myname>
    ret=str.to_s.tr('^a-zA-Z0-9_<?>.,',"")
  else
    ret=str.to_s.tr('^a-zA-Z0-9_',"")
  end
  ret="_"+ret if JAVA_NUMBERS.include?(ret[0,1])
  ret="_"+ret if JAVA_RESERVED_WORD.include?(ret)
  return ret
end

#java_toNameBean(name) ⇒ Object



273
274
275
276
277
278
279
# File 'lib/ontomde-uml2-java/java.rb', line 273

def java_toNameBean(name)
  #special case handling introduced for struts
  return name if name[1,1].upcase==name[1,1]
  name=String.new(name)
  name[0] = name[0, 1].upcase
  return name
end

#java_toNameProperty(name) ⇒ Object

Converts string name to a property name and returns its value.

Example:

java_toNameProperty("Xyz") return "xyz"
java_toNameProperty("XYZ") return "xYZ"


292
293
294
295
296
297
298
# File 'lib/ontomde-uml2-java/java.rb', line 292

def java_toNameProperty(name)
  result = String.new(name)
  if !result.empty?
    result[0] = result[0, 1].downcase
  end
  return result
end

#java_uniqueNameObject

return a unique name for this element. Logs an error messge is uniqueness is not verified.



191
192
193
194
195
196
197
198
199
200
# File 'lib/ontomde-uml2-java/java.rb', line 191

def java_uniqueName
  ret=java_Name.to_s
  k=JAVA_UNIQUE_NAME[ret]
  if k.nil?
    JAVA_UNIQUE_NAME[ret]=rdf_uri
  elsif k!=rdf_uri
    log_error_unique_name
  end
  return ret
end

#log_error_unique_nameObject



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/ontomde-uml2-java/java.rb', line 202

def log_error_unique_name
  #return if log_already_displayed?("#{rdf_uri}__uniqueName")
  log.error {
    <<END
non unique name detected
********* INVALID DATA DETECTED **********
** This software expects uml names to be globaly unique.
** The following item has been detected to be an homonym
** of a previously processed model element.
** #{mtk_object_message}
**
** Check your model and make sure names are unique.
**
** This model element is related to these other model elements:
#{mtk_related_message}
********* INVALID DATA DETECTED **********
END
  }
  if context[:java_failIfNonUniqueName]
    raise Warning.new(),"unique name assertion failed"
  end

end