Module: Muml_Classifier

Defined in:
lib/ontomde-uml2/umlx.rb,
lib/ontomde-uml2/uml2.rb,
lib/ontomde-uml2/umlx.rb,
lib/ontomde-uml2/umlx.rb,
lib/ontomde-uml2/umlx.rb,
lib/ontomde-uml2/umlx.rb,
lib/ontomde-uml2/owner.rb,
lib/ontomde-uml2/helper.rb,
lib/ontomde-uml2/depencies.rb,
lib/ontomde-uml2/kb/protege.rb,
lib/ontomde-uml2/createAndAdd.rb

Overview

Helper methods to compute class depencies This feature is used primarily for imports (in ActionScript generator)

Constant Summary collapse

ProtegeURI =
Hash.new
RDF_METACLASS_URI =

RDF metaclass for a classifier

"#{NS_UML_CLASS}#UML_METACLASS"

Instance Method Summary collapse

Instance Method Details

#mainSubClassOfURIObject



132
133
134
# File 'lib/ontomde-uml2/kb/protege.rb', line 132

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

#prot_labelObject

label used in protege 2000



103
104
105
# File 'lib/ontomde-uml2/kb/protege.rb', line 103

def prot_label
  return "#{prot_uri_local}"
end

#prot_uri_localObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/ontomde-uml2/kb/protege.rb', line 107

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.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ontomde-uml2/kb/protege.rb', line 137

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

  write("<#{e.prot_uri}> <#{RDF_SUBCLASSOF_URI}> <#{mainSubClassOfURI}> .\n")
  write("<#{e.prot_uri}> <#{NS_UML_CLASS}#UML_LABEL> \"#{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



123
124
125
126
127
# File 'lib/ontomde-uml2/kb/protege.rb', line 123

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

#umlx_assignableClassifier(ret = Set.new) ⇒ Object

returns every type assignable to this classifier (this includes self and any class deriving from it)



598
599
600
601
602
603
604
605
606
# File 'lib/ontomde-uml2/umlx.rb', line 598

def umlx_assignableClassifier(ret=Set.new)
  return ret if ret.include?(self)
  ret<< self
  uml_general_inv.each { |g|
    g.uml_generalization_inv.each {|c|
      c.umlx_assignableClassifier(ret)
    }}
  return ret
end

#umlx_classifier_generalization_indirect(s = Set.new) ⇒ Object

Returns in a Set any class this class inherit froms, both directly and indirectly (trough other classes) Note: parameter is used internaly for recursion and should not be used.



16
17
18
19
20
21
22
23
24
25
# File 'lib/ontomde-uml2/uml2.rb', line 16

def umlx_classifier_generalization_indirect(s=Set.new)
  self.uml_generalization.each { |gene|
    gene.uml_general.each{ |c|
      recurse=!s.include?(c) # anti boucle infinie sur modele KO
      s.add(c)
      c.umlx_classifier_generalization_indirect(s) if recurse
    }
  }
  return s
end

#umlx_computeDirectDepencies(ret = Set.new) ⇒ Object

returns every class this elements depends on



6
7
8
9
10
11
# File 'lib/ontomde-uml2/depencies.rb', line 6

def umlx_computeDirectDepencies(ret=Set.new)
  (uml_ownedAttribute+uml_ownedOperation).each { |a|
    a.umlx_computeDirectDepencies(ret)
  }
  return ret
end

#umlx_createAndAddAssociation(new_uri, otherEnd) ⇒ Object

Creates and adds a new UML Association. Return the newly created association. new_uri should be globaly unique.



199
200
201
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/createAndAdd.rb', line 199

def umlx_createAndAddAssociation(new_uri,otherEnd)
  c1=self; c2=otherEnd
  a=Cuml_Association.new(rdf_Repository,new_uri)

  m1=Cuml_Property.new(rdf_Repository,"#{new_uri}_e1")
  m1.uml_type=c2
  #m1.uml_class=c1
  c1.uml_ownedAttribute_add(m1)

  m2=Cuml_Property.new(rdf_Repository,"#{new_uri}_e2")
  m2.uml_type=c1
  #m2.uml_class=c1
  #c2.uml_ownedAttribute_add(m2)



  [m1,m2].each {  |m|
    a.uml_memberEnd_add(m)
    m.uml_association=a
    m.uml_isUnique=RDF_TRUE
    m.uml_isOrdered=RDF_FALSE
    m.uml_visibility=::Cuml_VisibilityKind::Public
  }

  return [a,m1,m2]
end

#umlx_createAndAddOperation(new_uri, new_name = nil) ⇒ Object

Creates and adds a new UML Operation. Return the newly created element. new_uri should be globaly unique.



173
174
175
176
177
178
179
# File 'lib/ontomde-uml2/createAndAdd.rb', line 173

def umlx_createAndAddOperation(new_uri,new_name=nil)
  m=Cuml_Operation.new(rdf_Repository,new_uri)
  self.uml_ownedOperation_add(m)
  m.uml_name=new_name unless new_name.nil?
  m.uml_visibility=::Cuml_VisibilityKind::Public
  return m
end

#umlx_createAndAddProperty(new_uri, new_name = nil) ⇒ Object

Creates and adds a new UML property. Return the newly created element. new_uri should be globaly unique.



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/ontomde-uml2/createAndAdd.rb', line 184

def umlx_createAndAddProperty(new_uri,new_name=nil)
  #log.debug { %{umlx_createAndAddProperty : name="#{new_name}" uri="#{uri}" owner="#{self}" owner_uri="#{self.rdf_uri}"} }
  m=Cuml_Property.new(rdf_Repository,new_uri)
  self.uml_ownedAttribute_add(m)
  m.uml_name=new_name unless new_name.nil?
  m.uml_isUnique=RDF_TRUE
  m.uml_isOrdered=RDF_FALSE
  m.uml_visibility=::Cuml_VisibilityKind::Public
  #m.uml_class=self
  return m
end

#umlx_getElementNamed(name) ⇒ Object

returns nil or element with the proper name in the current namespace



235
236
237
238
239
240
241
242
243
# File 'lib/ontomde-uml2/umlx.rb', line 235

def umlx_getElementNamed(name)
  uml_ownedAttribute.each { |om|
    return om if om.uml_name.to_s==name
  }
  uml_ownedOperation.each { |om|
    return om if om.uml_name.to_s==name
  }
  return super(name)
end

#umlx_hasRelation?Boolean

returns true if this class directly carries associations, compositions or aggregations.



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

def umlx_hasRelation?
  uml_ownedAttribute.each { |o|
    return true unless o.umlx_isAttribute?
  }
  return false
end

#umlx_modelObject

Returns UML Model containing self.



293
294
295
296
297
298
299
300
301
302
303
# File 'lib/ontomde-uml2/umlx.rb', line 293

def umlx_model
  p=umlx_package
  return p.umlx_model unless p.nil?

  #(uml_nestedClassifier_inv).each { |o|
  # puts "o=#{o}"
  #}

  log.error { "umlx_model:no model found for #{self.class.name} #{self}" }
  return rdf_Repository.umlx_model
end

#umlx_ownedAndInheritedOperation(ret = Set.new) ⇒ Object

returns every type assignable to this classifier (this includes self and any class deriving from it)



4
5
6
7
8
9
10
11
12
13
# File 'lib/ontomde-uml2/helper.rb', line 4

def umlx_ownedAndInheritedOperation(ret=Set.new)
  uml_ownedOperation.each {|biz|
    ret << biz
  }
  uml_generalization.each { |g|
    next if g.kind_of?(Muml_Interface)
    g.uml_general_one.umlx_ownedAndInheritedOperation(ret)
  }
  return ret
end

#umlx_owner=(p) ⇒ Object



26
27
28
29
30
31
# File 'lib/ontomde-uml2/owner.rb', line 26

def umlx_owner=(p)
  old=umlx_owner_one
  old.uml_ownedMember.delete(self) unless old.nil?
  p.uml_ownedMember_add(self)
  ext_isReferencedBy_add(p)
end

#umlx_owner_oneObject



19
20
21
22
23
24
25
# File 'lib/ontomde-uml2/owner.rb', line 19

def umlx_owner_one
  #return uml_ownedMember_inv_one0
  ext_isReferencedBy.each { |res|
    return res if res.respond_to?(:uml_ownedMember) && res.uml_ownedMember.include?(self)
  }
  return nil
end