Annotation Interface Reference
When the annotation is applied to a method, the method is the bind method of the reference.
When the annotation is applied to a field, the field will contain the bound service(s) of the reference.
When the annotation is applied to a parameter of a constructor, the parameter will contain the bound service(s) of the reference.
This annotation is not processed at runtime by Service Component Runtime. It must be processed by tools and used to add a Component Description to the bundle.
In the generated Component Description for a component, the references must
be ordered in ascending lexicographical order (using String.compareTo
) of the reference name
s.
- See Also:
-
- "The reference element of a Component Description."
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionThe name of the bind method for this reference.The cardinality of this reference.The collection type for this reference.The name of the field for this reference.The field option for this reference.The name of this reference.int
The zero-based parameter number of the constructor parameter for this reference.The policy for this reference.The policy option for this reference.The reference scope for this reference.Class<?>
The type of the service for this reference.The target property for this reference.The name of the unbind method for this reference.The name of the updated method for this reference.
-
Element Details
-
name
String nameThe name of this reference.The name of this reference must be specified when using this annotation in the
Component.reference()
element since there is no annotated member from which the name can be determined. If not specified, the name of this reference is based upon how this annotation is used:- Annotated method - If the method name begins with
bind
,set
oradd
, that prefix is removed to create the name of the reference. Otherwise, the name of the reference is the method name. - Annotated field - The name of the reference is the field name.
- Annotated constructor parameter - The name of the reference is the parameter name.
- See Also:
-
- "The name attribute of the reference element of a Component Description."
- Default:
- ""
- Annotated method - If the method name begins with
-
service
Class<?> serviceThe type of the service for this reference.The type of the service for this reference must be specified when using this annotation in the
Component.reference()
element since there is no annotated member from which the type of the service can be determined.If not specified, the type of the service for this reference is based upon how this annotation is used:
- Annotated method - The type of the service is the type of the first parameter of the method.
- Annotated field - The type of the service is based upon the
cardinality of the reference and the type of the field being annotated.
If the cardinality is either
0..n
, or1..n
, the type of the field must be one ofjava.util.Collection
,java.util.List
, or a subtype ofjava.util.Collection
, so the type of the service is the generic type of the collection. If the cardinality is either0..1
or1..1
, and the type of the field isjava.util.Optional
, the type of the service is the generic type of thejava.util.Optional
. Otherwise, the type of the service is the type of the field. - Annotated constructor parameter - The type of the service is based
upon the cardinality of the reference and the type of the parameter being
annotated. If the cardinality is either
0..n
, or1..n
, the type of the parameter must be one ofjava.util.Collection
orjava.util.List
, so the type of the service is the generic type of the collection. If the cardinality is either0..1
or1..1
, and the type of the parameter isjava.util.Optional
, the type of the service is the generic type of thejava.util.Optional
. Otherwise, the type of the service is the type of the parameter.
- See Also:
-
- "The interface attribute of the reference element of a Component Description."
AnyService
- Default:
- java.lang.Object.class
-
cardinality
ReferenceCardinality cardinalityThe cardinality of this reference.If not specified, the cardinality of this reference is based upon how this annotation is used:
- Annotated method - The cardinality is
1..1
. - Annotated field - The cardinality is based on the type of the field.
If the type is either
java.util.Collection
,java.util.List
, or a subtype ofjava.util.Collection
, the cardinality is0..n
. If the type isjava.util.Optional
, the cardinality is0..1
. Otherwise the cardinality is1..1
. - Annotated constructor parameter - The cardinality is based on the
type of the parameter. If the type is either
java.util.Collection
orjava.util.List
, the cardinality is0..n
. If the type isjava.util.Optional
, the cardinality is0..1
. Otherwise the cardinality is1..1
. Component.reference()
element - The cardinality is1..1
.
- See Also:
-
- "The cardinality attribute of the reference element of a Component Description."
- Default:
- MANDATORY
- Annotated method - The cardinality is
-
policy
ReferencePolicy policyThe policy for this reference.If not specified, the policy of this reference is based upon how this annotation is used:
- Annotated method - The policy is
STATIC
. - Annotated field - The policy is based on the modifiers of the field.
If the field is declared
volatile
, the policy isReferencePolicy.DYNAMIC
. Otherwise the policy isSTATIC
. - Annotated constructor parameter - The policy is
STATIC
. STATIC policy must be used for constructor parameters. Component.reference()
element - The policy isSTATIC
.
- See Also:
-
- "The policy attribute of the reference element of a Component Description."
- Default:
- STATIC
- Annotated method - The policy is
-
target
String targetThe target property for this reference.If not specified, no target property is set. A target property must be specified if the
service()
element refers toAnyService
.- See Also:
-
- "The target attribute of the reference element of a Component Description."
- Default:
- ""
-
policyOption
ReferencePolicyOption policyOptionThe policy option for this reference.If not specified, the
RELUCTANT
reference policy option is used.- Since:
- 1.2
- See Also:
-
- "The policy-option attribute of the reference element of a Component Description."
- Default:
- RELUCTANT
-
scope
ReferenceScope scopeThe reference scope for this reference.If not specified, the
bundle
reference scope is used.- Since:
- 1.3
- See Also:
-
- "The scope attribute of the reference element of a Component Description."
- Default:
- BUNDLE
-
bind
String bindThe name of the bind method for this reference.If specified and this reference annotates a method, the specified name must match the name of the annotated method.
If not specified, the name of the bind method is based upon how this annotation is used:
- Annotated method - The name of the annotated method is the name of the bind method.
- Annotated field - There is no bind method name.
- Annotated constructor parameter - There is no bind method name.
Component.reference()
element - There is no bind method name.
If there is a bind method name, the component must contain a method with that name.
- Since:
- 1.3
- See Also:
-
- "The bind attribute of the reference element of a Component Description."
- Default:
- ""
-
updated
String updatedThe name of the updated method for this reference.If not specified, the name of the updated method is based upon how this annotation is used:
- Annotated method - The name of the updated method is created from the
name of the annotated method. If the name of the annotated method begins
with
bind
,set
oradd
, that prefix is replaced withupdated
to create the name candidate for the updated method. Otherwise,updated
is prefixed to the name of the annotated method to create the name candidate for the updated method. If the component type contains a method with the candidate name, the candidate name is used as the name of the updated method. To declare no updated method when the component type contains a method with the candidate name, the value"-"
must be used. - Annotated field - There is no updated method name.
- Annotated constructor parameter - There is no updated method name.
Component.reference()
element - There is no updated method name.
If there is an updated method name, the component must contain a method with that name.
- Since:
- 1.2
- See Also:
-
- "The updated attribute of the reference element of a Component Description."
- Default:
- ""
- Annotated method - The name of the updated method is created from the
name of the annotated method. If the name of the annotated method begins
with
-
unbind
String unbindThe name of the unbind method for this reference.If not specified, the name of the unbind method is based upon how this annotation is used:
- Annotated method - The name of the unbind method is created from the
name of the annotated method. If the name of the annotated method begins
with
bind
,set
oradd
, that prefix is replaced withunbind
,unset
orremove
, respectively, to create the name candidate for the unbind method. Otherwise,un
is prefixed to the name of the annotated method to create the name candidate for the unbind method. If the component type contains a method with the candidate name, the candidate name is used as the name of the unbind method. To declare no unbind method when the component type contains a method with the candidate name, the value"-"
must be used. - Annotated field - There is no unbind method name.
- Annotated constructor parameter - There is no unbind method name.
Component.reference()
element - There is no unbind method name.
If there is an unbind method name, the component must contain a method with that name.
- See Also:
-
- "The unbind attribute of the reference element of a Component Description."
- Default:
- ""
- Annotated method - The name of the unbind method is created from the
name of the annotated method. If the name of the annotated method begins
with
-
field
String fieldThe name of the field for this reference.If specified and this reference annotates a field, the specified name must match the name of the annotated field.
If not specified, the name of the field is based upon how this annotation is used:
- Annotated method - There is no field name.
- Annotated field - The name of the annotated field is the name of the field.
- Annotated constructor parameter - There is no field name.
Component.reference()
element - There is no field name.
If there is a field name, the component must contain a field with that name.
- Since:
- 1.3
- See Also:
-
- "The field attribute of the reference element of a Component Description."
- Default:
- ""
-
fieldOption
FieldOption fieldOptionThe field option for this reference.If not specified, the field option is based upon how this annotation is used:
- Annotated method - There is no field option.
- Annotated field - The field option is based upon the policy and
cardinality of the reference and the modifiers of the field. If the
policy is
ReferencePolicy.DYNAMIC
, the cardinality is0..n
or1..n
, and the field is declaredfinal
, the field option isFieldOption.UPDATE
. Otherwise, the field option isFieldOption.REPLACE
. - Annotated constructor parameter - There is no field option.
Component.reference()
element - There is no field option.
- Since:
- 1.3
- See Also:
-
- "The field-option attribute of the reference element of a Component Description."
- Default:
- REPLACE
-
parameter
int parameterThe zero-based parameter number of the constructor parameter for this reference.If specified and this reference annotates an constructor parameter, the specified value must match the zero-based parameter number of the annotated constructor parameter.
If not specified, the parameter number is based upon how this annotation is used:
- Annotated method - There is no parameter number.
- Annotated field - There is no parameter number.
- Annotated constructor parameter - The zero-based parameter number of the parameter.
Component.reference()
element - There is no parameter number.
If there is a parameter number, the component must declare a constructor that has a parameter having the zero-based parameter number.
- Since:
- 1.4
- See Also:
-
- "The parameter attribute of the reference element of a Component Description."
- "The init attribute of the component element of a Component Description."
- Default:
- 0
-
collectionType
CollectionType collectionTypeThe collection type for this reference.If not specified, the collection type is based upon how this annotation is used:
- Annotated method - There is no collection type.
- Annotated field - The collection type is based upon the cardinality
of the reference and the type of the field. If the cardinality is either
0..n
or1..n
, the collection type is inferred from the generic type of thejava.util.Collection
. If the cardinality is either0..1
or1..1
, and the type of the field isjava.util.Optional
, the collection type is inferred from the generic type of thejava.util.Optional
. Otherwise, there is no collection type - Annotated constructor method parameter - The collection type is based
upon the cardinality of the reference and the type of the parameter. If
the cardinality is either
0..n
or1..n
, the collection type is inferred from the generic type of thejava.util.Collection
. If the cardinality is either0..1
or1..1
, and the type of the parameter isjava.util.Optional
, the collection type is inferred from the generic type of thejava.util.Optional
. Otherwise, there is no collection type Component.reference()
element - There is no collection type.
- Since:
- 1.4
- See Also:
-
- "The field-collection-type attribute of the reference element of a Component Description."
- Default:
- SERVICE
-