Enum ServiceCardinality
- All Implemented Interfaces:
Serializable,Comparable<ServiceCardinality>
The cardinality of a service being injected is controlled via the type of the injected
parameter and additionally via the
The cardinality can be either
The other aspect of cardinality, namely whether a single service or multiple services should be injected, is controlled via the type of the annotated field. For single service injection, the field's type is expected to be the type of the injected service. For multiple service injection, the field's type is expected to be a
Any further constraints, i.e. checking for an exact number or a range of services must be done via assertions.
@Service annotation's cardinality
attribute.
The cardinality can be either
OPTIONAL or MANDATORY. OPTIONAL
does not require the presence of a service, whereas MANDATORY requires at
least one service to be present, otherwise an exception is thrown.
The other aspect of cardinality, namely whether a single service or multiple services should be injected, is controlled via the type of the annotated field. For single service injection, the field's type is expected to be the type of the injected service. For multiple service injection, the field's type is expected to be a
Collection or
List with the type of the injected service as its generic type-argument.
Any further constraints, i.e. checking for an exact number or a range of services must be done via assertions.
- See Also:
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionFor unary service injection,AUTOdefaults toMANDATORY.At least one service must be present, otherwise aParameterResolutionExceptionis thrown.If no service is present,nullis injected for unary service injection, and an emptyListis injected for multiple service injection. -
Method Summary
Modifier and TypeMethodDescriptionstatic ServiceCardinalityReturns the enum constant of this type with the specified name.static ServiceCardinality[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
AUTO
For unary service injection,AUTOdefaults toMANDATORY. Whereas for multiple service injection,AUTOdefaults toOPTIONAL. -
OPTIONAL
If no service is present,nullis injected for unary service injection, and an emptyListis injected for multiple service injection. -
MANDATORY
At least one service must be present, otherwise aParameterResolutionExceptionis thrown.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-