@Retention(value=CLASS) @Target(value={METHOD,FIELD,PARAMETER}) public @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.
Modifier and Type | Optional Element and Description |
---|---|
String |
bind
The name of the bind method for this reference.
|
ReferenceCardinality |
cardinality
The cardinality of this reference.
|
CollectionType |
collectionType
The collection type for this reference.
|
String |
field
The name of the field for this reference.
|
FieldOption |
fieldOption
The field option for this reference.
|
String |
name
The name of this reference.
|
int |
parameter
The zero-based parameter number of the constructor parameter for this
reference.
|
ReferencePolicy |
policy
The policy for this reference.
|
ReferencePolicyOption |
policyOption
The policy option for this reference.
|
ReferenceScope |
scope
The reference scope for this reference.
|
Class<?> |
service
The type of the service for this reference.
|
String |
target
The target property for this reference.
|
String |
unbind
The name of the unbind method for this reference.
|
String |
updated
The name of the updated method for this reference.
|
public abstract String name
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:
bind
,
set
or add
, that prefix is removed to create the name of
the reference. Otherwise, the name of the reference is the method
name.public abstract Class<?> service
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:
0..n
,
or 1..n
, the type of the field
must be one of java.util.Collection
, java.util.List
, or a
subtype of java.util.Collection
, so the type of the service is
the generic type of the collection. If the cardinality is either
0..1
or
1..1
, and the type of the field is
java.util.Optional
, the type of the service is the generic type
of the java.util.Optional
. Otherwise, the type of the service is
the type of the field.0..n
, or
1..n
, the type of the parameter
must be one of java.util.Collection
or java.util.List
, so
the type of the service is the generic type of the collection. If the
cardinality is either 0..1
or
1..1
, and the type of the
parameter is java.util.Optional
, the type of the service is the
generic type of the java.util.Optional
. Otherwise, the type of
the service is the type of the parameter.AnyService
public abstract ReferenceCardinality cardinality
If not specified, the cardinality of this reference is based upon how this annotation is used:
1..1
.java.util.Collection
,
java.util.List
, or a subtype of java.util.Collection
, the
cardinality is 0..n
. If the type is
java.util.Optional
, the cardinality is
0..1
. Otherwise the cardinality is
1..1
.java.util.Collection
or java.util.List
, the cardinality is
0..n
. If the type is
java.util.Optional
, the cardinality is
0..1
. Otherwise the cardinality is
1..1
.Component.reference()
element - The cardinality is
1..1
.public abstract ReferencePolicy policy
If not specified, the policy of this reference is based upon how this annotation is used:
STATIC
.volatile
, the policy is
ReferencePolicy.DYNAMIC
. Otherwise the policy is
STATIC
.STATIC
. STATIC policy must be used for
constructor parameters.Component.reference()
element - The policy is
STATIC
.public abstract String target
If not specified, no target property is set. A target property must be
specified if the service()
element refers to AnyService
.
public abstract ReferencePolicyOption policyOption
If not specified, the RELUCTANT
reference policy option is used.
public abstract ReferenceScope scope
If not specified, the bundle
reference
scope is used.
public abstract String bind
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:
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.
public abstract String updated
If not specified, the name of the updated method is based upon how this annotation is used:
bind
, set
or add
, that prefix is replaced
with updated
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.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.
public abstract String unbind
If not specified, the name of the unbind method is based upon how this annotation is used:
bind
, set
or add
, that prefix is replaced
with unbind
, unset
or remove
, 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.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.
public abstract String field
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:
Component.reference()
element - There is no field name.If there is a field name, the component must contain a field with that name.
public abstract FieldOption fieldOption
If not specified, the field option is based upon how this annotation is used:
ReferencePolicy.DYNAMIC
, the cardinality is
0..n
or
1..n
, and the field is declared
final
, the field option is FieldOption.UPDATE
. Otherwise,
the field option is FieldOption.REPLACE
.Component.reference()
element - There is no field
option.public abstract int parameter
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:
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.
public abstract CollectionType collectionType
If not specified, the collection type is based upon how this annotation is used:
0..n
or
1..n
, the collection type is
inferred from the generic type of the java.util.Collection
. If
the cardinality is either 0..1
or
1..1
, and the type of the field is
java.util.Optional
, the collection type is inferred from the
generic type of the java.util.Optional
. Otherwise, there is no
collection type0..n
or
1..n
, the collection type is
inferred from the generic type of the java.util.Collection
. If
the cardinality is either 0..1
or
1..1
, and the type of the
parameter is java.util.Optional
, the collection type is inferred
from the generic type of the java.util.Optional
. Otherwise, there
is no collection typeComponent.reference()
element - There is no collection
type.Copyright © Contributors to the Eclipse Foundation Licensed under the Eclipse Foundation Specification License – v1.0