|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This interface represents an item which may be a component of a ContentItem but may not itself extend ContentItem. Implementing CustomCopy is not necessary for a component to be published. However, only CustomCopy objects can override default attribute/role copying behavior via its copyProperty method. Only DomainObjects should implement this interface.
Method Summary | |
boolean |
copyProperty(CustomCopy source,
com.arsdigita.persistence.metadata.Property property,
ItemCopier copier)
Copy the specified property (attribute or association) from the specified source item. |
Method Detail |
public boolean copyProperty(CustomCopy source, com.arsdigita.persistence.metadata.Property property, ItemCopier copier)
ObjectCopier
. If
the property in question is an association to
ContentItem
(s), this method should only
call FooContentItem newChild = copier.copy(srcItem, this,
riginalChild, property);
An attempt to call any other
method in order to copy the child will most likely have
disastrous consequences. In fact, this copier method should
generally be called for any DomainObject copies, later making
custom changes, unless the copying behavior itself is different
from the default (or the item should not be copied at all at
this point).
If a subclass of a class which implements CustomCopy overrides
this method, it should return super.copyProperty
for properties which do not need custom behavior in order to
indicate that it is not interested in handling the property in
any special way.
For example, the Article
class extends
ContentItem
. It defines an association to 0..n
ImageAsset
. Unfortunately, the association has
"order_n" and "caption" link attributes, which cannot be copied
automatically, since the persistence system doesn't know enough
about them. The following sample code from the Article
class ensures that images are copied correctly (note that this
example no longer applies to the Article case, so it remains as
a general example):
protected boolean copyProperty(CustomCopy srcItem, Property property, ItemCopier copier) { String attrName = property.getName(); // We only care about copying images; all other properties should // be handled in a default manner if (!attrName.equals(IMAGES)) return super.copyProperty(srcItem, property, copier); // The source item is guaranteed to be of the correct type Article src = (Article)srcItem; // Retrieve images from the source ImageAssetCollection srcImages = src.getImages(); // Copy each image using the passed-in copier while(srcImages.next()) { ImageAsset srcImage = srcImages.getImage(); // Images may be shared between items, and so they are not // composite. Thus, we are going to pass false to the object // copier in the second parameter ImageAsset newImage = (ImageAsset)copier.copy(srcItem, this, srcImage, property); // Add the new image to the new item addImage(newImage, src.getCaption(srcImage)); } // Tell the automated copying service that we have handled this // property return true; }
source
- the source CustomCopy itemproperty
- the property to copycopier
- a temporary class that is able to copy a child item
correctly.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |