Class EnumValueModelConverter
- java.lang.Object
-
- de.hybris.platform.servicelayer.internal.converter.impl.EnumValueModelConverter
-
- All Implemented Interfaces:
ModelConverter
public class EnumValueModelConverter extends java.lang.Object implements ModelConverter
Special model converter for hybris enum values.
-
-
Constructor Summary
Constructors Constructor Description EnumValueModelConverter(java.lang.Class enumClass, SourceTransformer sourceTransformer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterDetach(java.lang.Object model, ModelContext ctx)This method is executed after the givenmodelis attached from the givenModelContextvoidbeforeAttach(java.lang.Object model, ModelContext ctx)This method is executed before the givenmodelis attached to the givenModelContextjava.lang.Objectcreate(java.lang.String type)Creates a new empty model instance.booleanequals(java.lang.Object o)protected booleanexists(HybrisEnumValue enumValue)booleanexists(java.lang.Object model)Returnstrueif for the given model a source Item exists and if this item Item#isAlive()java.lang.ObjectgetAttributeValue(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.ClassgetEnumClass()java.lang.ObjectgetLocalizedAttributeValue(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 atrributesPersistenceObjectgetPersistenceSource(java.lang.Object model)java.lang.ObjectgetSource(java.lang.Object model)Returns underlying source for given model.java.lang.StringgetType(java.lang.Object model)Returns the exact type of the given model.protected java.lang.reflect.MethodgetValueOfMethod()java.util.Set<java.lang.String>getWritablePartOfAttributes(TypeService typeService)Returns a collection of writable partof atrributesinthashCode()voidinit(ConverterRegistry registry)Called once before using the converter the first time.booleanisJavaEnum()booleanisModified(java.lang.Object model)Returnstrueif the given model is new or the ModelValueHistory of the model contains changed attributes.booleanisModified(java.lang.Object model, java.lang.String attribute)Returnstrueif the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed.booleanisModified(java.lang.Object model, java.lang.String attribute, java.util.Locale loc)Returnstrueif the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed.booleanisNew(java.lang.Object model)Returnstrueif the given model was not persisted yet.booleanisRemoved(java.lang.Object model)Returnstrueif for the given model no source Item exists or this item is not Item#isAlive()booleanisUpToDate(java.lang.Object model)The given model is not up-to-date (returnsfalse) when: the model is new (seeModelConverter.isNew(Object)) or the model was removed (seeModelConverter.isRemoved(Object)) or the model was locally modified or the Item in the database is newer as the source item of the modeljava.lang.Objectload(java.lang.Object source)Creates a new model instance and fills its attributes with data from given source objectvoidreload(java.lang.Object model)Fills the attributes of passed model new using mapped source object.voidremove(java.lang.Object model)Tries to remove the source of the given model.voidsave(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.voidsetAttributeValue(java.lang.Object model, java.lang.String attributeQualifier, java.lang.Object value)Generic attribute value setter to modify attribute data on arbitrary model instances.
-
-
-
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()
-
exists
protected boolean exists(HybrisEnumValue enumValue)
-
isJavaEnum
public boolean isJavaEnum()
-
create
public java.lang.Object create(java.lang.String type)
Description copied from interface:ModelConverterCreates a new empty model instance.- Specified by:
createin interfaceModelConverter- Returns:
- new empty model
-
getType
public java.lang.String getType(java.lang.Object model)
Description copied from interface:ModelConverterReturns the exact type of the given model.- Specified by:
getTypein interfaceModelConverter
-
getPersistenceSource
public PersistenceObject getPersistenceSource(java.lang.Object model)
- Specified by:
getPersistenceSourcein interfaceModelConverter
-
getSource
public java.lang.Object getSource(java.lang.Object model)
Description copied from interface:ModelConverterReturns underlying source for given model.- Specified by:
getSourcein interfaceModelConverter- 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:ModelConverterCalled once before using the converter the first time.- Specified by:
initin interfaceModelConverter- Parameters:
registry- the registry holding this converter.
-
load
public java.lang.Object load(java.lang.Object source)
Description copied from interface:ModelConverterCreates a new model instance and fills its attributes with data from given source object- Specified by:
loadin interfaceModelConverter- 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:ModelConverterFills the attributes of passed model new using mapped source object.- Specified by:
reloadin interfaceModelConverter- Parameters:
model- model which will be filled from scratch using mapped source
-
remove
public void remove(java.lang.Object model)
Description copied from interface:ModelConverterTries to remove the source of the given model.- Specified by:
removein interfaceModelConverter- 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:ModelConverterSaves all attribute values from the model to the wrapped source object or creates a new one if no source is mapped yet.- Specified by:
savein interfaceModelConverter- Parameters:
model- the model to save
-
isModified
public boolean isModified(java.lang.Object model)
Description copied from interface:ModelConverterReturnstrueif the given model is new or the ModelValueHistory of the model contains changed attributes.- Specified by:
isModifiedin interfaceModelConverter- Parameters:
model- the model- Returns:
falseotherwise
-
isModified
public boolean isModified(java.lang.Object model, java.lang.String attribute)Description copied from interface:ModelConverterReturnstrueif the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. If the attribute is localized the current session dataLocale(see LocaleProvider#getCurrentDataLocale()) is used.- Specified by:
isModifiedin interfaceModelConverter- Parameters:
model- the modelattribute- the attribute qualifier- Returns:
falseif 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:ModelConverterReturnstrueif the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. For localized attributes the givenLocaleis used to check for modifications. If the Locale isnullthen all Locales will be checked for modifications. For non-localized attributes the given Locale will be ignored.- Specified by:
isModifiedin interfaceModelConverter- Parameters:
model- the modelattribute- the attribute qualifierloc- the Locale. Can benull.- Returns:
falseotherwise.
-
exists
public boolean exists(java.lang.Object model)
Description copied from interface:ModelConverterReturnstrueif for the given model a source Item exists and if this item Item#isAlive()- Specified by:
existsin interfaceModelConverter- Parameters:
model- the model- Returns:
falseif 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:ModelConverterReturnstrueif for the given model no source Item exists or this item is not Item#isAlive()- Specified by:
isRemovedin interfaceModelConverter- Parameters:
model- the model- Returns:
falseif the modelModelConverter.isNew(Object)or the item is alive.
-
isNew
public boolean isNew(java.lang.Object model)
Description copied from interface:ModelConverterReturnstrueif the given model was not persisted yet.- Specified by:
isNewin interfaceModelConverter- Parameters:
model- the model- Returns:
falseif an AttributeProvider for the given model exists.
-
isUpToDate
public boolean isUpToDate(java.lang.Object model)
Description copied from interface:ModelConverterThe given model is not up-to-date (returnsfalse) 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
- Specified by:
isUpToDatein interfaceModelConverter- Parameters:
model- the model- Returns:
trueif the model is up-to-date
- the model is new (see
-
getAttributeValue
public java.lang.Object getAttributeValue(java.lang.Object model, java.lang.String attributeQualifier)Description copied from interface:ModelConverterGeneric attribute value getter to read attribute data from arbitrary model instances.- Specified by:
getAttributeValuein interfaceModelConverter- Parameters:
model- the model instanceattributeQualifier- 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:ModelConverterGeneric attribute value getter to read attribute data from arbitrary model instances.- Specified by:
getLocalizedAttributeValuein interfaceModelConverter- Parameters:
model- the model instanceattributeQualifier- the attribute qualifierlocale- 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:ModelConverterGeneric attribute value setter to modify attribute data on arbitrary model instances.- Specified by:
setAttributeValuein interfaceModelConverter- Parameters:
model- the modelattributeQualifier- the attribute qualifiervalue- the attribute value
-
beforeAttach
public void beforeAttach(java.lang.Object model, ModelContext ctx)Description copied from interface:ModelConverterThis method is executed before the givenmodelis attached to the givenModelContext- Specified by:
beforeAttachin interfaceModelConverter
-
afterDetach
public void afterDetach(java.lang.Object model, ModelContext ctx)Description copied from interface:ModelConverterThis method is executed after the givenmodelis attached from the givenModelContext- Specified by:
afterDetachin interfaceModelConverter
-
getWritablePartOfAttributes
public java.util.Set<java.lang.String> getWritablePartOfAttributes(TypeService typeService)
Description copied from interface:ModelConverterReturns a collection of writable partof atrributes- Specified by:
getWritablePartOfAttributesin interfaceModelConverter
-
getPartOfAttributes
public java.util.Set<java.lang.String> getPartOfAttributes(TypeService typeService)
Description copied from interface:ModelConverterReturns a collection of all partof atrributes- Specified by:
getPartOfAttributesin interfaceModelConverter
-
getDirtyAttributes
public java.util.Map<java.lang.String,java.util.Set<java.util.Locale>> getDirtyAttributes(java.lang.Object model)
Description copied from interface:ModelConverterReturns 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 isnullthe key is a non-localized attribute qualifier else the map value contains the locale in which language the localized attribute was modified.- Specified by:
getDirtyAttributesin interfaceModelConverter- Parameters:
model- the new (not saved) model- Returns:
- a map with all modified attribute qualifier.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-