blob: 9db25db9e407b345dedfcdc2c634c1bce27a8f7a [file] [log] [blame]
Carsten Ziegeler5de92da2009-03-31 17:12:40 +00001/*
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 Ziegelerba751bd2009-04-18 18:31:43 +000019package org.apache.felix.scr.annotations;
Carsten Ziegeler5de92da2009-03-31 17:12:40 +000020
Carsten Ziegelerb5618fe2009-03-31 17:18:17 +000021import java.lang.annotation.*;
Carsten Ziegeler5de92da2009-03-31 17:12:40 +000022
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 &lt;reference&gt; 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 Ziegeler1993d102009-04-07 16:16:47 +000036@Retention(RetentionPolicy.SOURCE)
Carsten Ziegeler5de92da2009-03-31 17:12:40 +000037@Documented
38public @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 Ziegeler27764de2009-04-16 09:39:33 +000054 Class<?> referenceInterface() default AutoDetect.class;
Carsten Ziegeler5de92da2009-03-31 17:12:40 +000055
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 Ziegeler27764de2009-04-16 09:39:33 +000060 ReferenceCardinality cardinality() default ReferenceCardinality.MANDATORY_UNARY;
Carsten Ziegeler5de92da2009-03-31 17:12:40 +000061
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 Ziegelereff7ff72009-12-07 15:33:57 +000098 * 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 Ziegeler104fd022009-07-02 13:04:52 +0000104 * 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 Ziegeler5de92da2009-03-31 17:12:40 +0000109 */
Carsten Ziegeler6e0c9332009-06-12 16:05:22 +0000110 ReferenceStrategy strategy() default ReferenceStrategy.EVENT;
Carsten Ziegeler5de92da2009-03-31 17:12:40 +0000111}