Annotation Interface GenerateServiceFromMethod


@Documented @Retention(RUNTIME) @Target(ANNOTATION_TYPE) public @interface GenerateServiceFromMethod
This annotation is put on user-supplied annotations in order to cause the hk2-inhabitant-generator tool to create descriptors with certain properties.

The user-supplied annotation must have the following properties:

  • Must only apply to methods (or classes also annotated with Decorator)
  • Must be available at runtime
  • Must only be applied to interfaces marked with Configured
  • May have one or zero String fields marked with GeneratedServiceName
Only methods of type java.util.List with a parameterized type (e.g. List) or which take a single parameter and a void return type may be annotated with the user-supplied annotation. The parameterized actual type (or the type of the parameter) will end up being used as a field in the descriptor. A single method may have multiple user-supplied annotations marked with this annotation, in which case a different descriptor will be generated for each user-supplied annotation.

When a method on an Configured interface has a user-supplied annotation that is annotated with this interface the hk2-inhabitant-generator will generate a service descriptor with the following properties:

  • The implementation class will be as specified in this annotation
  • The available contracts will be as specified in this annotation
  • The scope will be as specified in this annotation
  • If the user-supplied annotation has a field marked with GeneratedServiceName it will be the name in the descriptor
  • It will have a metadata entry with the name of the actual type of the List parameterized return type (or the single parametere type) with key METHOD_ACTUAL
  • It will have a metadata entry with the name of the method with key METHOD_NAME
  • It will have a metadata entry with the name of the parent Configured class with key PARENT_CONFGIURED

If a class is annotated with a user-supplied annotation marked with this annotation then that class *must* also be annotated with the Decorate annotation. The Decorate annotation will provide the values for several of the fields as described below.

When a class on an Configured interface has a user-supplied annotation that is annotated with this interface the hk2-inhabitant-generator will generate a service descriptor with the following properties:

  • The implementation class will be as specified in this annotation
  • The available contracts will be as specified in this annotation
  • The scope will be as specified in this annotation
  • The name will come from the field annotated with GeneratedServiceName from the user-supplied annotation defined by the Decorate#with() method
  • It will have a metadata entry with the Decorate#targetType() value with key METHOD_ACTUAL
  • It will have a metadata entry with the Decorate#methodName() value with key METHOD_NAME
  • It will have a metadata entry with the name of the parent Configured class with key PARENT_CONFGIURED
Author:
jwells
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The set of fully qualified class names of the advertised contracts that are to be used in the generated descriptor.
    This must have the fully qualified class name of the implementation that is to be used in the generated descriptor
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The scope that the descriptor should take.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    This is the key in the metadata that will contain the actual type of the List return type of the method where the user-supplied annotation has been placed
    static final String
    This is the key in the metadata that will contain the name of the method where the user-supplied annotation has been placed
    static final String
    This is the key in the metadata that will contain the fully qualified class name of the class marked Configured that contains this annotation
  • Field Details

    • METHOD_ACTUAL

      static final String METHOD_ACTUAL
      This is the key in the metadata that will contain the actual type of the List return type of the method where the user-supplied annotation has been placed
      See Also:
    • METHOD_NAME

      static final String METHOD_NAME
      This is the key in the metadata that will contain the name of the method where the user-supplied annotation has been placed
      See Also:
    • PARENT_CONFIGURED

      static final String PARENT_CONFIGURED
      This is the key in the metadata that will contain the fully qualified class name of the class marked Configured that contains this annotation
      See Also:
  • Element Details

    • implementation

      String implementation
      This must have the fully qualified class name of the implementation that is to be used in the generated descriptor
      Returns:
      The fully qualified class name of the implementation
    • advertisedContracts

      String[] advertisedContracts
      The set of fully qualified class names of the advertised contracts that are to be used in the generated descriptor. Note that the implementation class is not automatically added to this list
      Returns:
      The fully qualified class names of the advertised contracts the generated descriptor should take
    • scope

      String scope
      The scope that the descriptor should take. Defaults to PerLookup
      Returns:
      The fully qualified class names of the scope the descriptor should take
      Default:
      "org.glassfish.hk2.api.PerLookup"