Class: Crdfs_Class

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

Direct Known Subclasses

Ckb_UML_METACLASS

Constant Summary collapse

JAVA_METACLASS_MAPPING =

Example: An UML metaclass class maps to a java.lang.Class java class. Note:

feature introduced for opencrx.
{
"uml_Class" => "java.lang.Class"
}

Instance Method Summary collapse

Instance Method Details

#java_qualifiedNameObject

Example:

Note: added for openmdx which uses attributes of type “metaclass-class”.



20
21
22
23
24
25
# File 'lib/ontomde-java/java/meta.rb', line 20

def java_qualifiedName
	qn=JAVA_METACLASS_MAPPING[rdf_uri]
	return qn unless qn.nil?
	msg="unknown java_qualifiedName for meta-class #{rdf_uri}"
	return "int /*TODO: #{msg} */"
end

#kbjava_aliasNameObject



242
243
244
245
246
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 242

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)


248
249
250
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 248

def kbjava_isPublic?
  return !kbjava_aliasName.nil?
end

#kbjava_uml_property_values(dataSource) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 252

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



173
174
175
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 173

def kbjava_umlSourceModel
  return rdf_Repository.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.



237
238
239
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 237

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



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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 180

def kbjava_writeJavaObject(umlSourceModelParam, dataSource,umlDataClass,stepOne)
  if rdf_type.nil?
    # object was created localy (it was not loaded from file)
    return
  end
  uml_type=self.rdf_type.kbjava_uml_model_element(umlSourceModelParam)

  return if uml_type.kind_of?(Muml_UseCase)
  return if uml_type.nil? # element is not mapped to an uml class (soa:soa, ...)

  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_isReadOnly=RDF_TRUE
    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

    if kbjava_aliasName.nil?
	#no alias, getter is private
    	p.java_AttributeGlobalGetter_one.uml_visibility= Cuml_VisibilityKind::Protected      
    end
    #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.uml_type_one.java_qualifiedName} elt= new #{uml_type.java_qualifiedName}();
#{p.java_Name}=elt;
#{mtk_stss{kbjava_writeJavaObjectSetters(dataSource)}}
	}
	return #{p.java_Name};
ENDinit

    # overide getter with init
  end
end

#kbjava_writeJavaObjectSetter(umlprop, valitem) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 290

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

  #t=umlprop.uml_type_one.java_qualifiedName

  m=DatatypeMapping.instance.getMapping(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



280
281
282
283
284
285
286
287
288
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 280

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