Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Carsten Ziegeler | ba751bd | 2009-04-18 18:31:43 +0000 | [diff] [blame] | 19 | package org.apache.felix.scr.annotations; |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 20 | |
Carsten Ziegeler | b5618fe | 2009-03-31 17:18:17 +0000 | [diff] [blame] | 21 | import java.lang.annotation.*; |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * The <code>Property</code> annotation defines properties which are made |
| 25 | * available to the component through the ComponentContext.getProperties() |
| 26 | * method. These annotations are not strictly required but may be used by |
| 27 | * components to defined initial configuration. Additionally properties may be |
| 28 | * set here to identify the component if it is registered as a service, for |
| 29 | * example the service.description and service.vendor properties. |
| 30 | * <p> |
| 31 | * This tag is used to declare <property> elements of the component |
| 32 | * declaration. See section 112.4.5, Properties and Property Elements, in the |
| 33 | * OSGi Service Platform Service Compendium Specification for more information. |
| 34 | */ |
Carsten Ziegeler | 27764de | 2009-04-16 09:39:33 +0000 | [diff] [blame] | 35 | @Target( { ElementType.TYPE, ElementType.FIELD }) |
Carsten Ziegeler | 1993d10 | 2009-04-07 16:16:47 +0000 | [diff] [blame] | 36 | @Retention(RetentionPolicy.SOURCE) |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 37 | @Documented |
| 38 | public @interface Property { |
| 39 | |
| 40 | /** |
| 41 | * The name of the property |
| 42 | */ |
Carsten Ziegeler | a4ca8fe | 2009-04-23 05:52:04 +0000 | [diff] [blame] | 43 | String name() default ""; |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * The label to display in a form to configure this property. This name may |
| 47 | * be localized by prepending a % sign to the name. Default value: |
| 48 | * %<name>.name |
| 49 | */ |
| 50 | String label() default ""; |
| 51 | |
| 52 | /** |
| 53 | * A descriptive text to provide the client in a form to configure this |
| 54 | * property. This name may be localized by prepending a % sign to the name. |
| 55 | * Default value: %<name>.description |
| 56 | */ |
| 57 | String description() default ""; |
| 58 | |
| 59 | /** |
| 60 | * The value(s) of the property. If the property type is not String, parsing |
| 61 | * of the value is done using the valueOf(String) method of the class |
| 62 | * defined by the property type. |
Carsten Ziegeler | 9aa4f3b | 2009-05-14 20:05:45 +0000 | [diff] [blame] | 63 | * This attribute should not be used in combination with any of the other |
| 64 | * value attributes. |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 65 | */ |
Carsten Ziegeler | 5d33aaf | 2009-05-19 06:24:41 +0000 | [diff] [blame] | 66 | String[] value() default {}; |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 67 | |
| 68 | /** |
Carsten Ziegeler | 9aa4f3b | 2009-05-14 20:05:45 +0000 | [diff] [blame] | 69 | * The long value(s) of the property. |
| 70 | * This attribute should not be used in combination with any of the other |
| 71 | * value attributes or the type attribute. |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 72 | */ |
Carsten Ziegeler | 5d33aaf | 2009-05-19 06:24:41 +0000 | [diff] [blame] | 73 | long[] longValue() default {}; |
Carsten Ziegeler | 9aa4f3b | 2009-05-14 20:05:45 +0000 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * The double value(s) of the property. |
| 77 | * This attribute should not be used in combination with any of the other |
| 78 | * value attributes. |
| 79 | */ |
Carsten Ziegeler | 5d33aaf | 2009-05-19 06:24:41 +0000 | [diff] [blame] | 80 | double[] doubleValue() default {}; |
Carsten Ziegeler | 9aa4f3b | 2009-05-14 20:05:45 +0000 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * The float value(s) of the property. |
| 84 | * This attribute should not be used in combination with any of the other |
| 85 | * value attributes or the type attribute. |
| 86 | */ |
Carsten Ziegeler | 5d33aaf | 2009-05-19 06:24:41 +0000 | [diff] [blame] | 87 | float[] floatValue() default {}; |
Carsten Ziegeler | 9aa4f3b | 2009-05-14 20:05:45 +0000 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * The int value(s) of the property. |
| 91 | * This attribute should not be used in combination with any of the other |
| 92 | * value attributes or the type attribute. |
| 93 | */ |
Carsten Ziegeler | 5d33aaf | 2009-05-19 06:24:41 +0000 | [diff] [blame] | 94 | int[] intValue() default {}; |
Carsten Ziegeler | 9aa4f3b | 2009-05-14 20:05:45 +0000 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * The byte value(s) of the property. |
| 98 | * This attribute should not be used in combination with any of the other |
| 99 | * value attributes or the type attribute. |
| 100 | */ |
Carsten Ziegeler | 5d33aaf | 2009-05-19 06:24:41 +0000 | [diff] [blame] | 101 | byte[] byteValue() default {}; |
Carsten Ziegeler | 9aa4f3b | 2009-05-14 20:05:45 +0000 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * The char value(s) of the property. |
| 105 | * This attribute should not be used in combination with any of the other |
| 106 | * value attributes or the type attribute. |
| 107 | */ |
Carsten Ziegeler | 5d33aaf | 2009-05-19 06:24:41 +0000 | [diff] [blame] | 108 | char[] charValue() default {}; |
Carsten Ziegeler | 9aa4f3b | 2009-05-14 20:05:45 +0000 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * The bool value(s) of the property. |
| 112 | * This attribute should not be used in combination with any of the other |
| 113 | * value attributes or the type attribute. |
| 114 | */ |
Carsten Ziegeler | 5d33aaf | 2009-05-19 06:24:41 +0000 | [diff] [blame] | 115 | boolean[] boolValue() default {}; |
Carsten Ziegeler | 9aa4f3b | 2009-05-14 20:05:45 +0000 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * The short value(s) of the property. |
| 119 | * This attribute should not be used in combination with any of the other |
| 120 | * value attributes or the type attribute. |
| 121 | */ |
Carsten Ziegeler | 5d33aaf | 2009-05-19 06:24:41 +0000 | [diff] [blame] | 122 | short[] shortValue() default {}; |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * Defines the cardinality of the property and its collection type. If the |
| 126 | * cardinality is negative, the property is expected to be stored in a |
| 127 | * {@link java.util.Vector} (primitive types such as boolean are boxed in |
| 128 | * the Wrapper class), if the cardinality is positive, the property is |
| 129 | * stored in an array (primitve types are unboxed, that is Boolean type |
| 130 | * values are stored in boolean[]). The actual value defines the maximum |
| 131 | * number of elements in the vector or array, where Integer.MIN_INT |
| 132 | * describes an unbounded Vector and Integer.MAX_INT describes an unbounded |
| 133 | * array. If the cardinality is zero, the property is a scalar value. If the |
| 134 | * defined value of the property is set in the value attribute, the |
| 135 | * cardinality defaults to 0 (zero for scalar value). If the property is |
| 136 | * defined in one or more properties starting with values, the cardinality |
| 137 | * defaults to Integer.MAX_INT, that is an unbounded array. |
| 138 | */ |
| 139 | int cardinality() default 0; |
| 140 | |
| 141 | /** |
| 142 | * Boolean flag defining whether a metatype descriptor entry should be |
| 143 | * generated for this property or not. By default a metatype descriptor |
| 144 | * entry, i.e. an AD element, is generated except for the properties |
| 145 | * <code>service.pid</code>, <code>service.description</code>, |
| 146 | * <code>service.id</code>, <code>service.ranking</code>, |
| 147 | * <code>service.vendor</code>, <code>service.bundlelocation</code> and |
| 148 | * <code>service.factoryPid</code>. If a property should not be available |
| 149 | * for display in a configuration user interface, this parameter should be |
| 150 | * set to true. |
| 151 | */ |
| 152 | boolean propertyPrivate() default false; |
| 153 | |
| 154 | /** |
| 155 | * Some properties may only be set to a set of possible values. To support |
| 156 | * user interfaces which provide a selection list of values or a list of |
| 157 | * checkboxes the option values and labels may be defined as parameters to |
| 158 | * the {@link Property} annotation. All parameters in the form of name-value |
| 159 | * pairs are used to build the list of available value options. The |
| 160 | * parameter name is used as the value while the parameter value is used as |
| 161 | * the label in the user interface. This label may be prepended with a % |
| 162 | * sign to localize the string. |
| 163 | * <p> |
| 164 | * The options are written to the metatype.xml file as Option elements |
| 165 | * inside the AD element defining the property. The name of the parameter |
| 166 | * will be used for the Option.value attribute while the value of the |
| 167 | * parameter defines the Option.label attribute. |
| 168 | */ |
| 169 | PropertyOption[] options() default {}; |
| 170 | |
| 171 | } |