Package org.eclipse.epsilon.emc.emf
Class AbstractEmfModel
- java.lang.Object
-
- org.eclipse.epsilon.eol.models.Model
-
- org.eclipse.epsilon.eol.models.CachedModel<org.eclipse.emf.ecore.EObject>
-
- org.eclipse.epsilon.emc.emf.AbstractEmfModel
-
- All Implemented Interfaces:
AutoCloseable
,IModel
- Direct Known Subclasses:
AbstractReflectiveEmfModel
,EmfMetaModel
,VirtualEmfModel
public abstract class AbstractEmfModel extends CachedModel<org.eclipse.emf.ecore.EObject>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.epsilon.eol.models.IModel
IModel.AmbiguityCheckResult
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
expand
protected org.eclipse.emf.ecore.resource.Resource
modelImpl
static String
PROPERTY_EXPAND
One of the keys used to construct the first argument toModel.load(StringProperties, String)
.static String
PROPERTY_PARALLELALLOF
Whether to perform getAllOfKind and getAllOfType operations in parallel.protected org.eclipse.emf.ecore.EPackage.Registry
registry
protected Map<Object,Object>
resourceLoadOptions
protected Map<Object,Object>
resourceStoreOptions
protected EmfModelTransactionSupport
transactionSupport
-
Fields inherited from class org.eclipse.epsilon.eol.models.CachedModel
allContentsCache, kindCache, PROPERTY_CACHED, PROPERTY_CONCURRENT, typeCache
-
Fields inherited from class org.eclipse.epsilon.eol.models.Model
aliases, ENV_PREFIX, name, PROPERTY_ALIASES, PROPERTY_NAME, PROPERTY_READONLOAD, PROPERTY_READONLY, PROPERTY_STOREONDISPOSAL, propertyGetter, propertySetter, readOnLoad, storeOnDisposal
-
-
Constructor Summary
Constructors Constructor Description AbstractEmfModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addMetamodelUri(String nsUri)
protected Collection<org.eclipse.emf.ecore.EObject>
allContentsFromModel()
IModel.AmbiguityCheckResult
checkAmbiguity(String type)
Used to test if a given type name is ambiguous or not within a model.protected Stream<org.eclipse.emf.ecore.EClass>
classesForName(String name, org.eclipse.emf.ecore.EPackage.Registry registry)
org.eclipse.emf.ecore.EClass
classForName(String name)
protected org.eclipse.emf.ecore.EClass
classForName(String name, boolean absolute, org.eclipse.emf.ecore.EPackage pkg)
protected org.eclipse.emf.ecore.EClass
classForName(String name, org.eclipse.emf.ecore.EPackage.Registry registry)
protected org.eclipse.emf.ecore.EObject
createInstanceInModel(String type)
protected boolean
deleteElementInModel(Object instance)
Returns true iff the given instance was deleted from the model.void
disposeModel()
protected Collection<org.eclipse.emf.ecore.EObject>
getAllOfKindFromModel(String kind)
protected Collection<org.eclipse.emf.ecore.EObject>
getAllOfTypeFromModel(String type)
Collection<String>
getAllTypeNamesOf(Object instance)
Returns the fully qualified names of every type to which the given object conforms.Object
getCacheKeyForType(String type)
Returns an identity for the given type, which will be used byCachedModel
as a key for the memoization of model elements by type.Object
getContainerOf(Object object)
Object
getElementById(String id)
String
getElementId(Object instance)
Object
getEnumerationValue(String enumeration, String label)
protected String
getFullyQualifiedName(org.eclipse.emf.ecore.EClassifier eClassifier)
String
getFullyQualifiedTypeNameOf(Object instance)
Returns a string representing the fully-qualified type of the instance object.protected InputStream
getInputStream(String file)
org.eclipse.emf.ecore.resource.Resource
getModelImpl()
Deprecated.UsegetResource()
insteadprotected org.eclipse.emf.ecore.EPackage.Registry
getPackageRegistry()
Get the (cached) package registry belonging to the model implementation, if no registry is available the global one is providedorg.eclipse.emf.ecore.resource.Resource
getResource()
Map<Object,Object>
getResourceLoadOptions()
protected List<org.eclipse.emf.ecore.resource.Resource>
getResources()
Map<Object,Object>
getResourceStoreOptions()
IModelTransactionSupport
getTransactionSupport()
String
getTypeNameOf(Object instance)
Returns a string representing the type of the instance object.Object
getTypeOf(Object instance)
protected boolean
hasAdapter(Class<? extends org.eclipse.emf.ecore.util.EContentAdapter> adapterType)
Determines whether this model has an adapter matching the specified type.boolean
hasType(String type)
protected void
initCaches()
Sets the caches based on this model's properties.boolean
isExpand()
boolean
isInstantiable(String type)
boolean
isLoaded()
Convenience method for determining when a model has been loaded.boolean
isModelElement(Object instance)
Used to test whether a Java object can be contained by this model.boolean
isOfKind(Object instance, String metaClass)
boolean
isOfType(Object instance, String metaClass)
boolean
isParallelAllOf()
boolean
isPropertySet(Object instance, String property)
Returnstrue
if this instance has an explicit value for this property.boolean
knowsAboutProperty(Object instance, String property)
Returnstrue
if this instance could have this property at some point.protected boolean
knowsAboutProperty(org.eclipse.emf.ecore.EObject instance, String property)
void
load(StringProperties properties, IRelativePathResolver resolver)
boolean
owns(Object instance)
Used to test whether an object is contained in this model.Object
putResourceLoadOption(Object key, Object value)
Object
putResourceStoreOption(Object key, Object value)
void
setElementId(Object instance, String newId)
void
setExpand(boolean expand)
void
setModelImpl(org.eclipse.emf.ecore.resource.Resource modelImpl)
Deprecated.UsesetResource(Resource)
insteadvoid
setParallelAllOf(boolean parallel)
void
setResource(org.eclipse.emf.ecore.resource.Resource resource)
void
setResourceLoadOptions(Map<Object,Object> options)
void
setResourceStoreOptions(Map<Object,Object> options)
boolean
store(OutputStream os)
boolean
store(String fileName)
boolean
store(org.eclipse.emf.common.util.URI uri)
void
validate()
-
Methods inherited from class org.eclipse.epsilon.eol.models.CachedModel
addToCache, allContents, clearCache, createInstance, deleteElement, dispose, getAllOfKind, getAllOfKindOrType, getAllOfType, isCachingEnabled, isConcurrent, load, loadModel, removeFromCache, setCachingEnabled, setConcurrent, wrap
-
Methods inherited from class org.eclipse.epsilon.eol.models.Model
allInstances, createInstance, getAliases, getMetamodel, getName, getPropertyGetter, getPropertySetter, isReadOnLoad, isStoredOnDisposal, load, load, setName, setReadOnLoad, setStoredOnDisposal
-
-
-
-
Field Detail
-
PROPERTY_EXPAND
public static final String PROPERTY_EXPAND
One of the keys used to construct the first argument toModel.load(StringProperties, String)
. When paired with "true", external references will be resolved during loading. Otherwise, external references are not resolved. Paired with "true" by default.- See Also:
- Constant Field Values
-
PROPERTY_PARALLELALLOF
public static final String PROPERTY_PARALLELALLOF
Whether to perform getAllOfKind and getAllOfType operations in parallel. False by default.- See Also:
- Constant Field Values
-
modelImpl
protected org.eclipse.emf.ecore.resource.Resource modelImpl
-
expand
protected boolean expand
-
registry
protected org.eclipse.emf.ecore.EPackage.Registry registry
-
transactionSupport
protected EmfModelTransactionSupport transactionSupport
-
-
Method Detail
-
initCaches
protected void initCaches()
Description copied from class:CachedModel
Sets the caches based on this model's properties. This method should only be called if there has been a change to the properties (CachedModel.cachingEnabled
orCachedModel.concurrent
) as the caches will be reset.- Overrides:
initCaches
in classCachedModel<org.eclipse.emf.ecore.EObject>
-
getInputStream
protected InputStream getInputStream(String file) throws IOException
- Throws:
IOException
-
addMetamodelUri
public void addMetamodelUri(String nsUri)
-
getPackageRegistry
protected org.eclipse.emf.ecore.EPackage.Registry getPackageRegistry()
Get the (cached) package registry belonging to the model implementation, if no registry is available the global one is provided- Returns:
- the (global) package registry
-
getEnumerationValue
public Object getEnumerationValue(String enumeration, String label) throws EolEnumerationValueNotFoundException
-
knowsAboutProperty
public boolean knowsAboutProperty(Object instance, String property)
Description copied from interface:IModel
Returnstrue
if this instance could have this property at some point.- Specified by:
knowsAboutProperty
in interfaceIModel
- Overrides:
knowsAboutProperty
in classModel
-
knowsAboutProperty
protected boolean knowsAboutProperty(org.eclipse.emf.ecore.EObject instance, String property)
-
isPropertySet
public boolean isPropertySet(Object instance, String property) throws EolRuntimeException
Description copied from interface:IModel
Returnstrue
if this instance has an explicit value for this property. This would be equivalent to eIsSet in EMF.- Specified by:
isPropertySet
in interfaceIModel
- Overrides:
isPropertySet
in classModel
- Throws:
EolRuntimeException
-
getAllOfTypeFromModel
protected Collection<org.eclipse.emf.ecore.EObject> getAllOfTypeFromModel(String type) throws EolModelElementTypeNotFoundException
- Specified by:
getAllOfTypeFromModel
in classCachedModel<org.eclipse.emf.ecore.EObject>
- Throws:
EolModelElementTypeNotFoundException
-
getAllOfKindFromModel
protected Collection<org.eclipse.emf.ecore.EObject> getAllOfKindFromModel(String kind) throws EolModelElementTypeNotFoundException
- Specified by:
getAllOfKindFromModel
in classCachedModel<org.eclipse.emf.ecore.EObject>
- Throws:
EolModelElementTypeNotFoundException
-
getCacheKeyForType
public Object getCacheKeyForType(String type) throws EolModelElementTypeNotFoundException
Description copied from class:CachedModel
Returns an identity for the given type, which will be used byCachedModel
as a key for the memoization of model elements by type.- Specified by:
getCacheKeyForType
in classCachedModel<org.eclipse.emf.ecore.EObject>
- Throws:
EolModelElementTypeNotFoundException
-
classForName
public org.eclipse.emf.ecore.EClass classForName(String name) throws EolModelElementTypeNotFoundException
-
classForName
protected org.eclipse.emf.ecore.EClass classForName(String name, org.eclipse.emf.ecore.EPackage.Registry registry)
-
classesForName
protected Stream<org.eclipse.emf.ecore.EClass> classesForName(String name, org.eclipse.emf.ecore.EPackage.Registry registry)
-
classForName
protected org.eclipse.emf.ecore.EClass classForName(String name, boolean absolute, org.eclipse.emf.ecore.EPackage pkg)
-
allContentsFromModel
protected Collection<org.eclipse.emf.ecore.EObject> allContentsFromModel()
- Specified by:
allContentsFromModel
in classCachedModel<org.eclipse.emf.ecore.EObject>
-
createInstanceInModel
protected org.eclipse.emf.ecore.EObject createInstanceInModel(String type) throws EolModelElementTypeNotFoundException, EolNotInstantiableModelElementTypeException
- Specified by:
createInstanceInModel
in classCachedModel<org.eclipse.emf.ecore.EObject>
- Throws:
EolModelElementTypeNotFoundException
EolNotInstantiableModelElementTypeException
-
getTransactionSupport
public IModelTransactionSupport getTransactionSupport()
- Specified by:
getTransactionSupport
in interfaceIModel
- Overrides:
getTransactionSupport
in classModel
-
deleteElementInModel
protected boolean deleteElementInModel(Object instance) throws EolRuntimeException
Description copied from class:CachedModel
Returns true iff the given instance was deleted from the model.- Specified by:
deleteElementInModel
in classCachedModel<org.eclipse.emf.ecore.EObject>
- Throws:
EolRuntimeException
-
owns
public boolean owns(Object instance)
Description copied from interface:IModel
Used to test whether an object is contained in this model.- Parameters:
instance
- the Java object to test.- Returns:
- true if and only if instance is contained by this model.
-
store
public boolean store(String fileName)
-
store
public boolean store(org.eclipse.emf.common.util.URI uri)
-
store
public boolean store(OutputStream os)
-
disposeModel
public void disposeModel()
- Specified by:
disposeModel
in classCachedModel<org.eclipse.emf.ecore.EObject>
-
getResource
public org.eclipse.emf.ecore.resource.Resource getResource()
-
setResource
public void setResource(org.eclipse.emf.ecore.resource.Resource resource)
-
getModelImpl
@Deprecated public org.eclipse.emf.ecore.resource.Resource getModelImpl()
Deprecated.UsegetResource()
instead
-
setModelImpl
public void setModelImpl(org.eclipse.emf.ecore.resource.Resource modelImpl)
Deprecated.UsesetResource(Resource)
instead
-
getResources
protected List<org.eclipse.emf.ecore.resource.Resource> getResources()
-
getTypeNameOf
public String getTypeNameOf(Object instance)
Description copied from interface:IModel
Returns a string representing the type of the instance object. The value returned by this function can be passed to createInstance to instantiate another object of the same type as instance.- Parameters:
instance
- The model object whose type is to be determined.- Returns:
- the name of the type of the model object, instance.
-
getFullyQualifiedTypeNameOf
public String getFullyQualifiedTypeNameOf(Object instance)
Description copied from interface:IModel
Returns a string representing the fully-qualified type of the instance object. The value returned by this function can be passed to createInstance to instantiate another object of the same type as instance.- Specified by:
getFullyQualifiedTypeNameOf
in interfaceIModel
- Overrides:
getFullyQualifiedTypeNameOf
in classModel
- Parameters:
instance
- The model object whose type is to be determined.- Returns:
- the name of the type of the model object, instance.
-
getAllTypeNamesOf
public Collection<String> getAllTypeNamesOf(Object instance)
Description copied from class:CachedModel
Returns the fully qualified names of every type to which the given object conforms. The values are used by byCachedModel
for the memoization of model elements by their kind (CachedModel.getAllOfKind(String)
).- Specified by:
getAllTypeNamesOf
in classCachedModel<org.eclipse.emf.ecore.EObject>
-
isInstantiable
public boolean isInstantiable(String type)
-
hasType
public boolean hasType(String type)
-
checkAmbiguity
public IModel.AmbiguityCheckResult checkAmbiguity(String type)
Description copied from interface:IModel
Used to test if a given type name is ambiguous or not within a model. For example, the package registry in an EMF model could include multiple EClasses with the same name.
-
hasAdapter
protected boolean hasAdapter(Class<? extends org.eclipse.emf.ecore.util.EContentAdapter> adapterType)
Determines whether this model has an adapter matching the specified type.- Parameters:
adapterType
- The adapter class.- Returns:
true
if this model's adapters contains the specified adapter type.- Since:
- 1.6
-
getFullyQualifiedName
protected String getFullyQualifiedName(org.eclipse.emf.ecore.EClassifier eClassifier)
-
isModelElement
public boolean isModelElement(Object instance)
Description copied from interface:IModel
Used to test whether a Java object can be contained by this model. For example, EMF models can contain instances of EObject, but not instances of just Object.- Specified by:
isModelElement
in interfaceIModel
- Overrides:
isModelElement
in classModel
- Parameters:
instance
- the Java object to test.- Returns:
- true if and only if instance can be contained by this model.
-
isOfKind
public boolean isOfKind(Object instance, String metaClass) throws EolModelElementTypeNotFoundException
- Specified by:
isOfKind
in interfaceIModel
- Overrides:
isOfKind
in classModel
- Throws:
EolModelElementTypeNotFoundException
-
isOfType
public boolean isOfType(Object instance, String metaClass) throws EolModelElementTypeNotFoundException
- Specified by:
isOfType
in interfaceIModel
- Overrides:
isOfType
in classModel
- Throws:
EolModelElementTypeNotFoundException
-
validate
public void validate() throws EolModelLoadingException
- Throws:
EolModelLoadingException
-
isExpand
public boolean isExpand()
-
setExpand
public void setExpand(boolean expand)
-
setParallelAllOf
public void setParallelAllOf(boolean parallel)
- Parameters:
parallel
-- Since:
- 1.6
-
isParallelAllOf
public boolean isParallelAllOf()
- Returns:
- Since:
- 1.6
-
load
public void load(StringProperties properties, IRelativePathResolver resolver) throws EolModelLoadingException
- Specified by:
load
in interfaceIModel
- Overrides:
load
in classCachedModel<org.eclipse.emf.ecore.EObject>
- Throws:
EolModelLoadingException
-
isLoaded
public boolean isLoaded()
Description copied from class:CachedModel
Convenience method for determining when a model has been loaded.- Overrides:
isLoaded
in classCachedModel<org.eclipse.emf.ecore.EObject>
- Returns:
- Whether the cache has been populated.
- Since:
- 1.6
-
setResourceLoadOptions
public void setResourceLoadOptions(Map<Object,Object> options)
- Since:
- 2.3.0
-
setResourceStoreOptions
public void setResourceStoreOptions(Map<Object,Object> options)
- Since:
- 2.3.0
-
-