Class ItemModelCloneCreator
- java.lang.Object
-
- de.hybris.platform.servicelayer.internal.model.impl.ItemModelCloneCreator
-
- Direct Known Subclasses:
CMSItemModelCloneCreator
public class ItemModelCloneCreator extends java.lang.ObjectThis class creates a deep copy of the given original model by creating a new model instance of the same type, reading all attributes values and stores them into the new instance.The only exception are part-of attribute values which consists of other models - these are cloned themselves and then used as attribute value in the new model instance.
By providing a
ItemModelCloneCreator.CopyContextthe caller may even add some preset values or define which types are being used when creating copied of part-of models.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classItemModelCloneCreator.CannotCloneExceptionClone error class.protected static classItemModelCloneCreator.CannotTranslateExceptionThrown when copy could not be donestatic classItemModelCloneCreator.CopyAttributeA wrapper for each item attribute to be stored while creating a copy.static classItemModelCloneCreator.CopyContextstatic classItemModelCloneCreator.CopyItemWrapper for a single (partOf) item to be copied.
-
Constructor Summary
Constructors Constructor Description ItemModelCloneCreator(ModelService modelService, I18NService i18nService, TypeService typeService)Creates and initialize ItemModelCloneCreator
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidconsume(java.util.Collection<ItemModelCloneCreator.CopyAttribute> readyAttributes)ItemModelcopy(ItemModel original)Creates a copy of the given item.ItemModelcopy(ItemModel original, ItemModelCloneCreator.CopyContext ctx)Creates a copy of the given item.ItemModelcopy(ItemModel original, ModelCloningContext cloningContext)Creates a copy of the given item.ItemModelcopy(ComposedTypeModel targetType, ItemModel original, ItemModelCloneCreator.CopyContext ctx)Creates a copy of the given item.ItemModelcopy(ComposedTypeModel targetType, ItemModel original, ModelCloningContext ctx)Creates a copy of the given item.ItemModelcopy(ComposedType targetType, ItemModel original, ItemModelCloneCreator.CopyContext ctx)Deprecated.since ages - usecopy(ComposedTypeModel, ItemModel, CopyContext)java.util.List<ItemModel>copyAll(ComposedTypeModel targetType, java.util.List<ItemModel> originals, ItemModelCloneCreator.CopyContext ctx)Creates copies of all specified items using a single copy context.java.util.List<ItemModel>copyAll(java.util.List<ItemModel> originals, ItemModelCloneCreator.CopyContext ctx)Creates copies of all specified items using a single copy context.voidcopyAttributes(ItemModel source, ItemModel target, java.util.Set<java.lang.String> attributes)Copies only given set ofattributesfrom thesourceto thetargetmodel.protected voidfindPartOfItems(java.lang.Object originalValue, ItemModelCloneCreator.CopyContext ctx)makes copy of partof itemsprotected booleanisEmpty(java.lang.Object value)Return true if value is null or value is empty collection/map.protected ItemModelCloneCreator.CopyItemprepareCopy(ComposedTypeModel targetType, ItemModel original, ItemModelCloneCreator.CopyContext ctx)prepare copy of original.protected ItemModelCloneCreator.CopyItemprepareCopy(ComposedType targetType, ItemModel original, ItemModelCloneCreator.CopyContext ctx)Deprecated.since ages - useprepareCopy(ComposedTypeModel, ItemModel, CopyContext)protected booleanprocess(ItemModelCloneCreator.CopyItem item, ItemModelCloneCreator.CopyContext ctx)protected voidreadAttributes(ItemModelCloneCreator.CopyItem item, ItemModelCloneCreator.CopyContext ctx)protected voidsetAllAttributes(ItemModel copy, java.util.Collection<ItemModelCloneCreator.CopyAttribute> attributes)protected java.lang.ObjecttranslateAttributeValue(ItemModelCloneCreator.CopyAttribute attr, java.lang.Object originalValue, ItemModelCloneCreator.CopyContext ctx)protected java.util.Collection<ItemModelCloneCreator.CopyAttribute>translatePendingAttributes(ItemModelCloneCreator.CopyItem item, ItemModelCloneCreator.CopyContext ctx)
-
-
-
Constructor Detail
-
ItemModelCloneCreator
public ItemModelCloneCreator(ModelService modelService, I18NService i18nService, TypeService typeService)
Creates and initialize ItemModelCloneCreator
-
-
Method Detail
-
copy
public ItemModel copy(ItemModel original) throws ItemModelCloneCreator.CannotCloneException
Creates a copy of the given item.- Parameters:
original- the item to copy- Throws:
ItemModelCloneCreator.CannotCloneException
-
copy
public ItemModel copy(ItemModel original, ModelCloningContext cloningContext) throws ItemModelCloneCreator.CannotCloneException
Creates a copy of the given item. Optionally cloning process can be influenced by providing a cloning context instance.- Parameters:
original- the item to copycloningContext- the cloning context to manage cloning process- Throws:
ItemModelCloneCreator.CannotCloneException
-
copy
public ItemModel copy(ItemModel original, ItemModelCloneCreator.CopyContext ctx) throws ItemModelCloneCreator.CannotCloneException
Creates a copy of the given item.- Parameters:
original- the item to copyctx- the copy context- Throws:
ItemModelCloneCreator.CannotCloneException
-
copy
@Deprecated public ItemModel copy(ComposedType targetType, ItemModel original, ItemModelCloneCreator.CopyContext ctx) throws ItemModelCloneCreator.CannotCloneException
Deprecated.since ages - usecopy(ComposedTypeModel, ItemModel, CopyContext)
-
copy
public ItemModel copy(ComposedTypeModel targetType, ItemModel original, ModelCloningContext ctx) throws ItemModelCloneCreator.CannotCloneException
Creates a copy of the given item. Allows to specify a type for the new copy to be created.- Parameters:
targetType- the type of copy to create (optional)original- the item to copyctx- the copy context- Throws:
ItemModelCloneCreator.CannotCloneException
-
copy
public ItemModel copy(ComposedTypeModel targetType, ItemModel original, ItemModelCloneCreator.CopyContext ctx) throws ItemModelCloneCreator.CannotCloneException
Creates a copy of the given item. Allows to specify a type for the new copy to be created.- Parameters:
targetType- the type of copy to create (optional)original- the item to copyctx- the copy context- Throws:
ItemModelCloneCreator.CannotCloneException
-
copyAll
public java.util.List<ItemModel> copyAll(java.util.List<ItemModel> originals, ItemModelCloneCreator.CopyContext ctx) throws ItemModelCloneCreator.CannotCloneException
Creates copies of all specified items using a single copy context. Therefore cross references between source items are replaces by references to the newly created copies.- Parameters:
originals- the items to copyctx- the copy context- Returns:
- the list of copies created
- Throws:
ItemModelCloneCreator.CannotCloneException- in case not all items could be copied completely, e.g. due to cyclic dependencies
-
copyAll
public java.util.List<ItemModel> copyAll(ComposedTypeModel targetType, java.util.List<ItemModel> originals, ItemModelCloneCreator.CopyContext ctx) throws ItemModelCloneCreator.CannotCloneException
Creates copies of all specified items using a single copy context. Therefore cross references between source items are replaces by references to the newly created copies.- Parameters:
originals- the items to copyctx- the copy contexttargetType-ComposedTypeModelof the clones- Returns:
- the list of copies created
- Throws:
ItemModelCloneCreator.CannotCloneException- in case not all items could be copied completely, e.g. due to cyclic dependencies
-
copyAttributes
public void copyAttributes(ItemModel source, ItemModel target, java.util.Set<java.lang.String> attributes)
Copies only given set ofattributesfrom thesourceto thetargetmodel.- Parameters:
source- model from which attribute values are to be copiedtarget- model to copy attribute values to
-
readAttributes
protected void readAttributes(ItemModelCloneCreator.CopyItem item, ItemModelCloneCreator.CopyContext ctx)
-
isEmpty
protected boolean isEmpty(java.lang.Object value)
Return true if value is null or value is empty collection/map.
-
prepareCopy
@Deprecated protected ItemModelCloneCreator.CopyItem prepareCopy(ComposedType targetType, ItemModel original, ItemModelCloneCreator.CopyContext ctx)
Deprecated.since ages - useprepareCopy(ComposedTypeModel, ItemModel, CopyContext)
-
prepareCopy
protected ItemModelCloneCreator.CopyItem prepareCopy(ComposedTypeModel targetType, ItemModel original, ItemModelCloneCreator.CopyContext ctx)
prepare copy of original.
-
findPartOfItems
protected void findPartOfItems(java.lang.Object originalValue, ItemModelCloneCreator.CopyContext ctx)makes copy of partof items
-
process
protected boolean process(ItemModelCloneCreator.CopyItem item, ItemModelCloneCreator.CopyContext ctx)
-
setAllAttributes
protected void setAllAttributes(ItemModel copy, java.util.Collection<ItemModelCloneCreator.CopyAttribute> attributes)
-
consume
protected void consume(java.util.Collection<ItemModelCloneCreator.CopyAttribute> readyAttributes)
-
translatePendingAttributes
protected java.util.Collection<ItemModelCloneCreator.CopyAttribute> translatePendingAttributes(ItemModelCloneCreator.CopyItem item, ItemModelCloneCreator.CopyContext ctx)
-
translateAttributeValue
protected java.lang.Object translateAttributeValue(ItemModelCloneCreator.CopyAttribute attr, java.lang.Object originalValue, ItemModelCloneCreator.CopyContext ctx) throws ItemModelCloneCreator.CannotTranslateException
-
-