Module: Muml_Namespace

Defined in:
lib/ontomde-uml2/uml2.rb,
lib/ontomde-uml2/uml2.rb,
lib/ontomde-uml2/umlx.rb

Constant Summary collapse

UMLX_SEARCH_EVERY_MODEL =

special token used to force umlx_getOrCreateProc to search every model

13579

Instance Method Summary collapse

Instance Method Details

#_computePackage_notUsedObject

Internal use.

Kept for possible future use.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ontomde-uml2/uml2.rb', line 42

def _computePackage_notUsed
  rdf_Repository.each { |a,x|
    if(x.class==Cuml_Class)
      x.uml_nestedClassifier {
        return x if e==self
      }
    end
    if(x.class==Cuml_Package)
      x.uml_ownedMember.each { |e|
        return x if e==self
      }
    end
  }
  return nil
end

#umlx_dataType_booleanObject

returns a boolean datatype



319
320
321
# File 'lib/ontomde-uml2/umlx.rb', line 319

def umlx_dataType_boolean 
  return umlx_getOrCreateDataType("boolean")
end

#umlx_dataType_integerObject

returns an integer datatype



327
328
329
# File 'lib/ontomde-uml2/umlx.rb', line 327

def umlx_dataType_integer
  return umlx_getOrCreateDataType("int")
end

#umlx_dataType_longObject

returns an long integer datatype



331
332
333
# File 'lib/ontomde-uml2/umlx.rb', line 331

def umlx_dataType_long
  return umlx_getOrCreateDataType("long")
end

#umlx_dataType_stringObject

returns a string datatype



323
324
325
# File 'lib/ontomde-uml2/umlx.rb', line 323

def umlx_dataType_string
  return umlx_getOrCreateDataType("string")
end

#umlx_getOrCreateClass(qual_name, startpoint = nil) ⇒ Object

Retrieves a class from its qualified name. Class will be created if not present in model. Example: umlx_getOrCreateClass(“java.util.HashSet”)



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/ontomde-uml2/umlx.rb', line 444

def umlx_getOrCreateClass(qual_name,startpoint=nil)
  ret=umlx_getOrCreateProc(qual_name,startpoint){ |owner,qual_name,c_name|
    c=owner.umlx_createAndAddClass(qual_name,c_name)
    c.umlx_external=RDF_TRUE
    c.db_isTransient=RDF_TRUE
    c
  }

  if ! ret.kind_of?(Cuml_Class)
    log.error {  <<END
**** ERROR NAME CLASH DETECTED ****
Creating a class named #{qual_name} failed
because an element of the same name was found
**** ERROR NAME CLASH DETECTED ****
END
    }
    return nil
  end
  return ret
end

#umlx_getOrCreateDataType(m_name) ⇒ Object

datatypes are created and looked up in umlx_reserved_model.



336
337
338
339
340
341
# File 'lib/ontomde-uml2/umlx.rb', line 336

def umlx_getOrCreateDataType(m_name)
  mod=umlx_reserved_model
  p=mod.umlx_getElementNamed(m_name)
  return p unless p.nil?
  return mod.umlx_createAndAddDataType(m_name,m_name)
end

#umlx_getOrCreateEnumeration(qual_name, startpoint = nil) ⇒ Object

Retrieves an enumeration from its qualified name. Class will be created if not present in model. Example: umlx_getOrCreateEnumeration(“com.mycompany.myEnum”)



434
435
436
437
438
# File 'lib/ontomde-uml2/umlx.rb', line 434

def umlx_getOrCreateEnumeration(qual_name,startpoint=nil)
  return umlx_getOrCreateProc(qual_name,startpoint) { |owner,qual_name,c_name|
    owner.umlx_createAndAddEnumeration(qual_name,c_name)
  }
end

#umlx_getOrCreateInterface(qual_name, startpoint = nil) ⇒ Object

Retrieves an interface from its qualified name. Class will be created if not present in model. Example: umlx_getOrCreateInterface(“java.util.Set”)



422
423
424
425
426
427
428
# File 'lib/ontomde-uml2/umlx.rb', line 422

def umlx_getOrCreateInterface(qual_name,startpoint=nil)
  return umlx_getOrCreateProc(qual_name,startpoint) { |owner,qual_name,c_name|
    ret=owner.umlx_createAndAddInterface(qual_name,c_name)
    ret.umlx_external=RDF_TRUE
    ret
  }
end

#umlx_getOrCreatePackage(qual_name, startpoint = nil) ⇒ Object

Retrieves a package from its qualified name. Package will be created if not present in model. Example: umlx_getOrCreatePackage(“com.mycompany”)



411
412
413
414
415
# File 'lib/ontomde-uml2/umlx.rb', line 411

def umlx_getOrCreatePackage(qual_name,startpoint=nil)
  return umlx_getOrCreateProc(qual_name,startpoint) { |owner,qual_name,c_name|
    owner.umlx_createAndAddPackage("#{owner.rdf_uri}/#{qual_name}",c_name)
  }
end

#umlx_getOrCreateProc(qual_name, startpoint = nil, &create) ⇒ Object

For internal use. Lookup element name qual_name. Returns element if found, yields otherwise.



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/ontomde-uml2/umlx.rb', line 358

def umlx_getOrCreateProc(qual_name,startpoint=nil,&create)
  #TODO Patch pour la gestion des génériques : A faire mieux qd gestion complète
  #Ne marche pas si plusiuers génériques encastrées
  if !qual_name.nil? && qual_name.include?("<")
    beforeGen = qual_name.split("<")
    s=beforeGen[0].split(".")
    if beforeGen.length > 1
      generic = "<#{beforeGen[1]}"
      s[s.length-1] += generic
    end
  else
    s=qual_name.split(".")
  end
  i=s.size
  c_name=s[i-1]
  s.delete_at(i-1)

  searchPath=[]
  if startpoint==UMLX_SEARCH_EVERY_MODEL
    rdf_Repository.each { |k,c|
      if c.kind_of?(Muml_Model)
        searchPath<< c
      end
    }
    searchPath<< umlx_reserved_model
  elsif startpoint.nil?
    searchPath<< umlx_reserved_model
  else
    searchPath=[startpoint]
  end

  c=nil
  # make cur global
  cur=nil
  searchPath.each { |cur|
    creationOK=(cur==startpoint) || (cur==umlx_reserved_model)
    s.each { |m_name|
      p=cur.umlx_getElementNamed(m_name)
      break if p.nil? && !creationOK
      #puts "---> #{cur.rdf_uri}/#{m_name}"  if (p.nil?)
      cur=(!p.nil?) ? p : cur.umlx_createAndAddPackage("#{cur.rdf_uri}/#{m_name}",m_name)
    }
    c=cur.umlx_getElementNamed(c_name)
    break unless c.nil?
  }
  c=yield(cur,qual_name,c_name) if c.nil?
  return c
end

#umlx_getOrCreateStereotype(m_name) ⇒ Object

stereotype are created and looked up in umlx_reserved_model.



344
345
346
347
348
349
# File 'lib/ontomde-uml2/umlx.rb', line 344

def umlx_getOrCreateStereotype(m_name)
  mod=umlx_reserved_model
  p=mod.umlx_getElementNamed(m_name)
  return p unless p.nil?
  return mod.umlx_createAndAddStereotype(m_name,m_name)
end

#umlx_hierarchyObject

Returns the chain of namespace owning this element including this element



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ontomde-uml2/uml2.rb', line 66

def umlx_hierarchy
  isarn=self.umlx_isARootNamespace?
  p=umlx_package
  r=nil
  if(p==nil || isarn ) # || p.kind_of?(Muml_Model))
    r=Array.new()
  else
    r=p.umlx_hierarchy
  end
  r.push(self) if !isarn
  return r
end

#umlx_isARootNamespace?Boolean

return true if element is a namespace root. Such an element is either an element stereotyped “root” or an instance of uml_Model. a root element name is not part of the qualified name of its enclosed elements.

Returns:

  • (Boolean)


62
63
64
# File 'lib/ontomde-uml2/uml2.rb', line 62

def umlx_isARootNamespace?
  return self.kind_of?(Muml_Model) || self.umlx_hasStereotype?("root")
end

#umlx_packageObject

Returns containing package. Note: Returns null if containing package is a Model.



32
33
34
35
36
37
# File 'lib/ontomde-uml2/uml2.rb', line 32

def umlx_package
  #TODO: utiliser relation inverse when available
  p=umlx_owner_one
  return nil if p.kind_of?(Cuml_Model)
  return p
end

#umlx_sub_hierarchyObject

Returns the chain of namespace owning this element NOT including this element



80
81
82
83
84
85
86
87
88
# File 'lib/ontomde-uml2/uml2.rb', line 80

def umlx_sub_hierarchy
  p=umlx_package
  if(p==nil)
    r=Array.new()
  else
    r=p.umlx_hierarchy
  end
  return r
end