public class JsonSimpleDiscoverer
extends java.lang.Object
EPackage
elements)
from JSON documents (i.e., json file).
Once created, a metamodel out of a JsonSource
element can be discovered by
calling the method discover(JsonSource)
.
To refine a metamodel, you have to call to refine(EPackage, JsonSource)
giving the metamodel to refine and a new JsonSource
.
This implementation does not depend on Xtext (since v0.1.0)
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
DEFAULT_NS_PREFIX
Default prefix for the discovered metamodel
|
private static java.lang.String |
DEFAULT_NS_URI
Default NS URI for the discovered metamodel
|
(package private) java.util.HashMap<java.lang.String,org.eclipse.emf.ecore.EClass> |
eClasses
The set of metamodel classes discovered
|
private static java.util.logging.Logger |
LOGGER
Used to log all the activity
|
Constructor and Description |
---|
JsonSimpleDiscoverer()
Constructs a new
JsonSimpleDiscoverer element |
Modifier and Type | Method and Description |
---|---|
private org.eclipse.emf.ecore.EClass |
createMetaclass(java.lang.String id,
com.google.gson.JsonObject jsonObject)
Creates a new metaclass form scratch.
|
private void |
createStructuralFeature(java.lang.String pairId,
com.google.gson.JsonElement value,
int lowerBound,
org.eclipse.emf.ecore.EClass eClass)
Creates a new
EStructuralFeature out from a pairId/Value |
private java.lang.String |
digestId(java.lang.String id)
Generates a type identifier from a String (normally coming for the key value of JSON objects)
|
org.eclipse.emf.ecore.EPackage |
discover(JsonSource source)
Launches the metamodel discoverer from a JSON document.
|
private org.eclipse.emf.ecore.EClass |
discoverMetaclass(java.lang.String id,
com.google.gson.JsonObject jsonObject)
Discover a metaclass for a
JsonSource |
private java.util.HashMap<java.lang.String,org.eclipse.emf.ecore.EClass> |
geteClasses()
Returns the set of metamodel classes discovered
|
private org.eclipse.emf.ecore.EClassifier |
mapType(java.lang.String id,
com.google.gson.JsonElement value)
Maps JSON types into ECORE types
|
org.eclipse.emf.ecore.EPackage |
refine(org.eclipse.emf.ecore.EPackage toRefine,
JsonSource source)
Refines an existing metamodel with new JSON definitions coming from a new
JsonSource . |
private org.eclipse.emf.ecore.EClass |
refineMetaclass(org.eclipse.emf.ecore.EClass eClass,
com.google.gson.JsonObject jsonObject)
Refines the attributes and references of an existing
EClass
from a new JsonObject definition. |
private static final java.lang.String DEFAULT_NS_PREFIX
private static final java.lang.String DEFAULT_NS_URI
private static final java.util.logging.Logger LOGGER
java.util.HashMap<java.lang.String,org.eclipse.emf.ecore.EClass> eClasses
public JsonSimpleDiscoverer()
JsonSimpleDiscoverer
elementpublic org.eclipse.emf.ecore.EPackage discover(JsonSource source)
The method receives a JsonSource
element, which includes the set of JSON documents
to be considered.
The discovered metamodel is returned and also stored in the JsonSource
received as param (calling AbstractJsonSource.setMetamodel(EPackage)
).
source
- The JsonSource
including the JSON documentsEPackage
)public org.eclipse.emf.ecore.EPackage refine(org.eclipse.emf.ecore.EPackage toRefine, JsonSource source)
JsonSource
.toRefine
- The existing EPackage
to refinesource
- The JsonSource
including the JSON documentsEPackage
)private org.eclipse.emf.ecore.EClass discoverMetaclass(java.lang.String id, com.google.gson.JsonObject jsonObject)
JsonSource
id
- Unique identifier for the JsonObject
jsonObject
- the JsonObject
EClass
private org.eclipse.emf.ecore.EClass createMetaclass(java.lang.String id, com.google.gson.JsonObject jsonObject)
JsonObject
as input and
an identifier.id
- Unique identifier of the JsonObject
jsonObject
- The new JsonObject
EClass
)private org.eclipse.emf.ecore.EClass refineMetaclass(org.eclipse.emf.ecore.EClass eClass, com.google.gson.JsonObject jsonObject)
EClass
from a new JsonObject
definition.eClass
- The existing EClass
jsonObject
- The JsonObject
to use as input to refineEClass
)private void createStructuralFeature(java.lang.String pairId, com.google.gson.JsonElement value, int lowerBound, org.eclipse.emf.ecore.EClass eClass)
EStructuralFeature
out from a pairId/ValuepairId
- Identifier of the featurevalue
- JsonElement
including the valuelowerBound
- The lover bound for the structural featureeClass
- EClass
containing the featureprivate org.eclipse.emf.ecore.EClassifier mapType(java.lang.String id, com.google.gson.JsonElement value)
id
- Identifier of the feature (to infer the name of the type if non-primitive)value
- JsonElement
including the valueEClassifier
private java.lang.String digestId(java.lang.String id)
id
- String to digestprivate java.util.HashMap<java.lang.String,org.eclipse.emf.ecore.EClass> geteClasses()
EClass
elements