Module: Muml_Namespace

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

Constant Summary collapse

UMLX_SEARCH_EVERY_MODEL =

special token used to force umlx_getOrCreateProc to search every model

13579
ProtegeURI =
Hash.new
RDF_METACLASS_URI =

RDF metaclass for a classifier

"#{NS_UML_CLASS}#UML_METACLASS"

Instance Method Summary collapse

Instance Method Details

#_computePackage_notUsedObject

Internal use.

Kept for possible future use.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ontomde-uml2/uml2.rb', line 72

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

#mainSubClassOfURIObject



167
168
169
# File 'lib/ontomde-uml2/kb/protege.rb', line 167

def mainSubClassOfURI
  return  "#{NS_UML_CLASS}#UML_CLASS"
end

#prot_labelObject

label used in protege 2000



138
139
140
# File 'lib/ontomde-uml2/kb/protege.rb', line 138

def prot_label
  return "#{prot_uri_local}"
end

#prot_uri_localObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ontomde-uml2/kb/protege.rb', line 142

def prot_uri_local
  b="#{prot_safe(uml_name)}"
  s=b
  i=1
  while true
    if ProtegeURI[s].nil?
      ProtegeURI[s]=self
      return s
    end
    return s if ProtegeURI[s]==self
    i=i+1
    s=b+"_"+i.to_s
  end
end

#prot_writeNTripleObject

writes RDF triple elements describing this classifier element.



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/ontomde-uml2/kb/protege.rb', line 172

def prot_writeNTriple
  e=self
  write("<#{e.prot_uri}> <#{RDF_TYPE_URI}> <#{RDF_METACLASS_URI}> .\n")
  write("<#{e.prot_uri}> <#{NS_RDF_2000}rdf-schema#label> \"#{e.uml_name.to_s.nt_escape}\" .\n")
  if e.uml_isAbstract?  || e.kind_of?(Muml_Interface) #|| e.kind_of?(Muml_UseCase)
    write("<#{e.prot_uri}> <http://protege.stanford.edu/system#role> \"abstract\" .\n")
  end
  e.append_comment
  e.prot_writeSubClassOf

  prefix= ''
  prefix='UC: ' if e.kind_of?(Muml_UseCase) 
  prefix='I: ' if e.kind_of?(Muml_Interface) 

  # Place element in its package hierarchy
  o=umlx_owner_one
  write("<#{prot_uri}> <#{RDF_SUBCLASSOF_URI}> <#{o.prot_uri}> .\n") unless o.nil? || o.prot_ignorePackage?

  write("<#{e.prot_uri}> <#{RDF_SUBCLASSOF_URI}> <#{mainSubClassOfURI}> .\n")
  write("<#{e.prot_uri}> <#{NS_UML_CLASS}#UML_LABEL> \"#{prefix}#{prot_label}\" .\n")
  write("<#{e.prot_uri}> <#{NS_UML_CLASS}#UML_URI> \"#{UriNamespace.instance.unalias(e.rdf_uri)}\" .\n")

end

#prot_writeSubClassOfObject

writes sub class of rdf instructions



158
159
160
161
162
# File 'lib/ontomde-uml2/kb/protege.rb', line 158

def prot_writeSubClassOf
  uml_generalization.each { |g|
    write("<#{prot_uri}> <#{RDF_SUBCLASSOF_URI}> <#{g.uml_general_one.prot_uri}> .\n")
  }
end

#umlx_dataType_booleanObject

returns a boolean datatype



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

def umlx_dataType_boolean 
  return umlx_getOrCreateDataType("boolean")
end

#umlx_dataType_integerObject

returns an integer datatype



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

def umlx_dataType_integer
  return umlx_getOrCreateDataType("int")
end

#umlx_dataType_longObject

returns an long integer datatype



334
335
336
# File 'lib/ontomde-uml2/umlx.rb', line 334

def umlx_dataType_long
  return umlx_getOrCreateDataType("long")
end

#umlx_dataType_stringObject

returns a string datatype



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

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



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/ontomde-uml2/umlx.rb', line 463

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.



339
340
341
342
343
344
# File 'lib/ontomde-uml2/umlx.rb', line 339

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



453
454
455
456
457
# File 'lib/ontomde-uml2/umlx.rb', line 453

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_getOrCreateGeneric(qual_name, genericParams, startpoint = nil) ⇒ Object

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



437
438
439
440
441
442
443
444
445
446
447
# File 'lib/ontomde-uml2/umlx.rb', line 437

def umlx_getOrCreateGeneric(qual_name,genericParams,startpoint=nil)
  qual_name=%{#{qual_name}<#{genericParams}>}
  return umlx_getOrCreateProc(qual_name,startpoint) { |owner,qual_name,c_name|
    #TODO: duplication probable si plusieurs fois meme generic 
    ret=owner.umlx_createAndAddInterface(qual_name,c_name)
    #ret.uml_name="#{qual_name}<#{genericParams}>"
    ret.umlx_external=RDF_TRUE
    ret.java_isGeneric=RDF_TRUE
    ret
  }
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”)



425
426
427
428
429
430
431
# File 'lib/ontomde-uml2/umlx.rb', line 425

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



414
415
416
417
418
# File 'lib/ontomde-uml2/umlx.rb', line 414

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.



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
406
407
408
# File 'lib/ontomde-uml2/umlx.rb', line 361

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.



347
348
349
350
351
352
# File 'lib/ontomde-uml2/umlx.rb', line 347

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



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ontomde-uml2/uml2.rb', line 105

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)


92
93
94
# File 'lib/ontomde-uml2/uml2.rb', line 92

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.



61
62
63
64
65
66
67
# File 'lib/ontomde-uml2/uml2.rb', line 61

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

#umlx_rootNamespace_one0Object

return root namespace for this element



97
98
99
100
101
102
# File 'lib/ontomde-uml2/uml2.rb', line 97

def umlx_rootNamespace_one0
	return self if umlx_isARootNamespace? 
	root=umlx_package
	return nil if root.nil?
	return root.umlx_rootNamespace_one0
end

#umlx_sub_hierarchyObject

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



119
120
121
122
123
124
125
126
127
# File 'lib/ontomde-uml2/uml2.rb', line 119

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