001    package org.tynamo.descriptor.annotation;
002    
003    import org.apache.commons.lang.Validate;
004    import org.tynamo.descriptor.TynamoPropertyDescriptor;
005    
006    /**
007     * Creates a {@link InitialValueDescriptorExtension} using the
008     * information retrieved from a {@link InitialValue} annotation.
009     *
010     * @author pruggia
011     */
012    public class InitialValueAnnotationHandler extends AbstractAnnotationHandler
013                    implements DescriptorAnnotationHandler<InitialValue, TynamoPropertyDescriptor>
014    {
015    
016            /**
017             * Creates a {@link InitialValueDescriptorExtension} and adds it to
018             * the property descriptor.
019             *
020             * @param annotation Annotation added to the property. It cannot be null.
021             * @param descriptor The property descriptor. It cannot be null.
022             * @return The provided descriptor with the extension added.
023             */
024            public TynamoPropertyDescriptor decorateFromAnnotation(final InitialValue annotation,
025                                                                                                              final TynamoPropertyDescriptor descriptor)
026            {
027                    Validate.notNull(annotation, "The annotation cannot be null");
028                    Validate.notNull(descriptor, "The descriptor cannot be null");
029                    InitialValueDescriptorExtension extension = new InitialValueDescriptorExtension(annotation.value());
030                    descriptor.addExtension(InitialValueDescriptorExtension.class
031                                    .getName(), extension);
032                    return descriptor;
033            }
034    }
035