blob: 4fffce54b3954d421d7f2b98962ff8e1ac7f076a [file] [log] [blame]
Stuart McCulloch26e7a5a2011-10-17 10:31:43 +00001/*
2 * Copyright (c) OSGi Alliance (2011). All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.osgi.service.component.annotations;
18
19import java.lang.annotation.ElementType;
20import java.lang.annotation.Retention;
21import java.lang.annotation.RetentionPolicy;
22import java.lang.annotation.Target;
23
24/**
25 * Identify the annotated method as a {@code bind} method of a Service
26 * Component.
27 *
28 * <p>
29 * The annotated method is a bind method of the Component.
30 *
31 * <p>
32 * This annotation is not processed at runtime by a Service Component Runtime
33 * implementation. It must be processed by tools and used to add a Component
34 * Description to the bundle.
35 *
36 * @see "The reference element of a Component Description."
37 * @version $Id$
38 */
39@Retention(RetentionPolicy.CLASS)
40@Target(ElementType.METHOD)
41public @interface Reference {
42 /**
43 * The name of this reference.
44 *
45 * <p>
46 * If not specified, the name of this reference is based upon the name of
47 * the method being annotated. If the method name begins with {@code set} or
48 * {@code add}, that is removed.
49 *
50 * @see "The name attribute of the reference element of a Component Description."
51 */
52 String name() default "";
53
54 /**
55 * The type of the service to bind to this reference.
56 *
57 * <p>
58 * If not specified, the type of the service to bind is based upon the type
59 * of the first argument of the method being annotated.
60 *
61 * @see "The interface attribute of the reference element of a Component Description."
62 */
63 Class< ? > service() default Object.class;
64
65 /**
66 * The cardinality of the reference.
67 *
68 * <p>
69 * If not specified, the reference has a
70 * {@link ReferenceCardinality#MANDATORY 1..1} cardinality.
71 *
72 * @see "The cardinality attribute of the reference element of a Component Description."
73 */
74 ReferenceCardinality cardinality() default ReferenceCardinality.MANDATORY;
75
76 /**
77 * The policy for the reference.
78 *
79 * <p>
80 * If not specified, the {@link ReferencePolicy#STATIC STATIC} reference
81 * policy is used.
82 *
83 * @see "The policy attribute of the reference element of a Component Description."
84 */
85 ReferencePolicy policy() default ReferencePolicy.STATIC;
86
87 /**
88 * The target filter for the reference.
89 *
90 * @see "The target attribute of the reference element of a Component Description."
91 */
92 String target() default "";
93
94 /**
95 * The name of the unbind method which pairs with the annotated bind method.
96 *
97 * <p>
98 * To declare no unbind method, the value {@code "-"} must be used.
99 *
100 * <p>
101 * If not specified, the name of the unbind method is derived from the name
102 * of the annotated bind method. If the annotated method name begins with
103 * {@code set}, that is replaced with {@code unset} to derive the unbind
104 * method name. If the annotated method name begins with {@code add}, that
105 * is replaced with {@code remove} to derive the unbind method name.
106 * Otherwise, {@code un} is prefixed to the annotated method name to derive
107 * the unbind method name.
108 *
109 * @see "The unbind attribute of the reference element of a Component Description."
110 */
111 String unbind() default "";
112}