Stuart McCulloch | 26e7a5a | 2011-10-17 10:31:43 +0000 | [diff] [blame^] | 1 | package aQute.bnd.annotation.metatype; |
| 2 | |
| 3 | import java.lang.annotation.*; |
| 4 | |
| 5 | /** |
| 6 | * The Metadata interface provides access to the properties that underly a |
| 7 | * Configurable interface. Any Configurable interface can implement this |
| 8 | * interface. The interface provides the annotations that can be used to create |
| 9 | * metatype objects. |
| 10 | * |
| 11 | * @ConsumerInterface |
| 12 | */ |
| 13 | |
| 14 | public interface Meta { |
| 15 | enum Type { |
| 16 | Boolean, |
| 17 | Byte, |
| 18 | Character, |
| 19 | Short, |
| 20 | Integer, |
| 21 | Long, |
| 22 | Float, |
| 23 | Double, |
| 24 | String, |
| 25 | Password |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Constant NULL for default usage |
| 30 | */ |
| 31 | final String NULL = "§NULL§"; |
| 32 | |
| 33 | /** |
| 34 | * The OCD Annotation maps to the OCD element in the Metatype specification. |
| 35 | * The only difference is that it is possible to create a Designate element |
| 36 | * as well. |
| 37 | * |
| 38 | */ |
| 39 | @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @interface OCD { |
| 40 | /** |
| 41 | * The name for this component. The default name is a the short class |
| 42 | * name that us un-camel cased to make it more readable. |
| 43 | * |
| 44 | * @return The name of this component |
| 45 | */ |
| 46 | String name() default NULL; |
| 47 | |
| 48 | /** |
| 49 | * The id of the component. Default the name of the class in FQN |
| 50 | * notation but with nested classes using the $ as separator (not .). |
| 51 | * |
| 52 | * The Felix webconsole always uses this id as the PID and not the pid |
| 53 | * in the Designate element. Reported as an error. |
| 54 | * |
| 55 | * @return the id |
| 56 | */ |
| 57 | String id() default NULL; |
| 58 | |
| 59 | /** |
| 60 | * The localization prefix. The default localization prefix is the name |
| 61 | * of the class with a $ separator for nested classes. |
| 62 | * |
| 63 | * @return the localization prefix. |
| 64 | */ |
| 65 | String localization() default NULL; |
| 66 | |
| 67 | /** |
| 68 | * A description for this ocd. The default is empty. |
| 69 | * |
| 70 | * @return the description |
| 71 | */ |
| 72 | String description() default NULL; |
| 73 | |
| 74 | /** |
| 75 | * Defines if this is for a factory or not. |
| 76 | */ |
| 77 | boolean factory() default false; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * The AD element in the Metatype specification. |
| 82 | * |
| 83 | */ |
| 84 | @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @interface AD { |
| 85 | /** |
| 86 | * A description of the attribute. Default is empty. |
| 87 | * |
| 88 | * @return The description of the attribute. |
| 89 | */ |
| 90 | String description() default NULL; |
| 91 | |
| 92 | /** |
| 93 | * The name of the attribute. By default the un-camel cased version of |
| 94 | * the method name. |
| 95 | * |
| 96 | * @return the name |
| 97 | */ |
| 98 | String name() default NULL; |
| 99 | |
| 100 | /** |
| 101 | * The id of the attribute. By default the name of the method. The id is |
| 102 | * the key used to access the properties. This is the reason the AD is a |
| 103 | * runtime annotation so the runtime can find the proper key. |
| 104 | * |
| 105 | * @return the id |
| 106 | */ |
| 107 | String id() default NULL; |
| 108 | |
| 109 | /** |
| 110 | * The type of the field. This must be one of the basic types in the |
| 111 | * metatype specification. By default, the type is derived from the |
| 112 | * return type of the method. This includes most collections and arrays. |
| 113 | * Unrecognized types are defaulted to String. |
| 114 | * |
| 115 | * @return the type to be used. |
| 116 | */ |
| 117 | Type type() default Type.String; |
| 118 | |
| 119 | /** |
| 120 | * The cardinality of the attribute. If not explicitly set it will be |
| 121 | * derived from the attributes return type. Collections return |
| 122 | * Integer.MIN_VALUE and arrays use Integer.MAX_VALUE. |
| 123 | * |
| 124 | * If a single string needs to be converted to a Collection or array |
| 125 | * then the | will be used as a separator to split the line. |
| 126 | * |
| 127 | * @return the cardinality of the attribute |
| 128 | */ |
| 129 | int cardinality() default 0; |
| 130 | |
| 131 | /** |
| 132 | * The minimum value. This string must be converted to the attribute |
| 133 | * type before comparison takes place. |
| 134 | * |
| 135 | * @return the min value |
| 136 | */ |
| 137 | String min() default NULL; |
| 138 | |
| 139 | /** |
| 140 | * The maximum value. This string must be converted to the attribute |
| 141 | * type before comparison takes place. |
| 142 | * |
| 143 | * @return the max value |
| 144 | */ |
| 145 | String max() default NULL; |
| 146 | |
| 147 | /** |
| 148 | * The default value. This value must be converted to the return type of |
| 149 | * the attribute. For multi valued returns use the | as separator. |
| 150 | * |
| 151 | * @return the default value |
| 152 | */ |
| 153 | String deflt() default NULL; |
| 154 | |
| 155 | /** |
| 156 | * Indicates that this attribute is required. By default attributes are |
| 157 | * required. |
| 158 | * |
| 159 | * @return |
| 160 | */ |
| 161 | boolean required() default true; |
| 162 | |
| 163 | /** |
| 164 | * Provide labels for options. These labels must match the values. If no |
| 165 | * labels are set, the un-cameled version of the values are used (if |
| 166 | * they are set of course). |
| 167 | * |
| 168 | * @return the option labels |
| 169 | */ |
| 170 | String[] optionLabels() default NULL; |
| 171 | |
| 172 | /** |
| 173 | * The values of options. If not set and the return type is an enum |
| 174 | * class then the values will be derived from this return type. |
| 175 | * |
| 176 | * @return the option labels |
| 177 | */ |
| 178 | String[] optionValues() default NULL; |
| 179 | } |
| 180 | } |