Class EnumValueModelConverter

  • All Implemented Interfaces:
    ModelConverter

    public class EnumValueModelConverter
    extends java.lang.Object
    implements ModelConverter
    Special model converter for hybris enum values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterDetach​(java.lang.Object model, ModelContext ctx)
      This method is executed after the given model is attached from the given ModelContext
      void beforeAttach​(java.lang.Object model, ModelContext ctx)
      This method is executed before the given model is attached to the given ModelContext
      java.lang.Object create​(java.lang.String type)
      Creates a new empty model instance.
      boolean equals​(java.lang.Object o)  
      protected boolean exists​(HybrisEnumValue enumValue)  
      boolean exists​(java.lang.Object model)
      Returns true if for the given model a source Item exists and if this item Item#isAlive()
      java.lang.Object getAttributeValue​(java.lang.Object model, java.lang.String attributeQualifier)
      Generic attribute value getter to read attribute data from arbitrary model instances.
      java.util.Map<java.lang.String,​java.util.Set<java.util.Locale>> getDirtyAttributes​(java.lang.Object model)
      Returns a map with all modified attribute qualifiers for the given model.
      java.lang.Class getEnumClass()  
      java.lang.Object getLocalizedAttributeValue​(java.lang.Object model, java.lang.String attributeQualifier, java.util.Locale locale)
      Generic attribute value getter to read attribute data from arbitrary model instances.
      java.util.Set<java.lang.String> getPartOfAttributes​(TypeService typeService)
      Returns a collection of all partof atrributes
      PersistenceObject getPersistenceSource​(java.lang.Object model)  
      java.lang.Object getSource​(java.lang.Object model)
      Returns underlying source for given model.
      java.lang.String getType​(java.lang.Object model)
      Returns the exact type of the given model.
      protected java.lang.reflect.Method getValueOfMethod()  
      java.util.Set<java.lang.String> getWritablePartOfAttributes​(TypeService typeService)
      Returns a collection of writable partof atrributes
      int hashCode()  
      void init​(ConverterRegistry registry)
      Called once before using the converter the first time.
      boolean isJavaEnum()  
      boolean isModified​(java.lang.Object model)
      Returns true if the given model is new or the ModelValueHistory of the model contains changed attributes.
      boolean isModified​(java.lang.Object model, java.lang.String attribute)
      Returns true if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed.
      boolean isModified​(java.lang.Object model, java.lang.String attribute, java.util.Locale loc)
      Returns true if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed.
      boolean isNew​(java.lang.Object model)
      Returns true if the given model was not persisted yet.
      boolean isRemoved​(java.lang.Object model)
      Returns true if for the given model no source Item exists or this item is not Item#isAlive()
      boolean isUpToDate​(java.lang.Object model)
      The given model is not up-to-date (returns false) when: the model is new (see ModelConverter.isNew(Object)) or the model was removed (see ModelConverter.isRemoved(Object)) or the model was locally modified or the Item in the database is newer as the source item of the model
      java.lang.Object load​(java.lang.Object source)
      Creates a new model instance and fills its attributes with data from given source object
      void reload​(java.lang.Object model)
      Fills the attributes of passed model new using mapped source object.
      void remove​(java.lang.Object model)
      Tries to remove the source of the given model.
      void save​(java.lang.Object model, java.util.Collection<java.lang.String> excluded)
      Saves all attribute values from the model to the wrapped source object or creates a new one if no source is mapped yet.
      void setAttributeValue​(java.lang.Object model, java.lang.String attributeQualifier, java.lang.Object value)
      Generic attribute value setter to modify attribute data on arbitrary model instances.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EnumValueModelConverter

        public EnumValueModelConverter​(java.lang.Class enumClass,
                                       SourceTransformer sourceTransformer)
    • Method Detail

      • getEnumClass

        public java.lang.Class getEnumClass()
      • getValueOfMethod

        protected java.lang.reflect.Method getValueOfMethod()
      • isJavaEnum

        public boolean isJavaEnum()
      • create

        public java.lang.Object create​(java.lang.String type)
        Description copied from interface: ModelConverter
        Creates a new empty model instance.
        Specified by:
        create in interface ModelConverter
        Returns:
        new empty model
      • getType

        public java.lang.String getType​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns the exact type of the given model.
        Specified by:
        getType in interface ModelConverter
      • getSource

        public java.lang.Object getSource​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns underlying source for given model.
        Specified by:
        getSource in interface ModelConverter
        Parameters:
        model - the model for which to return the source
        Returns:
        the underlying source of the given model, or null if the source doesn't (yet) exist
      • init

        public void init​(ConverterRegistry registry)
        Description copied from interface: ModelConverter
        Called once before using the converter the first time.
        Specified by:
        init in interface ModelConverter
        Parameters:
        registry - the registry holding this converter.
      • load

        public java.lang.Object load​(java.lang.Object source)
        Description copied from interface: ModelConverter
        Creates a new model instance and fills its attributes with data from given source object
        Specified by:
        load in interface ModelConverter
        Parameters:
        source - object which will be used for filling new model
        Returns:
        new model instance with data of given source
      • reload

        public void reload​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Fills the attributes of passed model new using mapped source object.
        Specified by:
        reload in interface ModelConverter
        Parameters:
        model - model which will be filled from scratch using mapped source
      • remove

        public void remove​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Tries to remove the source of the given model.
        Specified by:
        remove in interface ModelConverter
        Parameters:
        model - the model for which to remove the source
      • save

        public void save​(java.lang.Object model,
                         java.util.Collection<java.lang.String> excluded)
        Description copied from interface: ModelConverter
        Saves all attribute values from the model to the wrapped source object or creates a new one if no source is mapped yet.
        Specified by:
        save in interface ModelConverter
        Parameters:
        model - the model to save
      • isModified

        public boolean isModified​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns true if the given model is new or the ModelValueHistory of the model contains changed attributes.
        Specified by:
        isModified in interface ModelConverter
        Parameters:
        model - the model
        Returns:
        false otherwise
      • isModified

        public boolean isModified​(java.lang.Object model,
                                  java.lang.String attribute)
        Description copied from interface: ModelConverter
        Returns true if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. If the attribute is localized the current session data Locale (see LocaleProvider#getCurrentDataLocale()) is used.
        Specified by:
        isModified in interface ModelConverter
        Parameters:
        model - the model
        attribute - the attribute qualifier
        Returns:
        false if the attribute was not modified.
      • isModified

        public boolean isModified​(java.lang.Object model,
                                  java.lang.String attribute,
                                  java.util.Locale loc)
        Description copied from interface: ModelConverter
        Returns true if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. For localized attributes the given Locale is used to check for modifications. If the Locale is null then all Locales will be checked for modifications. For non-localized attributes the given Locale will be ignored.
        Specified by:
        isModified in interface ModelConverter
        Parameters:
        model - the model
        attribute - the attribute qualifier
        loc - the Locale. Can be null.
        Returns:
        false otherwise.
      • exists

        public boolean exists​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns true if for the given model a source Item exists and if this item Item#isAlive()
        Specified by:
        exists in interface ModelConverter
        Parameters:
        model - the model
        Returns:
        false if the model was not persisted yet (no underlying item) or the item was removed.
      • isRemoved

        public boolean isRemoved​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns true if for the given model no source Item exists or this item is not Item#isAlive()
        Specified by:
        isRemoved in interface ModelConverter
        Parameters:
        model - the model
        Returns:
        false if the model ModelConverter.isNew(Object) or the item is alive.
      • isNew

        public boolean isNew​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns true if the given model was not persisted yet.
        Specified by:
        isNew in interface ModelConverter
        Parameters:
        model - the model
        Returns:
        false if an AttributeProvider for the given model exists.
      • isUpToDate

        public boolean isUpToDate​(java.lang.Object model)
        Description copied from interface: ModelConverter
        The given model is not up-to-date (returns false) when:
        Specified by:
        isUpToDate in interface ModelConverter
        Parameters:
        model - the model
        Returns:
        true if the model is up-to-date
      • getAttributeValue

        public java.lang.Object getAttributeValue​(java.lang.Object model,
                                                  java.lang.String attributeQualifier)
        Description copied from interface: ModelConverter
        Generic attribute value getter to read attribute data from arbitrary model instances.
        Specified by:
        getAttributeValue in interface ModelConverter
        Parameters:
        model - the model instance
        attributeQualifier - the attribute qualifier
        Returns:
        the attribute value
      • getLocalizedAttributeValue

        public java.lang.Object getLocalizedAttributeValue​(java.lang.Object model,
                                                           java.lang.String attributeQualifier,
                                                           java.util.Locale locale)
        Description copied from interface: ModelConverter
        Generic attribute value getter to read attribute data from arbitrary model instances.
        Specified by:
        getLocalizedAttributeValue in interface ModelConverter
        Parameters:
        model - the model instance
        attributeQualifier - the attribute qualifier
        locale - Locale for which value will be returned
        Returns:
        the attribute value
      • setAttributeValue

        public void setAttributeValue​(java.lang.Object model,
                                      java.lang.String attributeQualifier,
                                      java.lang.Object value)
        Description copied from interface: ModelConverter
        Generic attribute value setter to modify attribute data on arbitrary model instances.
        Specified by:
        setAttributeValue in interface ModelConverter
        Parameters:
        model - the model
        attributeQualifier - the attribute qualifier
        value - the attribute value
      • getDirtyAttributes

        public java.util.Map<java.lang.String,​java.util.Set<java.util.Locale>> getDirtyAttributes​(java.lang.Object model)
        Description copied from interface: ModelConverter
        Returns a map with all modified attribute qualifiers for the given model. The keys are all localized and non-localized attribute qualifier which were modified. If the map value is null the key is a non-localized attribute qualifier else the map value contains the locale in which language the localized attribute was modified.
        Specified by:
        getDirtyAttributes in interface ModelConverter
        Parameters:
        model - the new (not saved) model
        Returns:
        a map with all modified attribute qualifier.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object