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