Pierre De Rop | 6ce01ad | 2010-02-03 23:03:20 +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 | */ |
| 19 | package org.apache.felix.dm.annotation.api; |
| 20 | |
| 21 | import java.lang.annotation.ElementType; |
| 22 | import java.lang.annotation.Retention; |
| 23 | import java.lang.annotation.RetentionPolicy; |
| 24 | import java.lang.annotation.Target; |
| 25 | |
| 26 | /** |
| 27 | * This Annotation has to be specified within the MetaType annotation, and declares an Attribute Definition |
| 28 | * which complies to the MetaType specification. |
| 29 | */ |
| 30 | @Retention(RetentionPolicy.CLASS) |
| 31 | @Target(ElementType.ANNOTATION_TYPE) |
| 32 | public @interface Attribute |
| 33 | { |
| 34 | /** |
| 35 | * Unique identity for this attribute. Attributes share a global namespace in the registry. E.g. an attribute cn or commonName |
| 36 | * must always be a String and the semantics are always a name of some object. They share this aspect with LDAP/X.500 attributes. |
| 37 | * In these standards the OSI Object Identifier (OID) is used to uniquely identify an attribute. If such an OID exists, (which can |
| 38 | * be requested at several standard organisations and many companies already have a node in the tree) it can be returned here. Otherwise, |
| 39 | * a unique id should be returned which can be a Java class name (reverse domain name) or generated with a GUID algorithm. |
| 40 | * Note that all LDAP defined attributes already have an OID. It is strongly advised to define the attributes from existing LDAP schemes |
| 41 | * which will give the OID. Many such schemes exist ranging from postal addresses to DHCP parameters. |
| 42 | */ |
| 43 | String id(); |
| 44 | |
| 45 | /** |
| 46 | * Return the type for this attribute. If must be either one of the following types:<p> |
| 47 | * <ul> |
| 48 | * <li>String.class</li> |
| 49 | * <li>Long.class</li> |
| 50 | * <li>Integer.class</li> |
| 51 | * <li>Char.class</li> |
| 52 | * <li>Byte.class</li> |
| 53 | * <li>Double.class</li> |
| 54 | * <li>Float.class</li> |
| 55 | * <li>Boolean.class</li> |
| 56 | * </ul> |
| 57 | */ |
| 58 | Class<?> type() default String.class; |
| 59 | |
| 60 | /** |
| 61 | * Return a default for this attribute. The object must be of the appropriate type as defined by the cardinality and getType(). |
| 62 | * The return type is a list of String objects that can be converted to the appropriate type. The cardinality of the return |
| 63 | * array must follow the absolute cardinality of this type. E.g. if the cardinality = 0, the array must contain 1 element. |
| 64 | * If the cardinality is 1, it must contain 0 or 1 elements. If it is -5, it must contain from 0 to max 5 elements. Note that |
| 65 | * the special case of a 0 cardinality, meaning a single value, does not allow arrays or vectors of 0 elements. |
| 66 | */ |
| 67 | String[] defaults() default {}; |
| 68 | |
| 69 | /** |
| 70 | * Returns the name of the attribute. This name may be localized. |
| 71 | */ |
| 72 | String name(); |
| 73 | |
| 74 | /** |
| 75 | * Returns a description of this attribute. The description may be localized and must describe the semantics of this type and any |
| 76 | * constraints. |
| 77 | * @return The localized description of the definition. |
| 78 | */ |
| 79 | String description(); |
| 80 | |
| 81 | /** |
| 82 | * Return the cardinality of this attribute. The OSGi environment handles multi valued attributes in arrays ([]) or in Vector objects. |
| 83 | * The return value is defined as follows:<p> |
| 84 | * |
| 85 | * <ul> |
| 86 | * <li> x = Integer.MIN_VALUE no limit, but use Vector</li> |
| 87 | * <li> x < 0 -x = max occurrences, store in Vector</li> |
| 88 | * <li> x > 0 x = max occurrences, store in array []</li> |
| 89 | * <li> x = Integer.MAX_VALUE no limit, but use array []</li> |
| 90 | * <li> x = 0 1 occurrence required</li> |
| 91 | */ |
| 92 | int cardinality() default 0; |
| 93 | |
| 94 | /** |
| 95 | * Tells if this attribute is required or not. |
| 96 | */ |
| 97 | boolean required() default true; |
| 98 | |
| 99 | /** |
| 100 | * Return a list of option that this attribute can take. |
| 101 | * The Options are defined using the <code>Property</code> annotation, where the name attributes is used to |
| 102 | * reference the option label, and the value attribute is used to reference the option value. |
| 103 | */ |
| 104 | Property[] options() default {}; |
| 105 | } |