Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the specification of BeanManager.getInjectableReference() to CDI Full #676

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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