com.arsdigita.cms
Interface CustomCopy

All Known Implementing Classes:
ContentItem

public interface CustomCopy

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

copyProperty

public boolean copyProperty(CustomCopy source,
                            com.arsdigita.persistence.metadata.Property property,
                            ItemCopier copier)
Copy the specified property (attribute or association) from the specified source item. This method almost completely overrides the metadata-driven methods in 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;
 }
 

Parameters:
source - the source CustomCopy item
property - the property to copy
copier - a temporary class that is able to copy a child item correctly.
Returns:
true if the property was copied; false to indicate that regular metadata-driven methods should be used to copy the property.


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2352 UTC