@Retention(value=RUNTIME) @Target(value={METHOD,FIELD}) @Documented public @interface UseDefaults
These are the default values used for various types:
Byte: 0 Short: 0 Character: 0 Integer: 0 Long: 0L Double: 0.0d Float: 0.0f Boolean: false String: "" List: empty java.util.ArrayList Set: empty java.util.HashSet Collection: empty java.util.ArrayList enum: first declared value
If this annotation is not used, the property will be set to null, and unless @Optional
is declared
is not allowed.
The @UseDefaults
annotation can also have a value in its declaration. This value is used,
unless it is overridden in the assembly (see below). Java does not support generic types of annotation values,
so it accepts String values, which are deserialized from JSON using the Serialization SPI. This allows
for (albeit somewhat tedious) any object type to have a default value declared on it. If the property type is
String, then no value deserialization is done.
It is also possible to change the default values for Composites during the assembly. This is done by calling the
org.apache.polygene.bootstrap.ModuleAssembly#forMixin(Class)
method.
Example; Let's assume that we have the following mixin type;
public interface SomeType
{
@UseDefaults
Property<String> someValue();
}
And that we want to have someValue()
to be initialized to "<unknown>" instead of the empty string.
Then we need to declare the default for that with the following in the assembler.
public void assemble( ModuleAssembly module )
{
module.forMixin( SomeType.class ).declareDefaults().someValue().set( "<unknown>" );
}
}
public abstract String value