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