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>Reference</code> annotation defines references to other services |
| 25 | * made available to the component by the Service Component Runtime. |
| 26 | * <p> |
| 27 | * This annotation may be declared for a Java Class or any Java Field to which |
| 28 | * it might apply. Depending on where the annotation is declared, the parameters |
| 29 | * may have different default values. |
| 30 | * <p> |
| 31 | * This annotation is used to declare <reference> elements of the |
| 32 | * component declaration. See section 112.4.7, Reference Element, in the OSGi |
| 33 | * Service Platform Service Compendium Specification for more information. |
| 34 | */ |
| 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 Reference { |
| 39 | |
| 40 | /** |
| 41 | * The local name of the reference. If the annotation is declared on class |
| 42 | * level, this parameter is required. If the tag is declared for a field, |
| 43 | * the default value for the name parameter is the name of the field. |
| 44 | */ |
| 45 | String name() default ""; |
| 46 | |
| 47 | /** |
| 48 | * The name of the service interface. This name is used by the Service |
| 49 | * Component Runtime to access the service on behalf of the component. If |
| 50 | * the annotation is declared on class level, this parameter is required. If |
| 51 | * the annotation is declared for a field, the default value for the |
| 52 | * interface parameter is the type of the field. |
| 53 | */ |
Carsten Ziegeler | 27764de | 2009-04-16 09:39:33 +0000 | [diff] [blame] | 54 | Class<?> referenceInterface() default AutoDetect.class; |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * The cardinality of the service reference. This must be one of 0..1, 1..1, |
| 58 | * 0..n, and 1..n. |
| 59 | */ |
Carsten Ziegeler | 27764de | 2009-04-16 09:39:33 +0000 | [diff] [blame] | 60 | ReferenceCardinality cardinality() default ReferenceCardinality.MANDATORY_UNARY; |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * The dynamicity policy of the reference. If dynamic the service will be |
| 64 | * made available to the component as it comes and goes. If static the |
| 65 | * component will be deactivated and re-activated if the service comes |
| 66 | * and/or goes away. |
| 67 | */ |
| 68 | ReferencePolicy policy() default ReferencePolicy.STATIC; |
| 69 | |
| 70 | /** |
| 71 | * A service target filter to select specific services to be made available. |
| 72 | * In order to be able to overwrite the value of this value by a |
| 73 | * configuration property, this parameter must be declared. If the parameter |
| 74 | * is not declared, the respective declaration attribute will not be |
| 75 | * generated. |
| 76 | */ |
| 77 | String target() default ""; |
| 78 | |
| 79 | /** |
| 80 | * The name of the method to be called when the service is to be bound to |
| 81 | * the component. The default value is the name created by appending the |
| 82 | * reference name to the string bind. The method must be declared |
| 83 | * <code>public</code> or <code>protected</code> and take single argument |
| 84 | * which is declared with the service interface type. |
| 85 | */ |
| 86 | String bind() default ""; |
| 87 | |
| 88 | /** |
| 89 | * The name of the method to be called when the service is to be unbound |
| 90 | * from the component. The default value is the name created by appending |
| 91 | * the reference name to the string unbind. The method must be declared |
| 92 | * <code>public</code> or <code>protected</code> and take single argument |
| 93 | * which is declared with the service interface type. |
| 94 | */ |
| 95 | String unbind() default ""; |
| 96 | |
| 97 | /** |
Carsten Ziegeler | eff7ff7 | 2009-12-07 15:33:57 +0000 | [diff] [blame^] | 98 | * The name of the method to be called when the bound service updates its |
| 99 | * service registration properties. By default this is not set. |
| 100 | */ |
| 101 | String updated() default ""; |
| 102 | |
| 103 | /** |
Carsten Ziegeler | 104fd02 | 2009-07-02 13:04:52 +0000 | [diff] [blame] | 104 | * The reference strategy for the reference. This can either be |
| 105 | * {@link ReferenceStrategy#EVENT} in which case the bind and unbind |
| 106 | * methods are used or it can be {@link ReferenceStrategy#LOOKUP} |
| 107 | * in which case the reference is looked up through the |
| 108 | * component context. |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 109 | */ |
Carsten Ziegeler | 6e0c933 | 2009-06-12 16:05:22 +0000 | [diff] [blame] | 110 | ReferenceStrategy strategy() default ReferenceStrategy.EVENT; |
Carsten Ziegeler | 5de92da | 2009-03-31 17:12:40 +0000 | [diff] [blame] | 111 | } |