Module: Muml_NamedElement
- Defined in:
- lib/ontomde-java/java/xsd.rb,
lib/ontomde-java/java/java.rb,
lib/ontomde-java/jpa/mapping.rb,
lib/ontomde-java/crank/helper.rb
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
- #<=>(other) ⇒ Object
-
#display_java_Name_case_error(isDowncase) ⇒ Object
DISPLAY_JAVA_NAME_CASE_ERROR=Set.new().
-
#display_xsd_Name_case_error(isDowncase) ⇒ Object
DISPLAY_JAVA_NAME_CASE_ERROR=Set.new().
- #java_Name ⇒ Object
-
#java_NameBean ⇒ Object
Returns this element java_Name after applying a simplified java bean case convention.
-
#java_NameProperty ⇒ Object
Returns this element java_Name after applying a simplified java bean property case convention.
-
#java_safeName(str) ⇒ Object
returns a valid java symbol computed from str.
- #java_toNameBean(name) ⇒ Object
-
#java_toNameProperty(name) ⇒ Object
Converts string name to a property name and returns its value.
-
#java_uniqueName ⇒ Object
return a unique name for this element.
-
#jpa_addNameAnnotation ⇒ Object
add name annotation when name is different from default.
-
#jpa_Name ⇒ Object
jpa/hibernates breaks at runtime if a name begining with an underscore (_) is encountered.
- #log_error_unique_name ⇒ Object
- #xsd_Name ⇒ Object
-
#xsd_NameBean ⇒ Object
Returns this element xsd_Name after applying a simplified java bean case convention.
-
#xsd_NameProperty ⇒ Object
Returns this element xsd_Name after applying a simplified java bean property case convention.
-
#xsd_safeName(str) ⇒ Object
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= returns a valid java symbol computed from str.
- #xsd_toNameBean(name) ⇒ Object
-
#xsd_toNameProperty(name) ⇒ Object
Converts string name to a property name and returns its value.
-
#xsd_uniqueName ⇒ Object
return a unique name for this element.
Instance Method Details
#<=>(other) ⇒ Object
42 43 44 |
# File 'lib/ontomde-java/crank/helper.rb', line 42 def <=>(other) "#{self.java_Name}" <=> "#{other.java_Name}" end |
#display_java_Name_case_error(isDowncase) ⇒ Object
DISPLAY_JAVA_NAME_CASE_ERROR=Set.new()
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/ontomde-java/java/java.rb', line 297 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 |
#display_xsd_Name_case_error(isDowncase) ⇒ Object
DISPLAY_JAVA_NAME_CASE_ERROR=Set.new()
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/ontomde-java/java/xsd.rb', line 411 def display_xsd_Name_case_error(isDowncase) return unless context[:xsd_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_Name ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/ontomde-java/java/java.rb', line 269 def java_Name return @java_Name_cache unless @java_Name_cache.nil? s=java_safeName(uml_name.to_s) # JAVA_NAME_ALIAS.each { |k,v| # ps=s # s=s.gsub(k,v) # #puts "#{ps} -> #{s}" if s!=ps # } 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_NameBean ⇒ Object
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
318 319 320 |
# File 'lib/ontomde-java/java/java.rb', line 318 def java_NameBean return java_toNameBean(java_Name.to_s) end |
#java_NameProperty ⇒ Object
Returns this element java_Name after applying a simplified java bean property case convention.
330 331 332 333 |
# File 'lib/ontomde-java/java/java.rb', line 330 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
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/ontomde-java/java/java.rb', line 206 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
321 322 323 324 325 326 327 |
# File 'lib/ontomde-java/java/java.rb', line 321 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"
340 341 342 343 344 345 346 |
# File 'lib/ontomde-java/java/java.rb', line 340 def java_toNameProperty(name) result = String.new(name) if !result.empty? result[0] = result[0, 1].downcase end return result end |
#java_uniqueName ⇒ Object
return a unique name for this element. Logs an error messge is uniqueness is not verified.
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/ontomde-java/java/java.rb', line 228 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 |
#jpa_addNameAnnotation ⇒ Object
add name annotation when name is different from default.
15 16 17 18 19 |
# File 'lib/ontomde-java/jpa/mapping.rb', line 15 def jpa_addNameAnnotation d=jpa_Name.to_s.upcase j=java_Name.to_s.upcase return d==j ? nil : %{ name = "#{d}"} end |
#jpa_Name ⇒ Object
jpa/hibernates breaks at runtime if a name begining with an underscore (_) is encountered. We prepend jpa when a name starts with underscore.
7 8 9 10 11 |
# File 'lib/ontomde-java/jpa/mapping.rb', line 7 def jpa_Name n=java_Name.to_s.upcase ret=n[0,1]=='_' ? 'JPA'+n : n return ret end |
#log_error_unique_name ⇒ Object
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/ontomde-java/java/xsd.rb', line 364 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. ** #{} ** ** Check your model and make sure names are unique. ** ** This model element is related to these other model elements: #{} ********* INVALID DATA DETECTED ********** END } if context[:xsd_failIfNonUniqueName,true] raise Warning.new(),"unique name assertion failed" end end |
#xsd_Name ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/ontomde-java/java/xsd.rb', line 390 def xsd_Name return @xsd_Name_cache unless @xsd_Name_cache.nil? s=xsd_safeName(uml_name.to_s) b=context[:xsd_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_xsd_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_xsd_Name_case_error(false) end end @xsd_Name_cache=s return @xsd_Name_cache end |
#xsd_NameBean ⇒ Object
Returns this element xsd_Name after applying a simplified java bean case convention. java.sun.com/products/javabeans/docs/spec.html anIntAttribute –> AnIntAttribute aBooleanAttribute –> aBooleanAttribute
432 433 434 |
# File 'lib/ontomde-java/java/xsd.rb', line 432 def xsd_NameBean return xsd_toNameBean(xsd_Name.to_s) end |
#xsd_NameProperty ⇒ Object
Returns this element xsd_Name after applying a simplified java bean property case convention.
444 445 446 447 |
# File 'lib/ontomde-java/java/xsd.rb', line 444 def xsd_NameProperty return xsd_Name #return xsd_toNameProperty(xsd_Name) end |
#xsd_safeName(str) ⇒ Object
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= returns a valid java symbol computed from str
NOTE:
display a warning an return /*TODO …*/ if str is empty
Examples: xsd_safeName(“number”) returns number xsd_safeName(“8number”) returns _number
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/ontomde-java/java/xsd.rb', line 331 def xsd_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 xsd_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 |
#xsd_toNameBean(name) ⇒ Object
435 436 437 438 439 440 441 |
# File 'lib/ontomde-java/java/xsd.rb', line 435 def xsd_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 |
#xsd_toNameProperty(name) ⇒ Object
Converts string name to a property name and returns its value.
Example:
xsd_toNameProperty("Xyz") return "xyz"
xsd_toNameProperty("XYZ") return "xYZ"
454 455 456 457 458 459 460 |
# File 'lib/ontomde-java/java/xsd.rb', line 454 def xsd_toNameProperty(name) result = String.new(name) if !result.empty? result[0] = result[0, 1].downcase end return result end |
#xsd_uniqueName ⇒ Object
return a unique name for this element. Logs an error messge is uniqueness is not verified.
353 354 355 356 357 358 359 360 361 362 |
# File 'lib/ontomde-java/java/xsd.rb', line 353 def xsd_uniqueName ret=xsd_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 |