@@ -44,7 +44,7 @@ public class JsonComposer {
44
44
private HashMap <String , EClass > registry ;
45
45
HashMap <File , List <File >> jsonFiles ;
46
46
HashMap <EAttribute , List <Object >> cacheValues ;
47
-
47
+
48
48
public static void main (String [] args ) {
49
49
JsonStandaloneSetup .doSetup ();
50
50
@@ -102,7 +102,10 @@ public void compose(File resultPath) {
102
102
coverageCreator .createConceptMapping (eClass , duplicatedEClass );
103
103
eClass = duplicatedEClass ;
104
104
} else {
105
+ coverageCreator .createConceptMapping (eClass , registryElement );
105
106
composeAttributes (registryElement , eClass , coverageCreator );
107
+ composeReferences (registryElement , eClass , coverageCreator );
108
+ eClass = registryElement ;
106
109
}
107
110
for (EStructuralFeature otherFeature : eClass .getEStructuralFeatures ())
108
111
if (otherFeature instanceof EReference )
@@ -176,6 +179,22 @@ private void composeAttributes(EClass existingClass, EClass otherClass, Coverage
176
179
177
180
}
178
181
182
+ private void composeReferences (EClass existingClass , EClass otherClass , CoverageCreator coverageCreator ) {
183
+ for (EStructuralFeature otherFeature : otherClass .getEStructuralFeatures ()) {
184
+ if (otherFeature instanceof EReference ) {
185
+ EReference otherReference = (EReference ) otherFeature ;
186
+ EStructuralFeature existingFeature = existingClass .getEStructuralFeature (otherReference .getName ());
187
+ if (existingFeature == null ) {
188
+ EReference newReference = duplicateReference (otherReference );
189
+ existingClass .getEStructuralFeatures ().add (newReference );
190
+ System .out .println ("Reference " + newReference .getName () + " added" );
191
+ existingFeature = newReference ;
192
+ coverageCreator .createRefMapping (otherReference , (EReference ) existingFeature );
193
+ }
194
+ }
195
+ }
196
+
197
+ }
179
198
180
199
private EAttribute duplicateAttribute (EAttribute otherAttribute ) {
181
200
EAttribute newAttribute = EcoreFactory .eINSTANCE .createEAttribute ();
@@ -218,7 +237,7 @@ private EClass duplicateEClass(EClass otherClass, CoverageCreator coverageCreato
218
237
219
238
private EAttribute lookForSimilarAttribute (EClass existingClass , EAttribute otherAttribute , CoverageCreator coverageCreator ) {
220
239
List <Object > jsonValues = getJSONValues (otherAttribute .getName (), coverageCreator .getFile ());
221
-
240
+
222
241
Iterator <EAttribute > it = cacheValues .keySet ().iterator ();
223
242
while (it .hasNext ()) {
224
243
EAttribute eAttribute = it .next ();
@@ -235,18 +254,18 @@ private EAttribute lookForSimilarAttribute(EClass existingClass, EAttribute othe
235
254
}
236
255
}
237
256
}
238
-
257
+
239
258
return null ;
240
259
}
241
-
260
+
242
261
private List <Object > getJSONValues (String name , File service ) {
243
262
List <Object > result = new ArrayList <Object >();
244
263
if (jsonFiles == null ) return result ;
245
-
264
+
246
265
ResourceSet rset = new ResourceSetImpl ();
247
266
List <File > files = jsonFiles .get (service );
248
267
if (files == null ) return result ;
249
-
268
+
250
269
File file = files .get (0 );
251
270
Resource res = rset .getResource (URI .createFileURI (file .getAbsolutePath ()), true );
252
271
@@ -257,7 +276,7 @@ private List<Object> getJSONValues(String name, File service) {
257
276
}
258
277
259
278
Model model = (Model ) res .getContents ().get (0 );
260
-
279
+
261
280
for (JsonObject jsonObject : model .getObjects ()) {
262
281
for (Pair pair : jsonObject .getPairs ()) {
263
282
String key = pair .getString ();
@@ -272,10 +291,10 @@ private List<Object> getJSONValues(String name, File service) {
272
291
} // TODO make this recursive!
273
292
}
274
293
}
275
-
294
+
276
295
}
277
296
}
278
-
297
+
279
298
return result ;
280
299
}
281
300
0 commit comments