index.html 9.46 KB
Newer Older
Erwan BOUSSE's avatar
Erwan BOUSSE committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
68
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
<!DOCTYPE HTML>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Moclodash - Getting started</title>
    <link rel="stylesheet" href="/stylesheet.css">
    <link rel="stylesheet" href="/pygments.css">

    <!-- you don't need to keep this, but it's cool for stats! -->
    <meta name="generator" content="nanoc 4.11.18">
  </head>
  <body>
    <div id="main">
      
<h1 id="getting-started">Getting started</h1>

<p>What you need:</p>

<ul>
  <li>Some existing Eclipse installation with Moclodash plugins.</li>
  <li>An eclipse workspace with a plug-in or EMF project containing an ecore model serialized in one or multiple xmi files. Note that:
    <ul>
      <li>These ecore files must all be in the same folder.</li>
      <li>For our approach to be interesting, the mutable properties of the metamodel must be tagged by adding a suffix <code>_m</code> to their names.</li>
    </ul>
  </li>
</ul>

<p>In this guide, we consider an empty EMF project called “MyProject” containing a folder “model”, in which the ecore files are stored. More preceisely, our starting point is the following:</p>

<p><img src="1.png" alt="Starting point: a single project with a single ecore file."></p>

<h2 id="generating-cloning-material">Generating cloning material</h2>

<p>In this first part we generate all the java code required to created runtime representations of models of a given metamodel, including those of memory efficient clones.</p>

<ol>
  <li>From a Java perspective, go to <em>Run → Run configurations</em>. Right click on <em>CloningMaterialGeneration</em>, and select <em>New</em>.</li>
  <li>There are three fields to fill and a checkbox:
    <ul>
      <li>the folder that contains all the ecore files,</li>
      <li>the project in which the Java code must be generated,</li>
      <li>the name of the metamodel (which is mostly useful when the metamodel contains multiple packages or files).</li>
      <li>if you also want to make a call to the EMF model code generator without handling a genmodel file yourself, tick the checkbox
<img src="2.png" alt="Creating a cloning material generation run configuration.">
</li>
    </ul>
  </li>
  <li>Press “Run”. If you enabled the console view, then you can observe the progress. In the end, four packages are created (one per cloning strategy) each containing:
    <ul>
      <li>A <code>Copier</code> class, used by the cloner to instantiate java proxy classes when a class is partially shareable,</li>
      <li>A <code>Tags</code> class, which can tell if a class is shareable or not for this strategy,</li>
      <li>Proxy java classes for all classes of the metamodel that are partially shareable.
<img src="3.png" alt="Getting a blink at the results.">
</li>
    </ul>
  </li>
</ol>

<h2 id="using-the-cloning-strategies">Using the cloning strategies</h2>

<p>In this second part we use the provided API to clone models using the different strategies. Here is a sample of code that creates a model using the same metamodel as previsously, and then clones it using the four cloning strategies:</p>

<pre><code class="language-java"><span class="cm">/* Creating a model */</span>

<span class="nc">ResourceSet</span> <span class="n">mymodel</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">ResourceSetImpl</span><span class="o">();</span>
<span class="nc">Resource</span> <span class="n">resource</span> <span class="o">=</span> <span class="n">mymodel</span><span class="o">.</span><span class="na">createResource</span><span class="o">(</span><span class="no">URI</span><span class="o">.</span><span class="na">createFileURI</span><span class="o">(</span><span class="s">"/tmp/mymodel.xmi"</span><span class="o">));</span>

<span class="nc">MymetamodelFactory</span> <span class="n">factory</span> <span class="o">=</span> <span class="nc">MymetamodelFactory</span><span class="o">.</span><span class="na">eINSTANCE</span><span class="o">;</span>

<span class="nc">ReadOnlyLeaf</span> <span class="n">ro</span> <span class="o">=</span> <span class="n">factory</span><span class="o">.</span><span class="na">createReadOnlyLeaf</span><span class="o">();</span>
<span class="n">ro</span><span class="o">.</span><span class="na">setD</span><span class="o">(</span><span class="mi">42</span><span class="o">);</span>
<span class="n">ro</span><span class="o">.</span><span class="na">setE</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>

<span class="nc">MutableLeaf</span> <span class="n">mut</span> <span class="o">=</span> <span class="n">factory</span><span class="o">.</span><span class="na">createMutableLeaf</span><span class="o">();</span>
<span class="n">mut</span><span class="o">.</span><span class="na">setF_m</span><span class="o">(</span><span class="mi">12</span><span class="o">);</span>
<span class="n">mut</span><span class="o">.</span><span class="na">setG_m</span><span class="o">(</span><span class="kc">true</span><span class="o">);</span>

<span class="nc">Root</span> <span class="n">r</span> <span class="o">=</span> <span class="n">factory</span><span class="o">.</span><span class="na">createRoot</span><span class="o">();</span>
<span class="n">r</span><span class="o">.</span><span class="na">setA_m</span><span class="o">(</span><span class="mi">1337</span><span class="o">);</span>
<span class="n">r</span><span class="o">.</span><span class="na">setB</span><span class="o">(</span><span class="mi">9000</span><span class="o">);</span>
<span class="n">r</span><span class="o">.</span><span class="na">setC</span><span class="o">(</span><span class="kc">true</span><span class="o">);</span>
<span class="n">r</span><span class="o">.</span><span class="na">setMutleaf</span><span class="o">(</span><span class="n">mut</span><span class="o">);</span>
<span class="n">r</span><span class="o">.</span><span class="na">setRoleaf</span><span class="o">(</span><span class="n">ro</span><span class="o">);</span>

<span class="n">resource</span><span class="o">.</span><span class="na">getContents</span><span class="o">().</span><span class="na">add</span><span class="o">(</span><span class="n">r</span><span class="o">);</span>


<span class="cm">/* Cloning the model with the four strategies */</span>

<span class="nc">Cloner</span> <span class="n">deepCloningCloner</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">ClonerImpl</span><span class="o">(</span><span class="nc">MyMMDeepCloningCloningMaterial</span><span class="o">.</span><span class="na">getInstance</span><span class="o">());</span>
<span class="nc">ResourceSet</span> <span class="n">clone1</span> <span class="o">=</span> <span class="n">deepCloningCloner</span><span class="o">.</span><span class="na">clone</span><span class="o">(</span><span class="n">mymodel</span><span class="o">,</span> <span class="s">"deepClones"</span><span class="o">);</span>

<span class="nc">Cloner</span> <span class="n">shareFieldsOnlyCloner</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">ClonerImpl</span><span class="o">(</span>
		<span class="nc">MyMMShareFieldsOnlyCloningMaterial</span><span class="o">.</span><span class="na">getInstance</span><span class="o">());</span>
<span class="nc">ResourceSet</span> <span class="n">clone2</span> <span class="o">=</span> <span class="n">shareFieldsOnlyCloner</span><span class="o">.</span><span class="na">clone</span><span class="o">(</span><span class="n">mymodel</span><span class="o">,</span> <span class="s">"shareFieldsOnlyClones"</span><span class="o">);</span>

<span class="nc">Cloner</span> <span class="n">shareObjOnlyCloner</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">ClonerImpl</span><span class="o">(</span><span class="nc">MyMMShareObjOnlyCloningMaterial</span><span class="o">.</span><span class="na">getInstance</span><span class="o">());</span>
<span class="nc">ResourceSet</span> <span class="n">clone3</span> <span class="o">=</span> <span class="n">shareObjOnlyCloner</span><span class="o">.</span><span class="na">clone</span><span class="o">(</span><span class="n">mymodel</span><span class="o">,</span> <span class="s">"shareObjOnlyClones"</span><span class="o">);</span>

<span class="nc">Cloner</span> <span class="n">shareAllCloner</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">ClonerImpl</span><span class="o">(</span><span class="nc">MyMMShareAllCloningMaterial</span><span class="o">.</span><span class="na">getInstance</span><span class="o">());</span>
<span class="nc">ResourceSet</span> <span class="n">clone4</span> <span class="o">=</span> <span class="n">shareAllCloner</span><span class="o">.</span><span class="na">clone</span><span class="o">(</span><span class="n">mymodel</span><span class="o">,</span> <span class="s">"shareAlldeepClones"</span><span class="o">);</span></code></pre>

    </div>
    <div id="sidebar">
    
       <ul>
        <li><a href="/">Moclodash</a></li>
      </ul>

      <h2>Tools</h2>
      <ul>
        <li><a href="/tools/plugin">Eclipse plugins</a></li>
        <li><a href="/tools/evaluation">Evaluation toolsuite</a></li>
      </ul>        
      <h2>Development</h2>
      <ul>
        <li><a href="https://gitlab.univ-nantes.fr/bousse-e/moclodash">Forge (external)</a></li>
        <li><a href="/source">Source code</a></li>
      </ul>
      <h2>Documentation</h2>
      <ul>
        <li><a href="/doc/getting-started">Getting started</a></li>
        <li><a href="/doc/evaluation">Running the evaluation</a></li>
        <li><a href="/doc/research">Research</a></li>
      </ul>
    </div>
  </body>
</html>