org.eclipse.emf.emfstore.internal.common.model.impl
Class IdEObjectCollectionImpl

java.lang.Object
  extended by org.eclipse.emf.common.notify.impl.BasicNotifierImpl
      extended by org.eclipse.emf.ecore.impl.BasicEObjectImpl
          extended by org.eclipse.emf.ecore.impl.EObjectImpl
              extended by org.eclipse.emf.emfstore.internal.common.model.impl.IdEObjectCollectionImpl
All Implemented Interfaces:
org.eclipse.emf.common.notify.Notifier, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.InternalEObject, ESIdToEObjectMapping<ModelElementId>, ESObjectContainer<ModelElementId>, APIDelegate<ESModelElementIdToEObjectMappingImpl>, ESDisposable, IdEObjectCollection, ModelElementIdToEObjectMapping
Direct Known Subclasses:
NotifiableIdEObjectCollectionImpl

public abstract class IdEObjectCollectionImpl
extends org.eclipse.emf.ecore.impl.EObjectImpl
implements IdEObjectCollection, ESDisposable

Implementation of an ID based storage mechanism for EObjects.

Author:
emueller, mkoegel

Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.emf.common.notify.impl.BasicNotifierImpl
org.eclipse.emf.common.notify.impl.BasicNotifierImpl.EAdapterList<E extends Object & org.eclipse.emf.common.notify.Adapter>, org.eclipse.emf.common.notify.impl.BasicNotifierImpl.EObservableAdapterList
 
Nested classes/interfaces inherited from interface org.eclipse.emf.ecore.InternalEObject
org.eclipse.emf.ecore.InternalEObject.EStore
 
Field Summary
static String MODELELEMENTID_GENERATOR_CLASS_ATTRIBUTE
          The attribute identifying the class of the ESModelElementIdGenerator extension point.
static String MODELELEMENTID_GENERATOR_EXTENSIONPOINT
          The extension point id to configure the ESModelElementIdGenerator.
 
Fields inherited from class org.eclipse.emf.ecore.impl.EObjectImpl
ELAST_EOBJECT_FLAG
 
Fields inherited from interface org.eclipse.emf.ecore.InternalEObject
EOPPOSITE_FEATURE_BASE
 
Constructor Summary
IdEObjectCollectionImpl()
          Constructor.
IdEObjectCollectionImpl(org.eclipse.emf.ecore.xmi.XMIResource xmiResource)
          Constructor.
 
Method Summary
 void addModelElement(org.eclipse.emf.ecore.EObject eObject)
          Adds the given model element to the collection.
 void allocateModelElementIds(Map<org.eclipse.emf.ecore.EObject,ModelElementId> eObjectToIdMapping)
          Allocates certain IDs for the given model elements in the mapping.
 void clearAllocatedCaches()
          Clear allocated caches.
 boolean contains(org.eclipse.emf.ecore.EObject modelElement)
          Checks whether a given EObject is contained in the collection.
 boolean contains(ModelElementId id)
          Checks whether the EObject with the given ESModelElementId is contained in the collection.
<T extends IdEObjectCollection>
T
copy()
          Copies the collection.
 void deleteModelElement(org.eclipse.emf.ecore.EObject modelElement)
          Deletes the given model element from the collection.
 void disallocateModelElementIds(Set<ModelElementId> modelElementIds)
          Removes any allocated ID entries from this collection that are contained in the given set of ModelElementIds.
 void dispose()
          Marker method for classes that need to perform clean-up tasks.
 org.eclipse.emf.ecore.EObject get(ModelElementId modelElementId)
          Get the EObject for the given ESModelElementId, if any.
 Set<org.eclipse.emf.ecore.EObject> getAllModelElements()
           Returns a flat representation of all model elements in the collection.
<T extends org.eclipse.emf.ecore.EObject>
Set<T>
getAllModelElementsByClass(Class<T> modelElementClass)
          Retrieve a list of all model elements of a certain type in the collection.
<T extends org.eclipse.emf.ecore.EObject>
Set<T>
getAllModelElementsByClass(Class<T> modelElementClass, Boolean includeSubclasses)
          Retrieve a list of all model elements of a certain type in the collection.
<T extends org.eclipse.emf.ecore.EObject>
org.eclipse.emf.common.util.EList<T>
getAllModelElementsByClass(org.eclipse.emf.ecore.EClass modelElementClass, org.eclipse.emf.common.util.EList<T> list)
          Gets all model elements by class.
<T extends org.eclipse.emf.ecore.EObject>
org.eclipse.emf.common.util.EList<T>
getAllModelElementsByClass(org.eclipse.emf.ecore.EClass modelElementClass, org.eclipse.emf.common.util.EList<T> list, Boolean subclasses)
          Gets all model elements by class.
 org.eclipse.emf.ecore.EObject getDeletedModelElement(ModelElementId deletedModelElementId)
          Returns the deleted model element by means of an ID.
 ModelElementId getDeletedModelElementId(org.eclipse.emf.ecore.EObject deletedModelElement)
          Returns the ID of a deleted model element.
 String getEObjectId(org.eclipse.emf.ecore.EObject eObject)
          Returns the EObject Id.
 Map<org.eclipse.emf.ecore.EObject,String> getEObjectToIdMapping()
          Returns a copy of the EObject/ID mapping where IDs are represented as strings.
 Map<String,org.eclipse.emf.ecore.EObject> getIdToEObjectMapping()
          Returns a copy of the ID/EObject mapping where IDs are represented as strings.
 org.eclipse.emf.ecore.EObject getModelElement(ModelElementId modelElementId)
          Returns the model element with the given ESModelElementId.
 ModelElementId getModelElementId(org.eclipse.emf.ecore.EObject eObject)
          Retrieve the ESModelElementId of the given model element.
abstract  org.eclipse.emf.common.util.EList<org.eclipse.emf.ecore.EObject> getModelElements()
          Returns all directly contained model element of the container, i.e.
<T extends org.eclipse.emf.ecore.EObject>
org.eclipse.emf.common.util.EList<T>
getModelElementsByClass(org.eclipse.emf.ecore.EClass modelElementClass, org.eclipse.emf.common.util.EList<T> list)
          Gets all model elements by class.
 void initMapping()
          Initializes the ID caches of the collection, i.e.
 void initMapping(Map<org.eclipse.emf.ecore.EObject,String> eObjectToIdMap, Map<String,org.eclipse.emf.ecore.EObject> idToEObjectMap)
          /** Initializes the ID caches of the project with the given mappings.
 void removeModelElement(org.eclipse.emf.ecore.EObject modelElement)
          Removes a model element.
 void removeModelElementAndChildrenFromResource(org.eclipse.emf.ecore.EObject eObject)
          Removes the the given EObject and all its contained children from their respective XMIResources.
 
Methods inherited from class org.eclipse.emf.ecore.impl.EObjectImpl
eAdapters, eClass, eContainerFeatureID, eDeliver, eInternalContainer, eInvoke, eIsProxy, eSetClass, eSetDeliver, eSetProxyURI
 
Methods inherited from class org.eclipse.emf.ecore.impl.BasicEObjectImpl
eAllContents, eBaseStructuralFeatureID, eBasicRemoveFromContainer, eBasicRemoveFromContainerFeature, eBasicSetContainer, eContainer, eContainingFeature, eContainmentFeature, eContains, eContents, eCrossReferences, eDerivedOperationID, eDerivedOperationID, eDerivedStructuralFeatureID, eDerivedStructuralFeatureID, eDirectResource, eDynamicBasicRemoveFromContainer, eDynamicGet, eDynamicGet, eDynamicInverseAdd, eDynamicInverseRemove, eDynamicInvoke, eDynamicIsSet, eDynamicIsSet, eDynamicSet, eDynamicSet, eDynamicUnset, eDynamicUnset, eGet, eGet, eGet, eGet, eInternalResource, eInverseAdd, eInverseAdd, eInverseRemove, eInverseRemove, eInvoke, eIsSet, eIsSet, eObjectForURIFragmentSegment, eOpenGet, eOpenIsSet, eOpenSet, eOpenUnset, eProxyURI, eResolveProxy, eResource, eSet, eSet, eSetResource, eSetStore, eSetting, eStore, eUnset, eUnset, eURIFragmentSegment, eVirtualGet, eVirtualGet, eVirtualIsSet, eVirtualSet, eVirtualUnset, toString
 
Methods inherited from class org.eclipse.emf.common.notify.impl.BasicNotifierImpl
eNotificationRequired, eNotify
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.emf.ecore.EObject
eAllContents, eClass, eContainer, eContainingFeature, eContainmentFeature, eContents, eCrossReferences, eGet, eGet, eInvoke, eIsProxy, eIsSet, eResource, eSet, eUnset
 
Methods inherited from interface org.eclipse.emf.common.notify.Notifier
eAdapters, eDeliver, eNotify, eSetDeliver
 
Methods inherited from interface org.eclipse.emf.emfstore.internal.common.api.APIDelegate
createAPI, toAPI
 
Methods inherited from interface org.eclipse.emf.ecore.InternalEObject
eNotificationRequired
 

Field Detail

MODELELEMENTID_GENERATOR_EXTENSIONPOINT

public static final String MODELELEMENTID_GENERATOR_EXTENSIONPOINT
The extension point id to configure the ESModelElementIdGenerator.

See Also:
Constant Field Values

MODELELEMENTID_GENERATOR_CLASS_ATTRIBUTE

public static final String MODELELEMENTID_GENERATOR_CLASS_ATTRIBUTE
The attribute identifying the class of the ESModelElementIdGenerator extension point.

See Also:
Constant Field Values
Constructor Detail

IdEObjectCollectionImpl

public IdEObjectCollectionImpl()
Constructor.


IdEObjectCollectionImpl

public IdEObjectCollectionImpl(org.eclipse.emf.ecore.xmi.XMIResource xmiResource)
                        throws IOException
Constructor. Adds the contents of the given XMIResource as model elements to the collection. If the XMIResource also has XMI IDs assigned to the EObjects it contains, they will be used for creating the ModelElementIds within the project, if not, the ModelElementIds will get created on the fly.

Parameters:
xmiResource - a XMIResource
Throws:
IOException - if the given XMIResource could not be loaded
Method Detail

getModelElements

public abstract org.eclipse.emf.common.util.EList<org.eclipse.emf.ecore.EObject> getModelElements()
Returns all directly contained model element of the container, i.e. a hierarchical representation of the model elements.

Specified by:
getModelElements in interface ESObjectContainer<ModelElementId>
Specified by:
getModelElements in interface IdEObjectCollection
Returns:
a list containing the directly contained model elements within the container
See Also:
IdEObjectCollection.getModelElements()

addModelElement

public void addModelElement(org.eclipse.emf.ecore.EObject eObject)
Adds the given model element to the collection.

Specified by:
addModelElement in interface IdEObjectCollection
Parameters:
eObject - the model element that should be added to the collection
See Also:
IdEObjectCollection.addModelElement(org.eclipse.emf.ecore.EObject)

contains

public boolean contains(org.eclipse.emf.ecore.EObject modelElement)
Checks whether a given EObject is contained in the collection.

Specified by:
contains in interface ESObjectContainer<ModelElementId>
Specified by:
contains in interface IdEObjectCollection
Parameters:
modelElement - the model element to be checked, whether it is contained in the collection
Returns:
true, if the model element is contained in the collection, false otherwise
See Also:
IdEObjectCollection.contains(org.eclipse.emf.ecore.EObject)

contains

public boolean contains(ModelElementId id)
Checks whether the EObject with the given ESModelElementId is contained in the collection.

Specified by:
contains in interface ESObjectContainer<ModelElementId>
Specified by:
contains in interface IdEObjectCollection
Parameters:
id - the model element ID of the EObject, which needs to be checked, whether it is contained in the collection
Returns:
true, if the EObject with the given model element ID is contained in the collection, false
See Also:
IdEObjectCollection.contains(org.eclipse.emf.emfstore.internal.common.model.ModelElementId)

getDeletedModelElementId

public ModelElementId getDeletedModelElementId(org.eclipse.emf.ecore.EObject deletedModelElement)
Returns the ID of a deleted model element. NOTE: If commands are used, IDs of deleted model elements are only available during command execution. If commands aren't used IDs of deleted model elements remain as long available until either a share, a commit or an update happens.

Parameters:
deletedModelElement - the model element that has been deleted
Returns:
the ID of the deleted model element or null if no such ID exists

getDeletedModelElement

public org.eclipse.emf.ecore.EObject getDeletedModelElement(ModelElementId deletedModelElementId)
Returns the deleted model element by means of an ID. NOTE: If commands are used, deleted model elements are only available during command execution. If commands aren't used IDs of deleted model elements remain as long available until either a share, a commit or an update happens.

Parameters:
deletedModelElementId - the ID of an already deleted model element
Returns:
the deleted model element or null if no such element exists

getModelElementId

public ModelElementId getModelElementId(org.eclipse.emf.ecore.EObject eObject)
Retrieve the ESModelElementId of the given model element.

Specified by:
getModelElementId in interface ESObjectContainer<ModelElementId>
Specified by:
getModelElementId in interface IdEObjectCollection
Parameters:
eObject - the model element for which to retrieve the ID for
Returns:
the ESModelElementId of the given model element
See Also:
IdEObjectCollection.getModelElementId(org.eclipse.emf.ecore.EObject)

getModelElement

public org.eclipse.emf.ecore.EObject getModelElement(ModelElementId modelElementId)
Returns the model element with the given ESModelElementId.

Specified by:
getModelElement in interface ESObjectContainer<ModelElementId>
Specified by:
getModelElement in interface IdEObjectCollection
Parameters:
modelElementId - the ID of the model element, that should be retrieved
Returns:
the model element that has the given ID assigned to it within the container
See Also:
IdEObjectCollection.getModelElement(org.eclipse.emf.emfstore.internal.common.model.ModelElementId)

deleteModelElement

public void deleteModelElement(org.eclipse.emf.ecore.EObject modelElement)
Deletes the given model element from the collection.

Specified by:
deleteModelElement in interface IdEObjectCollection
Parameters:
modelElement - the model element that should get deleted
See Also:
IdEObjectCollection.deleteModelElement(org.eclipse.emf.ecore.EObject)

removeModelElementAndChildrenFromResource

public void removeModelElementAndChildrenFromResource(org.eclipse.emf.ecore.EObject eObject)
Removes the the given EObject and all its contained children from their respective XMIResources.

Parameters:
eObject - the EObject to remove

getAllModelElements

public Set<org.eclipse.emf.ecore.EObject> getAllModelElements()

Returns a flat representation of all model elements in the collection.

The returned set is not modifiable and will throw an UnsupportedOperationException in case trying to do so.

Specified by:
getAllModelElements in interface ESObjectContainer<ModelElementId>
Specified by:
getAllModelElements in interface IdEObjectCollection
Returns:
a set of all model elements contained in the collection
See Also:
IdEObjectCollection.getAllModelElements()

getAllModelElementsByClass

public <T extends org.eclipse.emf.ecore.EObject> org.eclipse.emf.common.util.EList<T> getAllModelElementsByClass(org.eclipse.emf.ecore.EClass modelElementClass,
                                                                                                                 org.eclipse.emf.common.util.EList<T> list)
Gets all model elements by class.

Type Parameters:
T - type
Parameters:
modelElementClass - the EClass
list - the list of model elements
Returns:
the model elements matching the class

getModelElementsByClass

public <T extends org.eclipse.emf.ecore.EObject> org.eclipse.emf.common.util.EList<T> getModelElementsByClass(org.eclipse.emf.ecore.EClass modelElementClass,
                                                                                                              org.eclipse.emf.common.util.EList<T> list)
Gets all model elements by class.

Specified by:
getModelElementsByClass in interface IdEObjectCollection
Type Parameters:
T - type
Parameters:
modelElementClass - the EClass
list - the list of model elements
Returns:
the model elements matching the class

getAllModelElementsByClass

public <T extends org.eclipse.emf.ecore.EObject> org.eclipse.emf.common.util.EList<T> getAllModelElementsByClass(org.eclipse.emf.ecore.EClass modelElementClass,
                                                                                                                 org.eclipse.emf.common.util.EList<T> list,
                                                                                                                 Boolean subclasses)
Gets all model elements by class.

Type Parameters:
T - type
Parameters:
modelElementClass - the EClass
list - the list of model elements
subclasses - whether to use subclasses
Returns:
the model elements matching the class

getAllModelElementsByClass

public <T extends org.eclipse.emf.ecore.EObject> Set<T> getAllModelElementsByClass(Class<T> modelElementClass)
Retrieve a list of all model elements of a certain type in the collection.

Specified by:
getAllModelElementsByClass in interface ESObjectContainer<ModelElementId>
Type Parameters:
T - the type of the model element(s) to be retrieved
Parameters:
modelElementClass - the Class of the model element(s) to be retrieved
Returns:
a list of model elements of the given type
See Also:
ESObjectContainer.getAllModelElementsByClass(java.lang.Class)

getAllModelElementsByClass

public <T extends org.eclipse.emf.ecore.EObject> Set<T> getAllModelElementsByClass(Class<T> modelElementClass,
                                                                                   Boolean includeSubclasses)
Retrieve a list of all model elements of a certain type in the collection.

Specified by:
getAllModelElementsByClass in interface ESObjectContainer<ModelElementId>
Type Parameters:
T - the type of the model element(s) to be retrieved
Parameters:
modelElementClass - the Class of the model element(s) to be retrieved
includeSubclasses - whether to also include all subclasses of the given Class in the list
Returns:
a list of model elements of the given type
See Also:
ESObjectContainer.getAllModelElementsByClass(java.lang.Class, java.lang.Boolean)

initMapping

public void initMapping()
Initializes the ID caches of the collection, i.e. the collection will call IdEObjectCollection.getModelElements() and for each model element the ModelElementId is fetched via IdEObjectCollection.getModelElementId(EObject). Then a mapping between the model element and its ModelElementId is created within the cache.

Specified by:
initMapping in interface IdEObjectCollection
See Also:
IdEObjectCollection.initMapping()

initMapping

public void initMapping(Map<org.eclipse.emf.ecore.EObject,String> eObjectToIdMap,
                        Map<String,org.eclipse.emf.ecore.EObject> idToEObjectMap)
/** Initializes the ID caches of the project with the given mappings.

Specified by:
initMapping in interface IdEObjectCollection
Parameters:
eObjectToIdMap - a mapping from EObjects to IDs
idToEObjectMap - the reverse mapping of eObjectToIdMap
See Also:
IdEObjectCollection.initMapping(java.util.Map, java.util.Map)

copy

public <T extends IdEObjectCollection> T copy()
Copies the collection.

Type Parameters:
T - a collection type
Returns:
the copied collection instance

dispose

public void dispose()
Marker method for classes that need to perform clean-up tasks.

Specified by:
dispose in interface ESDisposable
See Also:
ESDisposable.dispose()

allocateModelElementIds

public void allocateModelElementIds(Map<org.eclipse.emf.ecore.EObject,ModelElementId> eObjectToIdMapping)
Allocates certain IDs for the given model elements in the mapping. If any EObject contained in the mapping is added to this collection its ModelElementId will be determined using the ID in the mapping.

Specified by:
allocateModelElementIds in interface IdEObjectCollection
Parameters:
eObjectToIdMapping - A map containing ModelElementIds for the model element and its children
See Also:
IdEObjectCollection.allocateModelElementIds(java.util.Map)

disallocateModelElementIds

public void disallocateModelElementIds(Set<ModelElementId> modelElementIds)
Removes any allocated ID entries from this collection that are contained in the given set of ModelElementIds.

Specified by:
disallocateModelElementIds in interface IdEObjectCollection
Parameters:
modelElementIds - the set of model element IDs to be released
See Also:
IdEObjectCollection.disallocateModelElementIds(java.util.Set)

clearAllocatedCaches

public void clearAllocatedCaches()
Clear allocated caches.

Specified by:
clearAllocatedCaches in interface IdEObjectCollection
See Also:
IdEObjectCollection.clearAllocatedCaches()

getEObjectId

public String getEObjectId(org.eclipse.emf.ecore.EObject eObject)
Returns the EObject Id.

Parameters:
eObject - the eobject
Returns:
the id or null if there is no model element id

get

public org.eclipse.emf.ecore.EObject get(ModelElementId modelElementId)
Get the EObject for the given ESModelElementId, if any.

Specified by:
get in interface ESIdToEObjectMapping<ModelElementId>
Parameters:
modelElementId - the ID
Returns:
the object or null if no EObject for the ID is found
See Also:
ESIdToEObjectMapping.get(java.lang.Object)

getIdToEObjectMapping

public Map<String,org.eclipse.emf.ecore.EObject> getIdToEObjectMapping()
Returns a copy of the ID/EObject mapping where IDs are represented as strings. This method is mainly provided for convenience and performance reasons, where the ID must be a string.

Specified by:
getIdToEObjectMapping in interface IdEObjectCollection
Returns:
the ID/EObject mapping
See Also:
IdEObjectCollection.getIdToEObjectMapping()

getEObjectToIdMapping

public Map<org.eclipse.emf.ecore.EObject,String> getEObjectToIdMapping()
Returns a copy of the EObject/ID mapping where IDs are represented as strings. This method is mainly provided for convenience and performance reasons, where the ID must be a string.

Specified by:
getEObjectToIdMapping in interface IdEObjectCollection
Returns:
the EObject/ID mapping
See Also:
IdEObjectCollection.getEObjectToIdMapping()

removeModelElement

public void removeModelElement(org.eclipse.emf.ecore.EObject modelElement)
Removes a model element.

Parameters:
modelElement - the element to remove


Copyright © 2015. All Rights Reserved.