Package org.eclipse.epsilon.eol.models
Class CachedModel<ModelElementType>
java.lang.Object
org.eclipse.epsilon.eol.models.Model
org.eclipse.epsilon.eol.models.CachedModel<ModelElementType>
- All Implemented Interfaces:
AutoCloseable
,IModel
- Direct Known Subclasses:
AbstractEmfModel
,AbstractSimulinkModel
,BibtexModel
,CsvModel
,HtmlModel
,JdtModel
,JsonModel
,PlainXmlModel
,YamlModel
A model that performs memoization of allContents, getAllOfType
and getAllOfKind. Subclasses should implement the template
methods, which compute real values from the model
or provide keys that can be used with a
Map
.
Although the collections used here are optionally thread-safe,
subclasses should manage their own data structures according to the
isConcurrent flag. In particular, allContentsFromModel()
should
be managed appropriately by subclasses.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.epsilon.eol.models.IModel
IModel.AmbiguityCheckResult
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Collection<ModelElementType>
protected Multimap<Object,
ModelElementType> static final String
Whether to cache allOf* calls by default.static final String
Whether to use thread-safe collections by default.protected Multimap<Object,
ModelElementType> 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addToCache
(String type, ModelElementType instance) Returns a collection containing all of the objects contained in this model.protected abstract Collection<ModelElementType>
void
createInstance
(String type) protected abstract ModelElementType
createInstanceInModel
(String type) void
protected abstract boolean
deleteElementInModel
(Object instance) Returns true iff the given instance was deleted from the model.void
dispose()
protected abstract void
getAllOfKind
(String kind) protected abstract Collection<ModelElementType>
getAllOfKindFromModel
(String kind) protected Collection<ModelElementType>
getAllOfKindOrType
(boolean isKind, String modelElementType) getAllOfType
(String type) protected abstract Collection<ModelElementType>
getAllOfTypeFromModel
(String type) protected abstract Collection<String>
getAllTypeNamesOf
(Object instance) Returns the fully qualified names of every type to which the given object conforms.protected abstract 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.protected void
Sets the caches based on this model's properties.boolean
boolean
boolean
isLoaded()
Convenience method for determining when a model has been loaded.void
load()
void
load
(StringProperties properties, IRelativePathResolver resolver) protected abstract void
protected void
removeFromCache
(ModelElementType instance) void
setCachingEnabled
(boolean cachingEnabled) void
setConcurrent
(boolean concurrent) protected Collection<ModelElementType>
wrap
(Collection<ModelElementType> contents) Methods inherited from class org.eclipse.epsilon.eol.models.Model
allInstances, createInstance, getAliases, getFullyQualifiedTypeNameOf, getMetamodel, getName, getPropertyGetter, getPropertySetter, getTransactionSupport, getTypeOf, isModelElement, isOfKind, isOfType, isPropertySet, isReadOnLoad, isStoredOnDisposal, knowsAboutProperty, load, load, setName, setReadOnLoad, setStoredOnDisposal
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.epsilon.eol.models.IModel
checkAmbiguity, close, getElementById, getElementId, getEnumerationValue, getTypeNameOf, hasType, isInstantiable, owns, setElementId, store, store
-
Field Details
-
PROPERTY_CACHED
Whether to cache allOf* calls by default. False for compatibility.- See Also:
-
PROPERTY_CONCURRENT
Whether to use thread-safe collections by default. False for compatibility.- Since:
- 1.6
- See Also:
-
allContentsCache
-
typeCache
-
kindCache
-
-
Constructor Details
-
CachedModel
protected CachedModel()- Since:
- 1.6
-
-
Method Details
-
allContentsFromModel
-
getAllOfTypeFromModel
protected abstract Collection<ModelElementType> getAllOfTypeFromModel(String type) throws EolModelElementTypeNotFoundException -
getAllOfKindFromModel
protected abstract Collection<ModelElementType> getAllOfKindFromModel(String kind) throws EolModelElementTypeNotFoundException -
createInstanceInModel
protected abstract ModelElementType createInstanceInModel(String type) throws EolModelElementTypeNotFoundException, EolNotInstantiableModelElementTypeException -
loadModel
- Throws:
EolModelLoadingException
-
disposeModel
protected abstract void disposeModel() -
deleteElementInModel
Returns true iff the given instance was deleted from the model.- Throws:
EolRuntimeException
-
getCacheKeyForType
protected abstract Object getCacheKeyForType(String type) throws EolModelElementTypeNotFoundException Returns an identity for the given type, which will be used byCachedModel
as a key for the memoization of model elements by type. -
getAllTypeNamesOf
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 (getAllOfKind(String)
). -
initCaches
protected void initCaches()Sets the caches based on this model's properties. This method should only be called if there has been a change to the properties (cachingEnabled
orconcurrent
) as the caches will be reset.- Since:
- 1.6
-
setCachingEnabled
public void setCachingEnabled(boolean cachingEnabled) -
isCachingEnabled
public boolean isCachingEnabled() -
isConcurrent
public boolean isConcurrent()- Returns:
- Since:
- 1.6
-
setConcurrent
public void setConcurrent(boolean concurrent) - Parameters:
concurrent
-- Since:
- 1.6
-
wrap
- Parameters:
contents
- The model elements- Returns:
- Since:
- 1.6
-
addToCache
protected void addToCache(String type, ModelElementType instance) throws EolModelElementTypeNotFoundException -
removeFromCache
protected void removeFromCache(ModelElementType instance) throws EolModelElementTypeNotFoundException -
isLoaded
public boolean isLoaded()Convenience method for determining when a model has been loaded.- Returns:
- Whether the cache has been populated.
- Since:
- 1.6
-
allContents
Description copied from interface:IModel
Returns a collection containing all of the objects contained in this model.- Returns:
- all of the objects contained in this model.
-
getAllOfKindOrType
protected Collection<ModelElementType> getAllOfKindOrType(boolean isKind, String modelElementType) throws EolModelElementTypeNotFoundException - Parameters:
isKind
-true
if callinggetAllOfKind(String)
.modelElementType
- The name of the model element type.- Returns:
- All model elements conforming to the kind / type (depending on the flag).
- Throws:
EolModelElementTypeNotFoundException
- Since:
- 1.6
-
getAllOfType
public Collection<ModelElementType> getAllOfType(String type) throws EolModelElementTypeNotFoundException -
getAllOfKind
public Collection<ModelElementType> getAllOfKind(String kind) throws EolModelElementTypeNotFoundException -
createInstance
public ModelElementType createInstance(String type) throws EolModelElementTypeNotFoundException, EolNotInstantiableModelElementTypeException -
deleteElement
- Throws:
EolRuntimeException
-
load
- Throws:
EolModelLoadingException
-
load
public void load(StringProperties properties, IRelativePathResolver resolver) throws EolModelLoadingException - Specified by:
load
in interfaceIModel
- Overrides:
load
in classModel
- Throws:
EolModelLoadingException
-
dispose
public void dispose() -
clearCache
public void clearCache()
-