Skip to content

Commit 525f194

Browse files
committed
Improve support for references in refinement
git-svn-id: http://svn.codespot.com/a/eclipselabs.org/json-discoverer/trunk@15 c8cc8c90-6326-4dad-56bf-2ea2b2d31442
1 parent b14e2da commit 525f194

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

fr.inria.atlanmod.json.discoverer/src/fr/inria/atlanmod/discoverer/JsonComposer.java

+28-9
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class JsonComposer {
4444
private HashMap<String, EClass> registry;
4545
HashMap<File, List<File>> jsonFiles;
4646
HashMap<EAttribute, List<Object>> cacheValues;
47-
47+
4848
public static void main(String[] args) {
4949
JsonStandaloneSetup.doSetup();
5050

@@ -102,7 +102,10 @@ public void compose(File resultPath) {
102102
coverageCreator.createConceptMapping(eClass, duplicatedEClass);
103103
eClass = duplicatedEClass;
104104
} else {
105+
coverageCreator.createConceptMapping(eClass, registryElement);
105106
composeAttributes(registryElement, eClass, coverageCreator);
107+
composeReferences(registryElement, eClass, coverageCreator);
108+
eClass = registryElement;
106109
}
107110
for(EStructuralFeature otherFeature : eClass.getEStructuralFeatures())
108111
if (otherFeature instanceof EReference)
@@ -176,6 +179,22 @@ private void composeAttributes(EClass existingClass, EClass otherClass, Coverage
176179

177180
}
178181

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+
}
179198

180199
private EAttribute duplicateAttribute(EAttribute otherAttribute) {
181200
EAttribute newAttribute = EcoreFactory.eINSTANCE.createEAttribute();
@@ -218,7 +237,7 @@ private EClass duplicateEClass(EClass otherClass, CoverageCreator coverageCreato
218237

219238
private EAttribute lookForSimilarAttribute(EClass existingClass, EAttribute otherAttribute, CoverageCreator coverageCreator) {
220239
List<Object> jsonValues = getJSONValues(otherAttribute.getName(), coverageCreator.getFile());
221-
240+
222241
Iterator<EAttribute> it = cacheValues.keySet().iterator();
223242
while(it.hasNext()) {
224243
EAttribute eAttribute = it.next();
@@ -235,18 +254,18 @@ private EAttribute lookForSimilarAttribute(EClass existingClass, EAttribute othe
235254
}
236255
}
237256
}
238-
257+
239258
return null;
240259
}
241-
260+
242261
private List<Object> getJSONValues(String name, File service) {
243262
List<Object> result = new ArrayList<Object>();
244263
if(jsonFiles == null) return result;
245-
264+
246265
ResourceSet rset = new ResourceSetImpl();
247266
List<File> files = jsonFiles.get(service);
248267
if(files == null) return result;
249-
268+
250269
File file = files.get(0);
251270
Resource res = rset.getResource(URI.createFileURI(file.getAbsolutePath()), true);
252271

@@ -257,7 +276,7 @@ private List<Object> getJSONValues(String name, File service) {
257276
}
258277

259278
Model model = (Model) res.getContents().get(0);
260-
279+
261280
for(JsonObject jsonObject : model.getObjects()) {
262281
for(Pair pair : jsonObject.getPairs()) {
263282
String key = pair.getString();
@@ -272,10 +291,10 @@ private List<Object> getJSONValues(String name, File service) {
272291
} // TODO make this recursive!
273292
}
274293
}
275-
294+
276295
}
277296
}
278-
297+
279298
return result;
280299
}
281300

0 commit comments

Comments
 (0)