From 525f194a7a4290248931709344cce51ce9955399 Mon Sep 17 00:00:00 2001 From: jlcanovas Date: Sat, 9 Mar 2013 16:48:48 +0000 Subject: [PATCH] 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 --- .../atlanmod/discoverer/JsonComposer.java | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/fr.inria.atlanmod.json.discoverer/src/fr/inria/atlanmod/discoverer/JsonComposer.java b/fr.inria.atlanmod.json.discoverer/src/fr/inria/atlanmod/discoverer/JsonComposer.java index 9aa422e..4b588b1 100644 --- a/fr.inria.atlanmod.json.discoverer/src/fr/inria/atlanmod/discoverer/JsonComposer.java +++ b/fr.inria.atlanmod.json.discoverer/src/fr/inria/atlanmod/discoverer/JsonComposer.java @@ -44,7 +44,7 @@ public class JsonComposer { private HashMap registry; HashMap> jsonFiles; HashMap> cacheValues; - + public static void main(String[] args) { JsonStandaloneSetup.doSetup(); @@ -102,7 +102,10 @@ public void compose(File resultPath) { coverageCreator.createConceptMapping(eClass, duplicatedEClass); eClass = duplicatedEClass; } else { + coverageCreator.createConceptMapping(eClass, registryElement); composeAttributes(registryElement, eClass, coverageCreator); + composeReferences(registryElement, eClass, coverageCreator); + eClass = registryElement; } for(EStructuralFeature otherFeature : eClass.getEStructuralFeatures()) if (otherFeature instanceof EReference) @@ -176,6 +179,22 @@ private void composeAttributes(EClass existingClass, EClass otherClass, Coverage } + private void composeReferences(EClass existingClass, EClass otherClass, CoverageCreator coverageCreator) { + for(EStructuralFeature otherFeature : otherClass.getEStructuralFeatures()) { + if (otherFeature instanceof EReference) { + EReference otherReference = (EReference) otherFeature; + EStructuralFeature existingFeature = existingClass.getEStructuralFeature(otherReference.getName()); + if(existingFeature == null) { + EReference newReference = duplicateReference(otherReference); + existingClass.getEStructuralFeatures().add(newReference); + System.out.println("Reference " + newReference.getName() + " added"); + existingFeature = newReference; + coverageCreator.createRefMapping(otherReference, (EReference) existingFeature); + } + } + } + + } private EAttribute duplicateAttribute(EAttribute otherAttribute) { EAttribute newAttribute = EcoreFactory.eINSTANCE.createEAttribute(); @@ -218,7 +237,7 @@ private EClass duplicateEClass(EClass otherClass, CoverageCreator coverageCreato private EAttribute lookForSimilarAttribute(EClass existingClass, EAttribute otherAttribute, CoverageCreator coverageCreator) { List jsonValues = getJSONValues(otherAttribute.getName(), coverageCreator.getFile()); - + Iterator it = cacheValues.keySet().iterator(); while(it.hasNext()) { EAttribute eAttribute = it.next(); @@ -235,18 +254,18 @@ private EAttribute lookForSimilarAttribute(EClass existingClass, EAttribute othe } } } - + return null; } - + private List getJSONValues(String name, File service) { List result = new ArrayList(); if(jsonFiles == null) return result; - + ResourceSet rset = new ResourceSetImpl(); List files = jsonFiles.get(service); if(files == null) return result; - + File file = files.get(0); Resource res = rset.getResource(URI.createFileURI(file.getAbsolutePath()), true); @@ -257,7 +276,7 @@ private List getJSONValues(String name, File service) { } Model model = (Model) res.getContents().get(0); - + for(JsonObject jsonObject : model.getObjects()) { for(Pair pair : jsonObject.getPairs()) { String key = pair.getString(); @@ -272,10 +291,10 @@ private List getJSONValues(String name, File service) { } // TODO make this recursive! } } - + } } - + return result; }