Class: Crdf_ProtegeDataModel

Inherits:
Crdf_Repository show all
Defined in:
lib/ontomde-java/kbjava/rdfToJava.rb

Overview

This module is meant to be applied to a protege 2000 knowledge model

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Crdf_Repository

#struts_getFunctionalException

Instance Attribute Details

#kbjava_umlSourceModelObject

uml model used to generate this protege data model attr :umlSourceModel



7
8
9
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 7

def kbjava_umlSourceModel
  @kbjava_umlSourceModel
end

Instance Method Details

#kbjava_addData!(umlDataClass) ⇒ Object

writes all in one java class which will contain all of our test instances loaded from source protege data model.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 34

def kbjava_addData!(umlDataClass)
  #write "package #{context[:dataTestPackageName]};\n"
  #write("public class #{context[:dataTestClassName]} {\n")

  #mtk_protected("converter") {
  umlDataClass.java_customCode= <<END
 private static java.text.SimpleDateFormat dfCalendar= new java.text.SimpleDateFormat("yyyy-MM-dd",java.util.Locale.ENGLISH);
 private static java.text.SimpleDateFormat dfTimestamp= new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss",java.util.Locale.ENGLISH);
public java.util.Date convertCalendar(final String s) {
	try  {
	return dfCalendar.parse(s) ;
	} catch (java.text.ParseException e) {
throw new java.lang.RuntimeException(e);
	}
}
public java.util.Date convertTimestamp(final String s) {
	try  {
	return dfTimestamp.parse(s) ;
	} catch (java.text.ParseException e) {
throw new java.lang.RuntimeException(e);
	}
}

END

  #}
  [true,false].each {|stepOne|
    self.each { |k,c|
      next unless c.kbjava_isUmlObject?
      c.kbjava_writeJavaObject(@kbjava_umlSourceModel, self,umlDataClass,stepOne)
    }}
  #write "}"
  #@kbjava_umlSourceModel.kbjava_computeCoverage
end

#kbjava_generateObject

Generates a DataSet default generation path may be overriden by providing appropriate context.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 11

def kbjava_generate
  mtk_default_context(:dataTestClassName=>'UserData',:dataTestPackageName => 'xmda.test') {

    dc=@kbjava_umlSourceModel.umlx_reserved_model.umlx_getOrCreateClass("#{context[:dataTestPackageName]}.#{context[:dataTestClassName]}")
    dc.umlx_external=RDF_FALSE

    #No Gui is provided for TestData (class is too big)
    dc.umlx_businessMethod=RDF_FALSE

    #UserData must be transient because UserData links
    #eventually to many many many objects and this
    #would generate has many columns in database
    #and as many joins.
    dc.db_isTransient=RDF_TRUE

    kbjava_addData!(dc)
  }
end

#kbjava_generateJavaJunit!Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/ontomde-java/kbjava/rdfToJava.rb', line 69

def kbjava_generateJavaJunit!
  self.each { |k,c|
    next unless c.kind_of?(Mkb_UML_TEST_DATA_SET)
    uml_type=c.rdf_type.kbjava_uml_model_element(@kbjava_umlSourceModel)
    p=uml_type.umlx_owner_one
    p=p.umlx_getOrCreatePackage(context[:kbjava_junitSubPackage,"junitUseCase"],p)
    p=p.umlx_getOrCreatePackage(uml_type.java_Name.to_s,p)

    n=p.umlx_createAndAddClass("#{c.rdf_uri}_junit","junit#{c.kb_UML_DATA_SET_NAME}")

    #propagate use case documentation to test class
    n.uml_ownedComment=uml_type.uml_ownedComment unless uml_type.uml_ownedComment.empty? 

    #Provide a Gui
    n.umlx_businessMethod=RDF_TRUE
    #puts "n=#{n.uml_name} busniess=#{n.umlx_businessMethod?}"
    #n.apaCom_addLogger!
    n.db_isTransient=RDF_TRUE
    #n.struts_isForm=RDF_FALSE
    n.umlx_external=RDF_FALSE
    n.java_import='org.junit.Test'
    #n.java_import_add('java.io.PrintWriter');
    #n.java_import_add('java.io.StringWriter');
    n.java_isATestFile=RDF_TRUE

    #also avoid org.junit.* import notused warning in Eclipse
    n.java_customCode="@Test\npublic void replaceWithMeaningfulTest(){}\n"

    return if uml_type.context[:rel_mapping] == 'none'

      m=n.umlx_createAndAddOperation(n.rdf_uri+"merge","merge");
      #TODO merge referenced items
      m.java_code="return this;"
      p=m.umlx_createAndAddReturnParameter(m.rdf_uri+'_ret',"return")
      p.uml_type=n
      m.umlx_businessMethod=RDF_FALSE

      persist=n.umlx_createAndAddOperation(n.rdf_uri+"persist","persist");
      persist.java_code="" # #{java_debug(%{log.debug("persisting referenced persistent elements");}\n}"
      p=persist.umlx_createAndAddReturnParameter(persist.rdf_uri+'_ret',"return")
      p.uml_type=n
      persist.umlx_businessMethod=RDF_FALSE

    #v=n.umlx_createAndAddProperty(n.rdf_uri+"__source","source");

    #ds="#{context[:dataTestPackageName]}.#{context[:dataTestClassName]}"
    #TODO: remove hard coded
    ds="xmda.test.UserData"
    #v.uml_type=n.umlx_getOrCreateClass(ds)
    #v.java_code="null"

    j=<<END
	// using one single source object
	// enables objects retrieved to be linked together.
	// Objects retrieved with a new source will *not* be linked together.
	#{ds} source=new #{ds}();
END
    c.kb_UML_DATA.each { |d|
      if  d.kb_UML_INSTANCE_ALIAS.empty?
        log.warn("data ignored in junit #{c} because of missing UML_INSTANCE_ALIAS")
        next
      end
      u=d.rdf_type.kbjava_uml_model_element(@kbjava_umlSourceModel)
      p=n.umlx_createAndAddProperty(n.rdf_uri+d.rdf_uri,"#{d.kb_UML_INSTANCE_ALIAS}");
      p.uml_type=u
      p.uml_isReadOnly=RDF_FALSE
      p.java_code="null"

      j="#{j}\n	set#{p.java_NameBean}(source.get#{p.java_NameBean}());"
      persist.java_code="#{persist.java_code.to_s} get#{p.java_NameBean}().persist();\n"
    }

    m=n.umlx_createAndAddOperation(n.rdf_uri+"initData","initData")
    m.umlx_businessMethod=RDF_FALSE
    m.java_code="#{j} return this;"
    #m.java_annotation_add(%{@SuppressWarnings("unused")})
    p=m.umlx_createAndAddReturnParameter(m.rdf_uri+'_ret',"return")
    p.uml_type=n

    persist.java_code="#{persist.java_code.to_s} return this;\n"
  }
end