Skip to content

Commit

Permalink
Move the specification of BeanManager.getInjectableReference() to CDI…
Browse files Browse the repository at this point in the history
… Full

We previously [1] moved the `getInjectableReference()` from the `BeanContainer`
interface to the `BeanManager` [2], but did not update the specification text
accordingly. Thus, the method is specified in the CDI Lite part of the spec,
but it in fact belongs to CDI Full. This commit moves the spec text around
to fix that.

Additionally, this commit removes the declaration of `resolveObserverMethods()`
from `BeanManager`, because that just overrides the same declaration that is
present on `BeanContainer`.

Finally, this commit moves the declaration of `getInjectableReference()` from
the end of the `BeanManager` source code to the beginning, for symmetry with
the `BeanContainer` declaration and to restore the previous layout.

[1] 520bad1
[2] #568
  • Loading branch information
Ladicek committed May 31, 2023
1 parent 57b1c2c commit 9f6d5d0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 54 deletions.
49 changes: 16 additions & 33 deletions api/src/main/java/jakarta/enterprise/inject/spi/BeanManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@
*/
public interface BeanManager extends BeanContainer {

/**
* <p>
* Obtains an injectable reference for a certain {@linkplain InjectionPoint injection point}.
* </p>
*
* @param ij the target injection point
* @param ctx a {@link CreationalContext} that may be used to destroy any object with scope
* {@link Dependent} that is created
* @return the injectable reference
* @throws UnsatisfiedResolutionException if typesafe resolution results in an unsatisfied dependency
* @throws AmbiguousResolutionException typesafe resolution results in an unresolvable ambiguous dependency
* @throws IllegalStateException if called during application initialization, before the {@link AfterDeploymentValidation}
* event is fired.
*/
Object getInjectableReference(InjectionPoint ij, CreationalContext<?> ctx);

/**
* Returns the {@link PassivationCapable} bean with the given identifier.
*
Expand Down Expand Up @@ -121,24 +137,6 @@ public interface BeanManager extends BeanContainer {
*/
public void validate(InjectionPoint injectionPoint);

/**
* Return an ordered set of {@linkplain ObserverMethod observer methods} for an event.
*
* Note that when called during invocation of an {@link AfterBeanDiscovery} event observer,
* this method will only return observers discovered by the container before the {@link AfterBeanDiscovery} event is fired.
*
* @param <T> the type of the event
* @param event the event object
* @param qualifiers the event qualifiers
* @return the resulting set of {@linkplain ObserverMethod observer methods}
* @throws IllegalArgumentException if the runtime type of the event object contains a type variable
* @throws IllegalArgumentException if two instances of the same non repeating qualifier type are given
* @throws IllegalArgumentException if an instance of an annotation that is not a qualifier type is given
* @throws IllegalStateException if called during application initialization, before the {@link AfterBeanDiscovery}
* event is fired.
*/
public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(T event, Annotation... qualifiers);

/**
* Return an ordered list of {@linkplain Decorator decorators} for a set of bean types and a set of qualifiers and which are
* enabled in the module or library containing the class into which the <code>BeanManager</code> was injected or the Java EE
Expand Down Expand Up @@ -423,19 +421,4 @@ public <T> Bean<T> createBean(BeanAttributes<T> attributes, Class<T> beanClass,
*/
<T> InterceptionFactory<T> createInterceptionFactory(CreationalContext<T> ctx, Class<T> clazz);

/**
* <p>
* Obtains an injectable reference for a certain {@linkplain InjectionPoint injection point}.
* </p>
*
* @param ij the target injection point
* @param ctx a {@link CreationalContext} that may be used to destroy any object with scope
* {@link Dependent} that is created
* @return the injectable reference
* @throws UnsatisfiedResolutionException if typesafe resolution results in an unsatisfied dependency
* @throws AmbiguousResolutionException typesafe resolution results in an unresolvable ambiguous dependency
* @throws IllegalStateException if called during application initialization, before the {@link AfterDeploymentValidation}
* event is fired.
*/
Object getInjectableReference(InjectionPoint ij, CreationalContext<?> ctx);
}
18 changes: 0 additions & 18 deletions spec/src/main/asciidoc/core/beanmanager_lite.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,6 @@ The third parameter is an instance of `CreationalContext` that may be used to de

If the given type is not a bean type of the given bean, an `IllegalArgumentException` is thrown.

[[bm_obtain_injectable_reference]]

==== Obtaining an injectable reference

The method `BeanContainer.getInjectableReference()` returns an injectable reference for a given injection point, as defined in <<injectable_reference>>.

[source, java]
----
public Object getInjectableReference(InjectionPoint ij, CreationalContext<?> ctx);
----

The first parameter represents the target injection point.
The second parameter is an instance of `CreationalContext` that may be used to destroy any object with scope `@Dependent` that is created.

If typesafe resolution results in an unsatisfied dependency, the container must throw an `UnsatisfiedResolutionException`. If typesafe resolution results in an unresolvable ambiguous dependency, the container must throw an `AmbiguousResolutionException`.

Implementations of `Bean` usually maintain a reference to an instance of `BeanContainer`. When the `Bean` implementation performs dependency injection, it must obtain the contextual instances to inject by calling `BeanContainer.getInjectableReference()`, passing an instance of `InjectionPoint` that represents the injection point and the instance of `CreationalContext` that was passed to `Bean.create()`.

[[bm_obtain_creationalcontext]]

==== Obtaining a `CreationalContext`
Expand Down
19 changes: 16 additions & 3 deletions spec/src/main/asciidoc/core/spi_full.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,27 @@ A portable extension or other object may obtain a reference to the current conta
`CDI.getBeanManager()` and `CDI.getBeanContainer()` may be called at any time after the container fires the `BeforeBeanDiscovery` container lifecycle event until the container fires the `BeforeShutdown` container lifecycle event.
If methods on `CDI` are called at any other time, non-portable behavior results.

[[bm_obtain_injectable_reference_full]]
[[bm_obtain_injectable_reference]]

==== Obtaining an injectable reference in {cdi_full}
==== Obtaining an injectable reference

In addition to rules defined in <<bm_obtain_injectable_reference>>, the following rules apply.
The method `BeanManager.getInjectableReference()` returns an injectable reference for a given injection point, as defined in <<injectable_reference>>.

[source, java]
----
public Object getInjectableReference(InjectionPoint ij, CreationalContext<?> ctx);
----

The first parameter represents the target injection point.
The second parameter is an instance of `CreationalContext` that may be used to destroy any object with scope `@Dependent` that is created.

If the `InjectionPoint` represents a decorator delegate injection point, `getInjectableReference()` returns a delegate, as defined in <<delegate_attribute>>.

If typesafe resolution results in an unsatisfied dependency, the container must throw an `UnsatisfiedResolutionException`. If typesafe resolution results in an unresolvable ambiguous dependency, the container must throw an `AmbiguousResolutionException`.

Implementations of `Bean` usually maintain a reference to an instance of `BeanManager`. When the `Bean` implementation performs dependency injection, it must obtain the contextual instances to inject by calling `BeanManager.getInjectableReference()`, passing an instance of `InjectionPoint` that represents the injection point and the instance of `CreationalContext` that was passed to `Bean.create()`.


[[bm_obtain_unmanaged_instance]]

==== Obtaining non-contextual instance
Expand Down

0 comments on commit 9f6d5d0

Please sign in to comment.