Skip to content

Commit

Permalink
Improve support for references in refinement
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.codespot.com/a/eclipselabs.org/json-discoverer/trunk@15 c8cc8c90-6326-4dad-56bf-2ea2b2d31442
  • Loading branch information
jlcanovas committed Mar 9, 2013
1 parent b14e2da commit 525f194
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class JsonComposer {
private HashMap<String, EClass> registry;
HashMap<File, List<File>> jsonFiles;
HashMap<EAttribute, List<Object>> cacheValues;

public static void main(String[] args) {
JsonStandaloneSetup.doSetup();

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -218,7 +237,7 @@ private EClass duplicateEClass(EClass otherClass, CoverageCreator coverageCreato

private EAttribute lookForSimilarAttribute(EClass existingClass, EAttribute otherAttribute, CoverageCreator coverageCreator) {
List<Object> jsonValues = getJSONValues(otherAttribute.getName(), coverageCreator.getFile());

Iterator<EAttribute> it = cacheValues.keySet().iterator();
while(it.hasNext()) {
EAttribute eAttribute = it.next();
Expand All @@ -235,18 +254,18 @@ private EAttribute lookForSimilarAttribute(EClass existingClass, EAttribute othe
}
}
}

return null;
}

private List<Object> getJSONValues(String name, File service) {
List<Object> result = new ArrayList<Object>();
if(jsonFiles == null) return result;

ResourceSet rset = new ResourceSetImpl();
List<File> files = jsonFiles.get(service);
if(files == null) return result;

File file = files.get(0);
Resource res = rset.getResource(URI.createFileURI(file.getAbsolutePath()), true);

Expand All @@ -257,7 +276,7 @@ private List<Object> 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();
Expand All @@ -272,10 +291,10 @@ private List<Object> getJSONValues(String name, File service) {
} // TODO make this recursive!
}
}

}
}

return result;
}

Expand Down

0 comments on commit 525f194

Please sign in to comment.