public class JsonAdvancedDiscoverer
extends java.lang.Object
JsonSources (i.e., receiving a
JsonSourceSet as input). The resulting metamodels are combined to obtain a
general one.
In the context of the JSON discoverer, the JsonAdvancedDiscoverer is used to
discover the metamodel out of a set of JSON-based Web services of the same API.
Note that this process is actually a metamodel composition process, where metamodels
discovered from a set of JsonSources are analyzed to create a new one covering
all of them.
Thus, the advanced discovery process follows these steps:
JsonSources (as JsonSourceSetJsonSourceCoverageCreators are returnedThis implementation does not depend on Xtext
| Modifier and Type | Field and Description |
|---|---|
(package private) java.util.HashMap<org.eclipse.emf.ecore.EAttribute,java.util.List<java.lang.Object>> |
cacheValues
Values for discovered values
|
(package private) static double |
CLASS_MATCHING_THRESHOLD
Threshold to consider when two metamodel classes are similar.
|
private java.util.HashMap<JsonSource,CoverageCreator> |
coverageCreators
Map with the coverage for each JsonSource
|
private static java.lang.String |
DEFAULT_NS_PREFIX
Default NS URI for the discovered metamodel
|
private static java.lang.String |
DEFAULT_NS_URI
Default prefix for the discovered metamodel
|
private static java.util.logging.Logger |
LOGGER
Used to log all the activity
|
private java.util.HashMap<java.lang.String,org.eclipse.emf.ecore.EClass> |
registry
Map with the set of EClasses discovered in the resulting metamodel
|
private JsonSourceSet |
sourceSet
The set of JsonSources to use in the discovery process
|
| Constructor and Description |
|---|
JsonAdvancedDiscoverer(JsonSourceSet sourceSet)
Constructs a new
JsonAdvancedDiscoverer with a set of JsonSourceSet elements |
| Modifier and Type | Method and Description |
|---|---|
private void |
composeAttributes(org.eclipse.emf.ecore.EClass existingClass,
org.eclipse.emf.ecore.EClass otherClass,
CoverageCreator coverageCreator)
Compose the attributes of two
EClasses. |
private void |
composeEClass(org.eclipse.emf.ecore.EClass existingClass,
org.eclipse.emf.ecore.EClass otherClass,
CoverageCreator coverageCreator)
Composes two
EClasses |
private void |
composeReferences(org.eclipse.emf.ecore.EClass existingClass,
org.eclipse.emf.ecore.EClass otherClass,
CoverageCreator coverageCreator)
Compose the references of two
EClasses. |
private java.lang.String |
digestId(java.lang.String id)
Disgests an identifier (changes the first letter to uppercase and removes the possible trailing "s")
|
org.eclipse.emf.ecore.EPackage |
discover()
Launches the advanced discover process
|
org.eclipse.emf.ecore.EPackage |
discover(java.io.File resultPath)
Launches the advanced discover process
|
private org.eclipse.emf.ecore.EAttribute |
duplicateAttribute(org.eclipse.emf.ecore.EAttribute otherAttribute)
Creates a new
EAttribute and initializes it with basic information
coming from another one |
private org.eclipse.emf.ecore.EClass |
duplicateEClass(org.eclipse.emf.ecore.EClass otherClass,
CoverageCreator coverageCreator)
Duplicates a Class having into consideration its structural features.
|
private org.eclipse.emf.ecore.EReference |
duplicateReference(org.eclipse.emf.ecore.EReference otherReference)
Creates a new
EReference and initializes it with basic information
coming from another one |
private java.util.List<java.lang.Object> |
getJSONValues(org.eclipse.emf.ecore.EAttribute eAttribute,
java.lang.String sourceName)
Gets the values for a particular key
|
private org.eclipse.emf.ecore.EAttribute |
lookForSimilarAttribute(org.eclipse.emf.ecore.EClass existingClass,
org.eclipse.emf.ecore.EAttribute otherAttribute,
CoverageCreator coverageCreator)
Looks for a similar attribute in an existing
EClass. |
private org.eclipse.emf.ecore.EClass |
lookForSimilarEClass(org.eclipse.emf.ecore.EClass existingClass)
Looks for a potential already discovered
EClass which may match with the one given
as input. |
void |
saveCoverage(java.util.List<java.io.File> resultPaths)
Saves the coverage information
|
private static final java.lang.String DEFAULT_NS_URI
private static final java.lang.String DEFAULT_NS_PREFIX
private static final java.util.logging.Logger LOGGER
static final double CLASS_MATCHING_THRESHOLD
To calculate the ratio, the number of matching attributes/refereces in the two metamodel classes are compared. Thus, two metamodel classes with matching attributes/references will give a ratio of 1
private JsonSourceSet sourceSet
private java.util.HashMap<java.lang.String,org.eclipse.emf.ecore.EClass> registry
private java.util.HashMap<JsonSource,CoverageCreator> coverageCreators
java.util.HashMap<org.eclipse.emf.ecore.EAttribute,java.util.List<java.lang.Object>> cacheValues
public JsonAdvancedDiscoverer(JsonSourceSet sourceSet)
JsonAdvancedDiscoverer with a set of JsonSourceSet elementssourceSet - A JsonSourceSet to represent a set of JSON documentspublic void saveCoverage(java.util.List<java.io.File> resultPaths)
resultPaths - The path where the coverage information will be savedpublic org.eclipse.emf.ecore.EPackage discover(java.io.File resultPath)
throws java.io.FileNotFoundException
resultPath - The path where the resulting metamodel will be storedjava.io.FileNotFoundException - There is no file to read frompublic org.eclipse.emf.ecore.EPackage discover()
private void composeAttributes(org.eclipse.emf.ecore.EClass existingClass,
org.eclipse.emf.ecore.EClass otherClass,
CoverageCreator coverageCreator)
EClasses.existingClass - Discovered EClassotherClass - EClass coming from previously discovered process, to compose with the existing onecoverageCreator - Coverage manager to track changesprivate void composeReferences(org.eclipse.emf.ecore.EClass existingClass,
org.eclipse.emf.ecore.EClass otherClass,
CoverageCreator coverageCreator)
EClasses.existingClass - Discovered EClassotherClass - EClass coming from previously discovered process, to compose with the existing onecoverageCreator - Coverage manager to track changesprivate org.eclipse.emf.ecore.EAttribute duplicateAttribute(org.eclipse.emf.ecore.EAttribute otherAttribute)
EAttribute and initializes it with basic information
coming from another oneotherAttribute - Attribute to duplicateprivate org.eclipse.emf.ecore.EReference duplicateReference(org.eclipse.emf.ecore.EReference otherReference)
EReference and initializes it with basic information
coming from another oneotherReference - Reference to duplicateprivate org.eclipse.emf.ecore.EClass duplicateEClass(org.eclipse.emf.ecore.EClass otherClass,
CoverageCreator coverageCreator)
otherClass - Class to duplicatecoverageCreator - Coverage manage to track changesprivate void composeEClass(org.eclipse.emf.ecore.EClass existingClass,
org.eclipse.emf.ecore.EClass otherClass,
CoverageCreator coverageCreator)
EClassesexistingClass - Discovered EClassotherClass - EClass coming from previously discovered process, to compose with the existing onecoverageCreator - Coverage manager to track changesprivate org.eclipse.emf.ecore.EClass lookForSimilarEClass(org.eclipse.emf.ecore.EClass existingClass)
EClass which may match with the one given
as input. First, a class with the same name is searched in the set of discovered classes.
If not found, a class with a ratio of same structural features (same name) higher than
CLASS_MATCHING_THRESHOLD is searched. If not found, returns null.
Input elements (represented as EClasses named "Input") are not consideredexistingClass - EClass to check with already discovered EClassesEClass)private org.eclipse.emf.ecore.EAttribute lookForSimilarAttribute(org.eclipse.emf.ecore.EClass existingClass,
org.eclipse.emf.ecore.EAttribute otherAttribute,
CoverageCreator coverageCreator)
EClass. Only names are considered.existingClass - Class in which the attribute is searchotherAttribute - The attribute to comparecoverageCreator - The coverage manage to track changesprivate java.util.List<java.lang.Object> getJSONValues(org.eclipse.emf.ecore.EAttribute eAttribute,
java.lang.String sourceName)
eAttribute - The contained attributesourceName - The name acting as keyprivate java.lang.String digestId(java.lang.String id)
id - Identifier to digest