Class ItemModelConverter
- java.lang.Object
-
- de.hybris.platform.servicelayer.internal.converter.impl.ItemModelConverter
-
- All Implemented Interfaces:
TypeSystemAwareModelConverter,UpdateableModelConverter,ModelConverter,java.lang.Cloneable
- Direct Known Subclasses:
PrefetchAllModelConverter,VariantProductModelConverter
public class ItemModelConverter extends java.lang.Object implements java.lang.Cloneable, UpdateableModelConverter, TypeSystemAwareModelConverter
This is a generalModelConverterimplementation which should be working for almost everyAbstractItemModel. Using theItemModelConverter(ModelService, I18NService, CommonI18NService, String, Class, SerializationStrategy, SourceTransformer, SelfHealingService)constructor you specify which source Item class you want to use (e.g. Product, this will be used for compatibility checks inload(Object)) and which ItemModel class will be created if you load such an item usingload(Object). If you need functionality which is beyond this simple implementation, you will have to provide your own ItemModel implementation. This class is an internal API and is subject to change without further notice
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classItemModelConverter.AttributesToLoadprotected static classItemModelConverter.LoadedAttributeValuesstatic classItemModelConverter.ModelAttributeInfoclassItemModelConverter.ModifiedAttributeValuesstatic classItemModelConverter.RelationTypeAttributeInfostatic classItemModelConverter.TypeAttributeInfoprotected static classItemModelConverter.TypeMetaInfoThis class is an internal API and is subject to change without further notice
-
Constructor Summary
Constructors Constructor Description ItemModelConverter(ModelService modelService, I18NService i18nService, CommonI18NService commonI18NService, java.lang.String type, java.lang.Class<? extends AbstractItemModel> modelClass, SerializationStrategy serializationStrategy)For backward compatibilityItemModelConverter(ModelService modelService, I18NService i18nService, CommonI18NService commonI18NService, java.lang.String type, java.lang.Class<? extends AbstractItemModel> modelClass, SerializationStrategy serializationStrategy, SourceTransformer sourceTransformer, SelfHealingService selfHealingService)Constructs a newItemModelConverterinstance which handles beans of given class type related to given composed type.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddModelModificationListener(java.lang.Object model, ModelModificationListener listener)Adds the givenModelModificationListenerto the given model.voidafterDetach(java.lang.Object model, ModelContext ctx)This method is executed after the givenmodelis attached from the givenModelContextvoidafterModification(AbstractItemModel model, PK pk, long persistenceVersion)protected ItemModelConverter.TypeMetaInfoassembleMetaInfo(ComposedType ct, java.util.Collection<ItemModelConverter.TypeAttributeInfo> attributes)InitializesItemModelConverter.TypeMetaInfo._modelAttributesAllandItemModelConverter.TypeMetaInfo._modelAttributesInitialusing attribute meta infos.voidbeforeAttach(java.lang.Object model, ModelContext ctx)This method is executed before the givenmodelis attached to the givenModelContextprotected java.util.Collection<ItemModelConverter.TypeAttributeInfo>calculateTypeAttributeInfos(ComposedType ct)Calculates attribute meta info objects for a given composed type.protected voidclearAttribute(AbstractItemModel model, java.lang.String qualifier)protected voidclearLocAttribute(AbstractItemModel model, java.lang.String qualifier, java.util.Locale loc)protected java.lang.ObjectconvertModelsToObjects(AbstractItemModel model, java.lang.String qualifier, java.lang.Object value)Checks if the given object is a model, a collection of models, or a map with models and tries to convert them to related source object.protected java.lang.ObjectconvertObjectsToModels(PersistenceObject item, java.lang.String qualifier, java.lang.Object value)Tries to convert given object, collection of objects or map of objects to related model instances.AbstractItemModelcreate(java.lang.String type)Instantiates a new instance of configured model class.protected ItemModelInternalContextcreateContextForExistingModel(java.lang.String type, PK pk, long persistenceVersion, AttributeProvider attributeProvider)protected ItemModelInternalContextcreateContextForNewModel(java.lang.String type)protected ItemModelConverter.ModelAttributeInfocreateModelAttributeInfo(ItemModelConverter.TypeAttributeInfo info)This method is an internal API and is subject to change without further noticeprotected AbstractItemModelcreateModelInstance(ItemModelInternalContext ctx)protected PersistenceObjectcreateNewItem(AbstractItemModel model, ItemModelConverter.ModifiedAttributeValues values)Performs item creation.booleanequals(java.lang.Object o)booleanexists(java.lang.Object model)Returnstrueif for the given model a source Item exists and if this item Item#isAlive()protected voidfillModel(AbstractItemModel model, ItemModelConverter.AttributesToLoad attributesToLoad, PersistenceObject item)Loads and fills model instance with loaded attribute values.java.util.List<ItemModelConverter.ModelAttributeInfo>getAllModelAttributes()protected ItemModelConverter.AttributesToLoadgetAttributesToReload(AbstractItemModel model, ItemModelConverter.ModifiedAttributeValues savedValues, boolean forCreation)java.lang.ObjectgetAttributeValue(java.lang.Object model, java.lang.String attributeQualifier)Generic attribute value getter to read attribute data from arbitrary model instances.protected CommonI18NServicegetCommonI18NService()protected ComposedTypegetComposedType(AbstractItemModel model)protected ConfigIntfgetConfig()Encapsulates fetching ofConfigIntf.java.lang.StringgetDefaultType()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.ObjectgetDirtyAttributeValue(java.lang.Object model, java.lang.String attributeQualifier)Internal method forDefaultModelServicewhen inspecting dirty attributes during save!protected java.util.Set<java.lang.String>getDirtyLocalizedAttributesWithNonDataLocales(java.util.Map<java.util.Locale,java.util.Set<java.lang.String>> dirtyLocalizedAttributes, java.util.Map<java.util.Locale,java.util.Set<java.util.Locale>> dataLocale2NonDataLocales)java.lang.ObjectgetDirtyLocalizedAttributeValue(java.lang.Object model, java.lang.String attributeQualifier, java.util.Locale locale)Internal method forDefaultModelServicewhen inspecting dirty attributes during save!protected DynamicAttributesProvidergetDynamicAttributesProvider()protected java.util.Set<ItemModelConverter.ModelAttributeInfo>getExcluded(java.util.Collection<java.lang.String> excluded)protected java.lang.ObjectgetFieldValue(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)protected java.lang.reflect.MethodgetGetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)protected I18NServicegetI18nService()ItemModelConverter.ModelAttributeInfogetInfo(java.lang.String qualfier)java.util.List<ItemModelConverter.ModelAttributeInfo>getInitialModelAttributes()protected LocaleProvidergetLocaleProvider()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.protected java.lang.reflect.MethodgetLocalizedGetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)protected java.lang.reflect.MethodgetLocalizedSetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info, java.lang.Object value)java.util.Set<java.lang.String>getMandatoryAttributes()java.util.Set<java.lang.String>getMandatoryAttributesForCreation()java.lang.Class<? extends AbstractItemModel>getModelClass()Gets the class used for instantiation of related models.protected ModelServicegetModelService()java.util.Set<java.lang.String>getPartOfAttributes(TypeService typeService)Returns a collection of all partof atrributesPersistenceObjectgetPersistenceSource(java.lang.Object model)SerializationStrategygetSerializationStrategy()protected java.lang.reflect.MethodgetSetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info, java.lang.Object value)java.lang.ObjectgetSource(java.lang.Object model)Deprecated.since 5.7.0 - Please usegetPersistenceSource(Object)protected java.util.LocalegetStdLocale()java.lang.StringgetType(java.lang.Object model)Returns the exact type of the given model.protected java.lang.StringgetTypeFromModelContext(java.lang.Object model)java.util.Set<java.lang.String>getUniqueAttributes()java.util.Set<java.lang.String>getWritablePartOfAttributes(TypeService typeService)Returns a collection of writable partof atrributesinthashCode()protected booleanhasNonDataLocales(java.util.Map<java.util.Locale,java.util.Set<java.util.Locale>> dataLocale2LocaleMappings)voidinit(ConverterRegistry registry)Called once before using the converter the first time.booleanisConfiguredForLegacyPersistence()protected booleanisEnumValue(java.lang.Object value)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.protected booleanisNonLazyLoadedAttribute(AttributeDescriptor desc)Tells whether or not a attribute should be lazy loaded.protected booleanisReferenceAttribute(AttributeDescriptor desc)Tells whether an attribute is a reference to an item (including Collection and Maps referencing items).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 modelbooleanjaloOnlyAttribute(java.lang.String qualifier)AbstractItemModelload(java.lang.Object source)Instantiates a new instance of configured model class for the given sourceItemand loads all of its attributes.protected voidmergeNonDataLocales(AbstractItemModel model)LocMap<java.util.Locale,java.lang.Object>mergeOldValuesIntoDataLocales(java.util.Map<java.util.Locale,java.util.Set<java.util.Locale>> dataLocale2LocaleMappings, java.lang.String qualifier, LocMap<java.util.Locale,java.lang.Object> oldLocValues)protected booleanmustConvert(Type type)Tells whether or not values of the given type require conversion before using them as model attribute values.protected voidpreLoadAttribute(AbstractItemModel model, java.lang.String qualifier, java.lang.Object value)protected voidpreLoadLocAttribute(java.util.Map<java.lang.String,LocMap<java.util.Locale,java.lang.Object>> localizedAttributesFieldValue, AbstractItemModel model, java.lang.String qualifier, java.util.Locale loc, java.lang.Object value)protected ItemModelConverter.LoadedAttributeValuesreadAttributes(java.util.Locale dataLoc, PersistenceObject item, java.util.Set<java.lang.String> qualifiers)Performs bulk-reading of item attribute values,protected AttributePrefetchModereadPrefetchSettings()Reads configuration settingServicelayerConstants.PARAM_PREFETCHand determines preFetch mode.protected java.lang.ObjectreadSingleAttribute(java.util.Locale dataLoc, PersistenceObject item, java.lang.String qualifier)Performs reading for a single item attribute.voidreload(java.lang.Object modelOriginal)Clears all attributes of given bean so that they will be reloaded on next request.voidremove(java.lang.Object model)Tries to remove the sourceItemof the givenAbstractItemModel.voidremoveModelModificationListener(java.lang.Object model, ModelModificationListener listener)Removes the ModelModificationListener from the given model.voidsave(java.lang.Object model, java.util.Collection<java.lang.String> excludedAttributes)Takes all modified values from the givenAbstractItemModeland writes them down to the source Item (if it exists).protected voidsetAttributeLoadError(AbstractItemModel model, java.lang.String qualifier, ModelLoadingException error)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.protected voidsetLocAttributeLoadError(AbstractItemModel model, java.lang.String qualifier, java.util.Locale loc, ModelLoadingException error)protected voidstoreAttributes(Item item, ItemModelConverter.ModifiedAttributeValues values)Performs storing of item attribute values.java.lang.StringtoString()voidtypeSystemChanged()Type system was changed and converter will respect this changes.voidunloadAttributes(AbstractItemModel model)
-
-
-
Constructor Detail
-
ItemModelConverter
public ItemModelConverter(ModelService modelService, I18NService i18nService, CommonI18NService commonI18NService, java.lang.String type, java.lang.Class<? extends AbstractItemModel> modelClass, SerializationStrategy serializationStrategy)
For backward compatibility
-
ItemModelConverter
public ItemModelConverter(ModelService modelService, I18NService i18nService, CommonI18NService commonI18NService, java.lang.String type, java.lang.Class<? extends AbstractItemModel> modelClass, SerializationStrategy serializationStrategy, SourceTransformer sourceTransformer, SelfHealingService selfHealingService)
Constructs a newItemModelConverterinstance which handles beans of given class type related to given composed type.- Parameters:
type- specifies the type this handler can handle, is used insave(Object, Collection)if a new item instance is createdmodelClass- specifies whichAbstractItemModelclass will be used to instantiate a new model viaload(Object)
-
-
Method Detail
-
readPrefetchSettings
protected AttributePrefetchMode readPrefetchSettings()
Reads configuration settingServicelayerConstants.PARAM_PREFETCHand determines preFetch mode. Method is called once initially for eachItemModelConverterinstance.ServicelayerConstants.VALUE_PREFETCH_DEFAULTor no value means
-
getConfig
protected ConfigIntf getConfig()
Encapsulates fetching ofConfigIntf. This allows overriding e.g. for test cases.
-
getInitialModelAttributes
public java.util.List<ItemModelConverter.ModelAttributeInfo> getInitialModelAttributes()
-
getAllModelAttributes
public java.util.List<ItemModelConverter.ModelAttributeInfo> getAllModelAttributes()
-
getInfo
public ItemModelConverter.ModelAttributeInfo getInfo(java.lang.String qualfier)
-
create
public AbstractItemModel create(java.lang.String type)
Instantiates a new instance of configured model class.- Specified by:
createin interfaceModelConverter- Returns:
- new empty model
-
isConfiguredForLegacyPersistence
public boolean isConfiguredForLegacyPersistence()
-
createModelInstance
protected AbstractItemModel createModelInstance(ItemModelInternalContext ctx)
-
createContextForNewModel
protected ItemModelInternalContext createContextForNewModel(java.lang.String type)
-
createContextForExistingModel
protected ItemModelInternalContext createContextForExistingModel(java.lang.String type, PK pk, long persistenceVersion, AttributeProvider attributeProvider)
-
load
public final AbstractItemModel load(java.lang.Object source)
Instantiates a new instance of configured model class for the given sourceItemand loads all of its attributes.- Specified by:
loadin interfaceModelConverter- Parameters:
source- object which will be used for filling new model- Returns:
- new model instance with data of given source
- Throws:
java.lang.IllegalArgumentException- if the given source object is not compatible with the item class provided in this classes constructor.
-
addModelModificationListener
public void addModelModificationListener(java.lang.Object model, ModelModificationListener listener)Description copied from interface:UpdateableModelConverterAdds the givenModelModificationListenerto the given model.- Specified by:
addModelModificationListenerin interfaceUpdateableModelConverter
-
removeModelModificationListener
public void removeModelModificationListener(java.lang.Object model, ModelModificationListener listener)Description copied from interface:UpdateableModelConverterRemoves the ModelModificationListener from the given model.- Specified by:
removeModelModificationListenerin interfaceUpdateableModelConverter
-
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
-
mergeNonDataLocales
protected void mergeNonDataLocales(AbstractItemModel model)
-
mergeOldValuesIntoDataLocales
public LocMap<java.util.Locale,java.lang.Object> mergeOldValuesIntoDataLocales(java.util.Map<java.util.Locale,java.util.Set<java.util.Locale>> dataLocale2LocaleMappings, java.lang.String qualifier, LocMap<java.util.Locale,java.lang.Object> oldLocValues)
-
getDirtyLocalizedAttributesWithNonDataLocales
protected java.util.Set<java.lang.String> getDirtyLocalizedAttributesWithNonDataLocales(java.util.Map<java.util.Locale,java.util.Set<java.lang.String>> dirtyLocalizedAttributes, java.util.Map<java.util.Locale,java.util.Set<java.util.Locale>> dataLocale2NonDataLocales)
-
hasNonDataLocales
protected boolean hasNonDataLocales(java.util.Map<java.util.Locale,java.util.Set<java.util.Locale>> dataLocale2LocaleMappings)
-
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
-
reload
public void reload(java.lang.Object modelOriginal)
Clears all attributes of given bean so that they will be reloaded on next request.- Specified by:
reloadin interfaceModelConverter- Parameters:
modelOriginal- model which will be filled from scratch using mapped source
-
remove
public void remove(java.lang.Object model)
Tries to remove the sourceItemof the givenAbstractItemModel.- Specified by:
removein interfaceModelConverter- Parameters:
model- the model for which to remove the source- Throws:
java.lang.IllegalArgumentException- if the given model is not of type ItemModel
-
save
public void save(java.lang.Object model, java.util.Collection<java.lang.String> excludedAttributes)Takes all modified values from the givenAbstractItemModeland writes them down to the source Item (if it exists). If the item doesn't exist, an exception is thrown since the Item type itself is abstract.- Specified by:
savein interfaceModelConverter- Parameters:
model- the model to save- Throws:
java.lang.IllegalArgumentException- if the given model is not an instance of ItemModeljava.lang.IllegalStateException- if the source item of the model doesn't exist any more
-
afterModification
public void afterModification(AbstractItemModel model, PK pk, long persistenceVersion)
-
unloadAttributes
public void unloadAttributes(AbstractItemModel model)
-
getExcluded
protected java.util.Set<ItemModelConverter.ModelAttributeInfo> getExcluded(java.util.Collection<java.lang.String> excluded)
-
getSource
@Deprecated public java.lang.Object getSource(java.lang.Object model)
Deprecated.since 5.7.0 - Please usegetPersistenceSource(Object)For the given bean the underlyingItemis returned.- 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
- Throws:
java.lang.IllegalArgumentException- if the given bean is not of typeAbstractItemModeljava.lang.IllegalStateException- is the model has never been persisted or the underlying item does not exist any more
-
getPersistenceSource
public PersistenceObject getPersistenceSource(java.lang.Object model)
- Specified by:
getPersistenceSourcein interfaceModelConverter
-
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
-
getDirtyAttributeValue
public java.lang.Object getDirtyAttributeValue(java.lang.Object model, java.lang.String attributeQualifier)Internal method forDefaultModelServicewhen inspecting dirty attributes during save!
-
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
-
getDirtyLocalizedAttributeValue
public java.lang.Object getDirtyLocalizedAttributeValue(java.lang.Object model, java.lang.String attributeQualifier, java.util.Locale locale)Internal method forDefaultModelServicewhen inspecting dirty attributes during save!
-
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
-
getModelClass
public java.lang.Class<? extends AbstractItemModel> getModelClass()
Gets the class used for instantiation of related models.- Returns:
- model class
-
getDefaultType
public java.lang.String getDefaultType()
-
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
-
getTypeFromModelContext
protected java.lang.String getTypeFromModelContext(java.lang.Object model)
-
getComposedType
protected ComposedType getComposedType(AbstractItemModel model)
-
readSingleAttribute
protected java.lang.Object readSingleAttribute(java.util.Locale dataLoc, PersistenceObject item, java.lang.String qualifier)Performs reading for a single item attribute.- Parameters:
dataLoc- the locale to be useditem- the item to read fromqualifier- the attribute qualifier- Returns:
- the attribute value
-
jaloOnlyAttribute
public boolean jaloOnlyAttribute(java.lang.String qualifier)
-
calculateTypeAttributeInfos
protected java.util.Collection<ItemModelConverter.TypeAttributeInfo> calculateTypeAttributeInfos(ComposedType ct)
Calculates attribute meta info objects for a given composed type.
-
isReferenceAttribute
protected boolean isReferenceAttribute(AttributeDescriptor desc)
Tells whether an attribute is a reference to an item (including Collection and Maps referencing items).
-
assembleMetaInfo
protected ItemModelConverter.TypeMetaInfo assembleMetaInfo(ComposedType ct, java.util.Collection<ItemModelConverter.TypeAttributeInfo> attributes)
InitializesItemModelConverter.TypeMetaInfo._modelAttributesAllandItemModelConverter.TypeMetaInfo._modelAttributesInitialusing attribute meta infos. Must be called with active write lock!!
-
createModelAttributeInfo
protected ItemModelConverter.ModelAttributeInfo createModelAttributeInfo(ItemModelConverter.TypeAttributeInfo info)
This method is an internal API and is subject to change without further notice
-
readAttributes
protected ItemModelConverter.LoadedAttributeValues readAttributes(java.util.Locale dataLoc, PersistenceObject item, java.util.Set<java.lang.String> qualifiers)
Performs bulk-reading of item attribute values,- Parameters:
item- the item to read fromqualifiers- the attributes to load values for
-
storeAttributes
protected void storeAttributes(Item item, ItemModelConverter.ModifiedAttributeValues values)
Performs storing of item attribute values.- Parameters:
item- the item to write intovalues- the (jalo compatible!) values to store
-
isNonLazyLoadedAttribute
protected boolean isNonLazyLoadedAttribute(AttributeDescriptor desc)
Tells whether or not a attribute should be lazy loaded.- Parameters:
desc- the attribute descriptor
-
mustConvert
protected boolean mustConvert(Type type)
Tells whether or not values of the given type require conversion before using them as model attribute values. Here all instances of composed types and other types containing composed types are considered to require conversion.- Parameters:
type- the type to check- See Also:
isNonLazyLoadedAttribute(AttributeDescriptor)
-
getStdLocale
protected java.util.Locale getStdLocale()
-
createNewItem
protected PersistenceObject createNewItem(AbstractItemModel model, ItemModelConverter.ModifiedAttributeValues values)
Performs item creation. Override this method if you have to provide sophisticated functionality to create a new Item (more than justComposedType.newInstance(Map).- Parameters:
values- the attributes for the new item- Returns:
- the new Item instance
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
fillModel
protected void fillModel(AbstractItemModel model, ItemModelConverter.AttributesToLoad attributesToLoad, PersistenceObject item)
Loads and fills model instance with loaded attribute values.- Parameters:
model- the model instance to fill values intoattributesToLoad- the attributes to be loaded
-
setLocAttributeLoadError
protected void setLocAttributeLoadError(AbstractItemModel model, java.lang.String qualifier, java.util.Locale loc, ModelLoadingException error)
-
setAttributeLoadError
protected void setAttributeLoadError(AbstractItemModel model, java.lang.String qualifier, ModelLoadingException error)
-
preLoadLocAttribute
protected void preLoadLocAttribute(java.util.Map<java.lang.String,LocMap<java.util.Locale,java.lang.Object>> localizedAttributesFieldValue, AbstractItemModel model, java.lang.String qualifier, java.util.Locale loc, java.lang.Object value)
-
clearLocAttribute
protected void clearLocAttribute(AbstractItemModel model, java.lang.String qualifier, java.util.Locale loc)
-
preLoadAttribute
protected void preLoadAttribute(AbstractItemModel model, java.lang.String qualifier, java.lang.Object value)
-
clearAttribute
protected void clearAttribute(AbstractItemModel model, java.lang.String qualifier)
-
convertModelsToObjects
protected java.lang.Object convertModelsToObjects(AbstractItemModel model, java.lang.String qualifier, java.lang.Object value)
Checks if the given object is a model, a collection of models, or a map with models and tries to convert them to related source object.- Parameters:
value- model, collection of models or map of models to convert- Returns:
- converted source object/s or original if no conversion is possible
-
convertObjectsToModels
protected java.lang.Object convertObjectsToModels(PersistenceObject item, java.lang.String qualifier, java.lang.Object value)
Tries to convert given object, collection of objects or map of objects to related model instances.- Parameters:
value- object, collection of objects or map of objects to convert to model/s- Returns:
- converted model or original if no conversion is possible
-
isEnumValue
protected boolean isEnumValue(java.lang.Object value)
-
getAttributesToReload
protected ItemModelConverter.AttributesToLoad getAttributesToReload(AbstractItemModel model, ItemModelConverter.ModifiedAttributeValues savedValues, boolean forCreation)
-
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.
-
getModelService
protected ModelService getModelService()
-
getI18nService
protected I18NService getI18nService()
-
getCommonI18NService
protected CommonI18NService getCommonI18NService()
-
getLocaleProvider
protected LocaleProvider getLocaleProvider()
-
getDynamicAttributesProvider
protected DynamicAttributesProvider getDynamicAttributesProvider()
-
getGetter
protected java.lang.reflect.Method getGetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)
-
getLocalizedGetter
protected java.lang.reflect.Method getLocalizedGetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)
-
getSetter
protected java.lang.reflect.Method getSetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info, java.lang.Object value)
-
getLocalizedSetter
protected java.lang.reflect.Method getLocalizedSetter(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info, java.lang.Object value)
-
getSerializationStrategy
public SerializationStrategy getSerializationStrategy()
-
getFieldValue
protected final java.lang.Object getFieldValue(java.lang.Object model, ItemModelConverter.ModelAttributeInfo info)
-
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.
-
getUniqueAttributes
public java.util.Set<java.lang.String> getUniqueAttributes()
-
getMandatoryAttributes
public java.util.Set<java.lang.String> getMandatoryAttributes()
-
getMandatoryAttributesForCreation
public java.util.Set<java.lang.String> getMandatoryAttributesForCreation()
-
typeSystemChanged
public void typeSystemChanged()
Description copied from interface:TypeSystemAwareModelConverterType system was changed and converter will respect this changes.- Specified by:
typeSystemChangedin interfaceTypeSystemAwareModelConverter
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-