001    package org.nakedobjects.applib.annotation;
002    
003    import java.lang.annotation.ElementType;
004    import java.lang.annotation.Inherited;
005    import java.lang.annotation.Retention;
006    import java.lang.annotation.RetentionPolicy;
007    import java.lang.annotation.Target;
008    
009    import org.nakedobjects.applib.adapters.EncoderDecoder;
010    
011    
012    /**
013     * Indicates that the class can be encoded or decoded either by delegating to an {@link EncoderDecoder} or
014     * through some externally-configured mechanism.
015     * 
016     * @see Defaulted
017     * @see Parseable
018     * @see Value
019     */
020    @Inherited
021    @Target( { ElementType.TYPE })
022    @Retention(RetentionPolicy.RUNTIME)
023    public @interface Encodable {
024    
025        /**
026         * The fully qualified name of a class that implements the {@link EncoderDecoder} interface.
027         * 
028         * <p>
029         * This is optional because some implementations may pick up encodeability via a configuration file, or
030         * via the equivalent {@link #encoderDecoderClass()}.
031         * 
032         * <p>
033         * It is common for value classes to act as their own encoder/decoders. Note that the framework requires
034         * that the nominated class provides a <tt>public</tt> no-arg constructor on the class. It instantiates
035         * an instance in order to do the encoding or decoding, uses the result and discards the instantiated
036         * object. What that means in particular is that a self-encoding class shouldn't encode its own state, it
037         * should encode the state of the object passed to it.
038         * 
039         * <p>
040         * Implementation note: the default value provided here is simply an empty string because <tt>null</tt>
041         * is not a valid default.
042         */
043        String encoderDecoderName() default "";
044    
045        /**
046         * As per {@link #encoderDecoderName()}, but specifying a class literal rather than a fully qualified
047         * class name.
048         * 
049         * <p>
050         * Implementation note: the default value provided here is simply the {@link Encodable}'s own class,
051         * because <tt>null</tt> is not a valid default.
052         */
053        Class<?> encoderDecoderClass() default Encodable.class;
054    
055    }