Class: Crdfs_Class

Inherits:
Object
  • Object
show all
Defined in:
lib/ontomde-uml2-kbjava/rdfToJava.rb

Direct Known Subclasses

Ckb_UML_METACLASS

Instance Method Summary collapse

Instance Method Details

#kbjava_aliasNameObject



224
225
226
227
228
# File 'lib/ontomde-uml2-kbjava/rdfToJava.rb', line 224

def kbjava_aliasName
  s=@kb_UML_INSTANCE_ALIAS
  return nil if s.nil?  || s.empty?
  return s.to_s
end

#kbjava_isPublic?Boolean

Returns:

  • (Boolean)


230
231
232
# File 'lib/ontomde-uml2-kbjava/rdfToJava.rb', line 230

def kbjava_isPublic?
  return !kbjava_aliasName.nil?
end

#kbjava_uml_property_values(dataSource) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/ontomde-uml2-kbjava/rdfToJava.rb', line 234

def kbjava_uml_property_values(dataSource)
  ret=Hash.new
  instance_variables.each {
    |m|
    next if ["@kbjava_property","@kb_UML_URI","@kb_UML_LABEL","@rdfs_label","@ext_isReferencedBy","@rdfs_subClassOf", "@kb_UML_INSTANCE_ALIAS","@kb_UML_REFERENCED_USE_CASE","@kb_inv_UML_REFERENCED_USE_CASE","@kb_UML_USE_CASE_ENV"].include?(m)

    var = instance_variable_get(m)
    rawval = self.instance_variable_get(m)

    next unless rawval.kind_of?(ArrayOrSingleElement)

    protprop_ident=m[1,m.length] #remove leading @
    protprop_uri=getRubyNameInverse(protprop_ident)
    protprop=dataSource[protprop_uri]

    umluri=protprop.instance_variable_get("@kb_UML_URI").to_s
    umlurialiased=::UriNamespace.instance.urialias(umluri)
    umlprop=kbjava_umlSourceModel[umlurialiased]

    if umlprop.nil?
      log.warn { "uml prop not found for slot '#{m}' umluri='#{umluri}' umluriprop='#{umlurialiased}'" }
      next
    end
    ret[umlprop]=rawval
  }
  return ret
end

#kbjava_umlSourceModelObject



166
167
168
# File 'lib/ontomde-uml2-kbjava/rdfToJava.rb', line 166

def kbjava_umlSourceModel
  return rdf_model.kbjava_umlSourceModel
end

#kbjava_varNameObject

Returns test object variable name which will be used to store this test object. Return uri if test object has no name.



219
220
221
# File 'lib/ontomde-uml2-kbjava/rdfToJava.rb', line 219

def kbjava_varName
  return kbjava_aliasName.nil? ? uri : kbjava_aliasName
end

#kbjava_writeJavaObject(umlSourceModelParam, dataSource, umlDataClass, stepOne) ⇒ Object

rdf_safe_attr_reader_many :kbjava_initMethod



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/ontomde-uml2-kbjava/rdfToJava.rb', line 173

def kbjava_writeJavaObject(umlSourceModelParam, dataSource,umlDataClass,stepOne)
  uml_type=rdf_type.kbjava_uml_model_element(umlSourceModelParam)

  return if uml_type.kind_of?(Muml_UseCase)

  if stepOne
    # Create attributes and every init methods (body expected)
    uml_type.kb_coverage_add(self)
    p=umlDataClass.umlx_createAndAddProperty(umlDataClass.rdf_uri+kbjava_varName,kbjava_varName.to_s)
    p.uml_type=uml_type
    p.uml_visibility=  Cuml_VisibilityKind::Private
    #p.java_noAccessors=RDF_TRUE
    self.kbjava_property=p

    #init method
    #p=self.kbjava_property_one
    #i=umlDataClass.umlx_createAndAddOperation(umlDataClass.rdf_uri+"init"+kbjava_varName,"init#{kbjava_varName}")
    #i.uml_visibility=  kbjava_isPublic? ? Cuml_VisibilityKind::Public : Cuml_VisibilityKind::Private
    #r=i.umlx_createAndAddReturnParameter(i.rdf_uri+"ret","_return")
    #r.uml_type=p.uml_type_one
    #self.kbjava_initMethod=i

    umlDataClass.java_addGlobalGetter!(p)
  else
    # Create init methods body
    p=self.kbjava_property_one
    #i=self.kbjava_initMethod_one
    i=p.java_AttributeGlobalGetter_one
    #write "private #{uml_type.java_qualifiedName} #{kbjava_varName}=null;\n"
    #write "#{kbjava_public ? "public" : "private"} #{uml_type.java_qualifiedName} get#{kbjava_varName}() {"
    #p=self.kbjava_property_one
    i.java_code= <<ENDinit
	if(#{p.java_Name}==null){
#{p.java_Name}= new #{uml_type.java_qualifiedName}();
#{p.uml_type_one.java_qualifiedName} elt= #{p.java_Name};
#{mtk_stss{kbjava_writeJavaObjectSetters(dataSource)}}
	}
	return #{p.java_Name};
ENDinit

    # overide getter with init
  end
end

#kbjava_writeJavaObjectSetter(umlprop, valitem) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/ontomde-uml2-kbjava/rdfToJava.rb', line 272

def kbjava_writeJavaObjectSetter(umlprop,valitem)
  return if umlprop.uml_name.empty?
  return unless umlprop.umlx_isNavigable?

  #t=umlprop.uml_type_one.java_qualifiedName

  m=JavaMapping.instance.getTemplate(umlprop.uml_type_one)
  v=m.prot_convertToJava(umlprop,valitem)
  #i=m.prot_init(umlprop,valitem)

  #puts "i='#{i}'"
  meth=umlprop.umlx_upperValueIsOne? ? "set" : "add"
  #write "    #{i}/* tpl-kbjava01 */\n"
  write "// read only " if umlprop.uml_isReadOnly?
  write "    elt.#{meth}#{umlprop.java_NameBean}(#{v});\n"
end

#kbjava_writeJavaObjectSetters(dataSource) ⇒ Object



262
263
264
265
266
267
268
269
270
# File 'lib/ontomde-uml2-kbjava/rdfToJava.rb', line 262

def kbjava_writeJavaObjectSetters(dataSource)
  kbjava_uml_property_values(dataSource).each {
    |umlprop,rawval|
    umlprop.kb_coverage_add(rawval)
    rawval.each {|v|
      kbjava_writeJavaObjectSetter(umlprop,v)
    }
  }
end