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.DefaultsProvider;
010
011
012 /**
013 * Indicates that the class should have a default, by providing a link to a {@link DefaultsProvider}, or some
014 * externally-configured mechanism.
015 *
016 * <p>
017 * This possibly seems a little tortuous. The more obvious means to provide a default would seem to be a
018 * simple <tt>@DefaultsTo(new SomeObject())</tt>. However, Java only allows primitives, strings and class literals to
019 * be used in annotations. We therefore need delegate to an external implementation. (This
020 * more complex design is also more flexible of course; the implementation of
021 * {@link DefaultsProvider} could adjust the default it provides according to circumstance,
022 * for example).
023 *
024 * @see Encodable
025 * @see Parseable
026 * @see Value
027 */
028 @Inherited
029 @Target( { ElementType.TYPE })
030 @Retention(RetentionPolicy.RUNTIME)
031 public @interface Defaulted {
032
033 /**
034 * The fully qualified name of a class that implements the {@link DefaultsProvider} interface.
035 *
036 * <p>
037 * This is optional because some implementations may pick up the defaults provider via a configuration
038 * file, or via the equivalent {@link #defaultsProviderClass()}.
039 *
040 * <p>
041 * Implementation note: the default value provided here is simply an empty string because <tt>null</tt>
042 * is not a valid default.
043 */
044 String defaultsProviderName() default "";
045
046 /**
047 * As per {@link #defaultsProviderName()}, but specifying a class literal rather than a fully qualified
048 * class name.
049 *
050 * <p>
051 * Implementation note: the default value provided here is simply the {@link Defaulted}'s own class,
052 * because <tt>null</tt> is not a valid default.
053 */
054 Class<?> defaultsProviderClass() default Defaulted.class;
055
056 }