Class Mapper

  • Direct Known Subclasses:
    QlMapper

    public abstract class Mapper
    extends Object
    A useful superclass for mapper implementations. Can be used to implement a many-to-many mapping between EObjects based on EMF Adapter mechanism.

    Subclasses must implement the newMapping(Class) method to instantiate the language-specific Mapper.Mappings. Subclasses should also provide a language-specific API for working with mappings.

    • Constructor Detail

      • Mapper

        public Mapper()
    • Method Detail

      • newMapping

        protected abstract <T extends Mapper.Mapping> T newMapping​(Class<T> mappingType)
        Returns a new mapping object of the given type.
        Parameters:
        mappingType - the type of the mapping (not null)
        Returns:
        a new mapping object of the given type (never null)
        Throws:
        IllegalArgumentException - if the mapper does not support mappings of the given type
      • getMapping

        protected <T extends Mapper.Mapping> T getMapping​(org.eclipse.emf.ecore.EObject eObject,
                                                          Class<T> mappingType,
                                                          boolean createOnDemand)
        Returns a mapping object of the given type associated with the given object. Uses newMapping(Class) if mapping creation is necessary.
        Parameters:
        eObject - the object (not null)
        mappingType - the type of the mapping (not null)
        createOnDemand - whether the mapping object should be created if not found
        Returns:
        the requested mapping object, or null if it is not found and createOnDemand is false
      • getMappedObjects

        protected Set<org.eclipse.emf.ecore.EObject> getMappedObjects​(org.eclipse.emf.ecore.EObject eObject,
                                                                      Class<? extends Mapper.Mapping> mappingType)
        Returns the set of mapped objects for the given object and the given type of mapping. The result is a copy of the actual list of mapped objects stored in the mapping and can be modified safely by the client. The set has the same iteration order as the original list. The first element of the set is the primary mapped object at the time of the invocation.
        Parameters:
        eObject - the object (not null)
        mappingType - the type of the mapping (not null)
        Returns:
        the set of mapped objects (never null)
      • getPrimaryMappedObject

        protected org.eclipse.emf.ecore.EObject getPrimaryMappedObject​(org.eclipse.emf.ecore.EObject eObject,
                                                                       Class<? extends Mapper.Mapping> mappingType)
        Returns the primary mapped object for the given object and the given type of mapping. The primary mapped object is the first element of the list of mapped objects stored in the mapping.
        Parameters:
        eObject - the object (not null)
        mappingType - the type of the mapping (not null)
        Returns:
        the primary mapped object, or null if no mapping is found or the list of mapped objects is empty.
      • unsetMapping

        protected void unsetMapping​(org.eclipse.emf.ecore.EObject eObject,
                                    Class<? extends Mapper.Mapping> mappingType)
        Disassociates the mapping object of the given type from the given object. Does nothing if such a mapping object is not found.
        Parameters:
        eObject - the object (not null)
        mappingType - the type of the mapping (not null)