Class AbstractResourceServices

java.lang.Object
org.jboss.weld.injection.spi.helpers.AbstractResourceServices
All Implemented Interfaces:
Service, ResourceInjectionServices

public abstract class AbstractResourceServices extends Object implements Service, ResourceInjectionServices
Abstract subclass for ResourceInjectionServices defining several common capabilities.
  • Constructor Details

    • AbstractResourceServices

      public AbstractResourceServices()
  • Method Details

    • resolveResource

      public Object resolveResource(jakarta.enterprise.inject.spi.InjectionPoint injectionPoint)
      Verifies that provided InjectionPoint has Resource annotation on it, extracts resource name from it and then invokes Context.lookup(String).
      Parameters:
      injectionPoint - injection points to inspect
      Returns:
      resource
    • resolveResource

      public Object resolveResource(String jndiName, String mappedName)
      Uses provided parameters to look up the resource via Context.lookup(String)
      Parameters:
      jndiName - jndi name of the resource, may be null
      mappedName - mappedName of the resource, may be null
      Returns:
      looked up resource
    • getResourceName

      protected String getResourceName(String jndiName, String mappedName)
      Returns a String representation of the resource name from provided parameters. mappedName takes precedence over jndiName unless it is null. Throws IllegalArgumentException if both parameters are null.
      Parameters:
      jndiName - jndiName or null
      mappedName - mappedName or null
      Returns:
      String representation of the resource name
    • getContext

      protected abstract Context getContext()
      Returns the Context instance.
      Returns:
      Context instance
    • getResourceName

      protected String getResourceName(jakarta.enterprise.inject.spi.InjectionPoint injectionPoint)
      Retrieves the Resource annotation from provided InjectionPoint and extracts resource name from it.
      Parameters:
      injectionPoint - injection point to inspect
      Returns:
      String representation of resource name
    • getPropertyName

      public static String getPropertyName(Method method)
      Returns property name as a String extracted from given method by looking at its name and stripping its prefix. May return null if the method name does not start with set/get/is prefix.
      Parameters:
      method - method to parse property name from
      Returns:
      property name or null if the name cannot be parsed
    • registerResourceInjectionPoint

      public ResourceReferenceFactory<Object> registerResourceInjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint injectionPoint)
      Description copied from interface: ResourceInjectionServices
      Register a resource injection point. The implementation validates the injection point. If the validation passes, an instance of ResourceReferenceFactory is returned which may be used at runtime for creating instances of the resource.
      Specified by:
      registerResourceInjectionPoint in interface ResourceInjectionServices
      Parameters:
      injectionPoint - the injection point metadata
      Returns:
      resource factory
    • registerResourceInjectionPoint

      public ResourceReferenceFactory<Object> registerResourceInjectionPoint(String jndiName, String mappedName)
      Description copied from interface: ResourceInjectionServices
      Register a resource injection point with the given JNDI name and mapped name. The implementation validates the injection point. If the validation passes, an instance of ResourceReferenceFactory is returned which may be used at runtime for creating instances of the resource.
      Specified by:
      registerResourceInjectionPoint in interface ResourceInjectionServices
      Parameters:
      jndiName - JNDI name
      mappedName - mapped name
      Returns:
      resource factory
    • getResourceAnnotation

      protected jakarta.annotation.Resource getResourceAnnotation(jakarta.enterprise.inject.spi.InjectionPoint injectionPoint)
      Parses the Resource annotation from given InjectionPoint.
      Parameters:
      injectionPoint - Injection point to parse the annotation from
      Returns:
      Instance of Resource annotation if present, null otherwise
    • cleanup

      public void cleanup()
      Description copied from interface: Service
      Called by Weld when it is shutting down, allowing the service to perform any cleanup needed.
      Specified by:
      cleanup in interface Service