Class Hk2Helper

java.lang.Object
org.glassfish.jersey.inject.hk2.Hk2Helper

class Hk2Helper extends Object
This class contains the convenient methods for translation from jersey classes to HK2 and visa versa, then contains methods for binding structures such as Binder or Binding to a provided service locator.
  • Constructor Details

    • Hk2Helper

      Hk2Helper()
  • Method Details

    • bind

      static void bind(AbstractHk2InjectionManager injectionManager, Binder jerseyBinder)
      Bind a translated Jersey-like Binder to HK2-like Binder.
      Parameters:
      injectionManager - HK2 injection manager.
      jerseyBinder - Jersey-like binder.
    • bind

      static void bind(org.glassfish.hk2.api.ServiceLocator locator, Binding binding)
      Bind descriptors to Hk2-like Binder.
      Parameters:
      locator - HK2 locator.
      binding - single descriptor.
    • bind

      static void bind(org.glassfish.hk2.api.ServiceLocator locator, Iterable<Binding> descriptors)
      Bind descriptors to Hk2-like Binder.
      Parameters:
      locator - HK2 locator.
      descriptors - collection of descriptors.
    • getDynamicConfiguration

      private static org.glassfish.hk2.api.DynamicConfiguration getDynamicConfiguration(org.glassfish.hk2.api.ServiceLocator locator)
      Gets DynamicConfigurationService object from HK2 Locator and creates a new object of DynamicConfiguration to bind new services.
      Parameters:
      locator - HK2 locator.
      Returns:
      new instance of DynamicConfiguration to bind new services.
    • bindBinding

      private static void bindBinding(org.glassfish.hk2.api.ServiceLocator locator, Binding<?,?> binding)
      Binds the single descriptor using a single DynamicConfiguration.
      Parameters:
      locator - HK2 injection manager.
      binding - Jersey descriptor as a holder of information about an injection point.
    • bindBinding

      private static void bindBinding(org.glassfish.hk2.api.ServiceLocator locator, org.glassfish.hk2.api.DynamicConfiguration dc, Binding<?,?> binding)
      Binds the single descriptor using an external DynamicConfiguration.
      Parameters:
      locator - HK2 injection manager.
      dc - HK2 Dynamic configuration to bind the object.
      binding - Jersey descriptor as a holder of information about an injection point.
    • wrapInjectionResolver

      private static org.glassfish.hk2.api.ActiveDescriptor<?> wrapInjectionResolver(InjectionResolverBinding resolverDescriptor)
    • bindSupplierInstanceBinding

      private static void bindSupplierInstanceBinding(org.glassfish.hk2.api.ServiceLocator locator, SupplierInstanceBinding<?> binding)
      Registers a new instance Binder using the information from the Jersey binding SupplierInstanceBinding.
      Parameters:
      locator - HK2 instance manager.
      binding - Jersey descriptor as a holder of information about an injection point.
    • bindSupplierClassBinding

      private static void bindSupplierClassBinding(org.glassfish.hk2.api.ServiceLocator locator, SupplierClassBinding<?> binding)
      Registers a new instance Binder using the information from the Jersey binding SupplierClassBinding.
      Parameters:
      locator - HK2 instance manager.
      binding - Jersey descriptor as a holder of information about an injection point.
    • setupSupplierFactoryBridge

      private static void setupSupplierFactoryBridge(Binding<?,?> binding, org.glassfish.hk2.utilities.binding.ServiceBindingBuilder<?> builder)
    • translateToActiveDescriptor

      static org.glassfish.hk2.api.ActiveDescriptor<?> translateToActiveDescriptor(ClassBinding<?> desc)
    • bindBinding

      private static void bindBinding(org.glassfish.hk2.api.ServiceLocator locator, org.glassfish.hk2.api.DynamicConfiguration dc, org.glassfish.hk2.api.ActiveDescriptor<?> activeDescriptor, Set<AliasBinding> aliases)
      Binds a new instance Binding using the information from the Jersey descriptor InstanceBinding.

      Along with a new instance, the method is able to register aliases belonging to the new service.

      Parameters:
      locator - HK2 injection manager.
      dc - HK2 Dynamic configuration to bind the object.
      activeDescriptor - HK2 active descriptor.
      aliases - aliases belonging to the given descriptor.
    • translateToActiveDescriptor

      static org.glassfish.hk2.api.ActiveDescriptor<?> translateToActiveDescriptor(InstanceBinding<?> desc, Type... contracts)
    • translateToActiveDescriptor

      private static org.glassfish.hk2.api.ActiveDescriptor<?> translateToActiveDescriptor(InjectionResolverBinding<?> desc)
    • createAlias

      private static org.glassfish.hk2.utilities.AliasDescriptor<?> createAlias(org.glassfish.hk2.api.ServiceLocator locator, org.glassfish.hk2.api.ActiveDescriptor<?> descriptor, AliasBinding alias)
      Creates the alias object to a provided descriptor.
      Parameters:
      locator - locator used to create an alias.
      descriptor - descriptor which the alias belongs to.
      alias - source of the alias information.
      Returns:
      populated alias object, ready to bindBinder using DynamicConfiguration.
    • createBinder

      private static org.glassfish.hk2.utilities.Binder createBinder(Consumer<org.glassfish.hk2.utilities.binding.AbstractBinder> bindConsumer)
      Creates a new binder and automatically use it to bind the the descriptors in bindConsumer.
      Parameters:
      bindConsumer - consumer used to process the defined operation with a binder.
      Returns:
      populated binder.
    • transformScope

      private static Class<? extends Annotation> transformScope(Class<? extends Annotation> scope)
      Transforms Jersey scopes/annotations to HK2 equivalents.
      Parameters:
      scope - Jersey scope/annotation.
      Returns:
      HK2 equivalent scope/annotation.