Skip to content

Commit

Permalink
First pass at CDI (#175)
Browse files Browse the repository at this point in the history
* First pass at CDI

* applied feedback

Signed-off-by: Guillermo González de Agüero <z06.guillermo@gmail.com>
  • Loading branch information
ggam authored and bshannon committed Sep 17, 2019
1 parent 39b50b7 commit 06ac437
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 50 deletions.
12 changes: 6 additions & 6 deletions src/main/jbake/content/cdi-adv.adoc
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
type=page
status=published
title=Contexts and Dependency Injection for Jakarta EE: Advanced Topics
title=Jakarta Contexts and Dependency Injection: Advanced Topics
next=cdi-adv001.html
prev=cdi-basicexamples003.html
~~~~~~
= Contexts and Dependency Injection for Jakarta EE: Advanced Topics
= Jakarta Contexts and Dependency Injection: Advanced Topics


[[GJEHI]][[contexts-and-dependency-injection-for-jakarta-ee-advanced-topics]]

27 Contexts and Dependency Injection for Jakarta EE: Advanced Topics
--------------------------------------------------------------------
27 Jakarta Contexts and Dependency Injection: Advanced Topics
-------------------------------------------------------------


This chapter describes more advanced features of Contexts and Dependency
Injection for Jakarta EE (CDI). Specifically, it covers additional features
This chapter describes more advanced features of Jakarta Contexts and Dependency
Injection. Specifically, it covers additional features
CDI provides to enable loose coupling of components with strong typing,
in addition to those described in link:cdi-basic002.html#GIWHL[Overview
of CDI].
Expand Down
2 changes: 1 addition & 1 deletion src/main/jbake/content/cdi-adv001.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ In an implicit archive, CDI can only manage and inject beans annotated
with a scope type.

For a web application, the `beans.xml` deployment descriptor, if
present, must be in the `WEB-INF` directory. For EJB modules or JAR
present, must be in the `WEB-INF` directory. For enterprise bean modules or JAR
files, the `beans.xml` deployment descriptor, if present, must be in the
`META-INF` directory.
6 changes: 3 additions & 3 deletions src/main/jbake/content/cdi-adv003.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ Using Producer Fields to Generate Resources
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A common use of a producer field is to generate an object such as a JDBC
`DataSource` or a Java Persistence API `EntityManager` (see
link:persistence-intro.html#BNBPZ[Chapter 40, "Introduction to the Java
Persistence API,"] for more information). The object can then be managed
`DataSource` or a Jakarta Persistence `EntityManager` (see
link:persistence-intro.html#BNBPZ[Chapter 40, "Introduction to Jakarta
Persistence,"] for more information). The object can then be managed
by the container. For example, you could create a `@UserDatabase`
qualifier and then declare a producer field for an entity manager as
follows:
Expand Down
2 changes: 1 addition & 1 deletion src/main/jbake/content/cdi-adv004.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Using Predefined Beans in CDI Applications
Jakarta EE provides predefined beans that implement the following
interfaces.

* `javax.transaction.UserTransaction`: A Java Transaction API (JTA) user
* `javax.transaction.UserTransaction`: A Jakarta Transactions user
transaction.
* `java.security.Principal`: The abstract notion of a principal, which
represents any entity, such as an individual, a corporation, or a login
Expand Down
2 changes: 1 addition & 1 deletion src/main/jbake/content/cdi-adv006.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ which specifies the tasks the interceptor will perform when intercepted
methods are invoked. It can also contain a method annotated
`@PostConstruct`, `@PreDestroy`, `@PrePassivate`, or `@PostActivate`, to
specify lifecycle callback interceptors, and a method annotated
`@AroundTimeout`, to specify EJB timeout interceptors. An interceptor
`@AroundTimeout`, to specify enterprise bean timeout interceptors. An interceptor
class can contain more than one interceptor method, but it must have no
more than one method of each type.

Expand Down
10 changes: 5 additions & 5 deletions src/main/jbake/content/cdi-basic.adoc
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
type=page
status=published
title=Introduction to Contexts and Dependency Injection for Jakarta EE
title=Introduction to Jakarta Contexts and Dependency Injection
next=cdi-basic001.html
prev=partcdi.html
~~~~~~
= Introduction to Contexts and Dependency Injection for Jakarta EE
= Introduction to Jakarta Contexts and Dependency Injection


[[GIWHB]][[introduction-to-contexts-and-dependency-injection-for-jakarta-ee]]

25 Introduction to Contexts and Dependency Injection for Jakarta EE
-------------------------------------------------------------------
25 Introduction to Jakarta Contexts and Dependency Injection
------------------------------------------------------------


This chapter describes Contexts and Dependency Injection for Jakarta EE
This chapter describes Jakarta Contexts and Dependency Injection
(CDI) which is one of several Jakarta EE features that help to knit
together the web tier and the transactional tier of the Jakarta EE
platform.
Expand Down
14 changes: 7 additions & 7 deletions src/main/jbake/content/cdi-basic002.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ Overview of CDI
---------------

CDI is a set of services that, used together, make it easy for
developers to use enterprise beans along with JavaServer Faces
developers to use enterprise beans along with Jakarta Server Faces
technology in web applications. Designed for use with stateful objects,
CDI also has many broader uses, allowing developers a great deal of
flexibility to integrate various kinds of components in a loosely
coupled but typesafe way

CDI 2.0 is specified by JSR 365. Related specifications that CDI uses
CDI 2.0 is specified in a Jakarta EE specification. Related specifications that CDI uses
include the following:

* JSR 330, Dependency Injection for Java
* Jakarta Dependency Injection
* The Managed Beans specification, an offshoot of the Jakarta EE platform
specification (JSR 366)
specification
The most fundamental services provided by CDI are as follows.

Expand All @@ -38,14 +38,14 @@ which implementation of a particular interface to inject.
In addition, CDI provides the following services:

* Integration with the Expression Language (EL), which allows any
component to be used directly within a JavaServer Faces page or a
JavaServer Pages page
component to be used directly within a Jakarta Server Faces page or a
Jakarta Server Pages page
* The ability to decorate injected components
* The ability to associate interceptors with components using typesafe
interceptor bindings
* An event-notification model
* A web conversation scope in addition to the three standard scopes
(request, session, and application) defined by the Java Servlet
(request, session, and application) defined by the Jakarta Servlet
specification
* A complete Service Provider Interface (SPI) that allows third-party
frameworks to integrate cleanly in the Jakarta EE environment
Expand Down
2 changes: 1 addition & 1 deletion src/main/jbake/content/cdi-basic003.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ About Beans
-----------

CDI redefines the concept of a bean beyond its use in other Java
technologies, such as the JavaBeans and Enterprise JavaBeans (EJB)
technologies, such as the JavaBeans and Jakarta Enterprise Beans
technologies. In CDI, a bean is a source of contextual objects that
define application state or logic. A Jakarta EE component is a bean if
the lifecycle of its instances may be managed by the container according
Expand Down
4 changes: 2 additions & 2 deletions src/main/jbake/content/cdi-basic004.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ following conditions.

* It is not a nonstatic inner class.
* It is a concrete class or is annotated `@Decorator`.
* It is not annotated with an EJB component-defining annotation or
declared as an EJB bean class in `ejb-jar.xml`.
* It is not annotated with an enterprise bean component-defining annotation or
declared as an enterprise bean class in `ejb-jar.xml`.
* It has an appropriate constructor. That is, one of the following is
the case.
Expand Down
4 changes: 2 additions & 2 deletions src/main/jbake/content/cdi-basic005.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Beans as Injectable Objects
---------------------------

The concept of injection has been part of Java technology for some time.
Since the Jakarta EE 5 platform was introduced, annotations have made it
Since the Java EE 5 platform was introduced, annotations have made it
possible to inject resources and some other kinds of objects into
container-managed objects. CDI makes it possible to inject more kinds of
objects and to inject them into objects that are not container-managed.
Expand All @@ -24,7 +24,7 @@ The following kinds of objects can be injected:
* Session beans
* Jakarta EE resources: data sources, Java Message Service topics, queues,
connection factories, and the like
* Persistence contexts (Java Persistence API `EntityManager` objects)
* Persistence contexts (Jakarta Persistence `EntityManager` objects)
* Producer fields
* Objects returned by producer methods
* Web service references
Expand Down
10 changes: 5 additions & 5 deletions src/main/jbake/content/cdi-basic007.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Injecting Beans
---------------

To use the beans you create, you inject them into yet another
bean that can then be used by an application, such as a JavaServer Faces
bean that can then be used by an application, such as a Jakarta Server Faces
application. For example, you might create a bean called `Printer` into
which you would inject one of the `Greeting` beans:

Expand Down Expand Up @@ -43,11 +43,11 @@ public class Printer {
----

More is needed for the complete picture of this bean. Its use of scope
needs to be understood. In addition, for a JavaServer Faces application,
needs to be understood. In addition, for a Jakarta Server Faces application,
the bean needs to be accessible through the EL.

Now that you can identify the target of the injection, it is important to
understand what can be injected and in what context. JSF 2.3 provides producers
that enable most important JSF artifacts to be injected. For detailed information,
see the package https://javaee.github.io/javaee-spec/[javadoc] for
understand what can be injected and in what context. Faces 2.3 provides producers
that enable most important Faces artifacts to be injected. For detailed information,
see the package https://jakarta.ee/specifications/faces/2.3/apidocs/[javadoc] for
`javax.faces.annotation`.
6 changes: 3 additions & 3 deletions src/main/jbake/content/cdi-basic008.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ means that an object exists to serve exactly one client (bean) and has
the same lifecycle as that client (bean).

|Conversation |`@ConversationScoped` |A user's interaction with a
servlet, including JavaServer Faces applications. The conversation scope
servlet, including Jakarta Server Faces applications. The conversation scope
exists within developer-controlled boundaries that extend it across
multiple requests for long-running conversations. All long-running
conversations are scoped to a particular HTTP servlet session and may
not cross session boundaries.
|=======================================================================


The first three scopes are defined by both JSR 365 and the JavaServer
The first three scopes are defined by both JSR 365 and the Jakarta Server
Faces specification. The last two are defined by JSR 365.

All predefined scopes except `@Dependent` are contextual scopes. CDI
Expand All @@ -74,7 +74,7 @@ Jakarta EE components, such as servlets and enterprise beans, and JavaBeans
components do not by definition have a well-defined scope. These
components are one of the following:

* Singletons, such as Enterprise JavaBeans singleton beans, whose state
* Singletons, such as enterprise singleton beans, whose state
is shared among all clients
* Stateless objects, such as servlets and stateless session beans, which
do not contain client-visible state
Expand Down
3 changes: 1 addition & 2 deletions src/main/jbake/content/cdi-basic013.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Jakarta EE deployment descriptors, the configuration settings in
The settings in `beans.xml` override the annotation settings if there is
a conflict. An archive must contain the `beans.xml` deployment
descriptor only in certain limited situations, described in
link:cdi-adv.html#GJEHI[Chapter 27, "Contexts and Dependency Injection
for Jakarta EE: Advanced Topics"].
link:cdi-adv.html#GJEHI[Chapter 27, "Jakarta Contexts and Dependency Injection: Advanced Topics"].

For a web application, the `beans.xml` deployment descriptor, if
present, must be in the `WEB-INF` directory. For EJB modules or JAR
Expand Down
3 changes: 1 addition & 2 deletions src/main/jbake/content/cdi-basic014.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ Using the @PostConstruct and @PreDestroy Annotations with CDI Managed Bean Class

CDI managed bean classes and their superclasses support the annotations
for initializing and for preparing for the destruction of a bean. These
annotations are defined in JSR 250: Common Annotations for the Java
platform (`http://jcp.org/en/jsr/detail?id=250`).
annotations are defined in Jakarta Annotations (`https://jakarta.ee/specifications/annotations/1.3/`).

The following topics are addressed here:

Expand Down
11 changes: 5 additions & 6 deletions src/main/jbake/content/cdi-basic015.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ For more information about CDI, see

* Contexts and Dependency Injection for Jakarta EE specification:
+
`http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html`
`https://jakarta.ee/specifications/cdi/2.0/`
* An introduction to Contexts and Dependency Injection for Jakarta EE:
+
`http://docs.jboss.org/weld/reference/latest/en-US/html/`
* Dependency Injection for Java specification:
* Jakarta Dependency Injection specification:
+
`http://jcp.org/en/jsr/detail?id=330`
* Managed Beans specification, which is part of the Java Platform,
Enterprise Edition (Jakarta EE) Specification:
`https://jakarta.ee/specifications/dependency-injection/1.0/`
* Jakarta Managed beans specification, which is part of the Jakarta EE Platform Specification:
+
`http://jcp.org/en/jsr/detail?id=366`
`https://jakarta.ee/specifications/managedbeans/1.0/`
2 changes: 1 addition & 1 deletion src/main/jbake/content/cdi-basicexamples002.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The simplegreeting CDI Example

The `simplegreeting` example illustrates some of the most basic features
of CDI: scopes, qualifiers, bean injection, and accessing a managed bean
in a JavaServer Faces application. When you run the example, you click a
in a Jakarta Server Faces application. When you run the example, you click a
button that presents either a formal or an informal greeting, depending
on how you edited one of the classes. The example includes four source
files, a Facelets page and template, and configuration files.
Expand Down
2 changes: 1 addition & 1 deletion src/main/jbake/content/cdi-basicexamples003.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class Generator implements Serializable {
The UserNumberBean Managed Bean
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The `UserNumberBean` managed bean, the managed bean for the JavaServer
The `UserNumberBean` managed bean, the managed bean for the Jakarta Server
Faces application, provides the basic logic for the game. This bean does
the following:

Expand Down
2 changes: 1 addition & 1 deletion src/main/jbake/content/cdi-bootstrap-se8001.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ The API for bootstrapping a CDI container in Java SE consists of the following e

** `initialize()` bootstraps the container.

* `javax.enterprise.inject.se.SeContainer` interface – Provides access to the `BeanManager` instance for programmatic lookup, as defined in the `SeContainer` interface, which is described at `http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#se_container`.
* `javax.enterprise.inject.se.SeContainer` interface – Provides access to the `BeanManager` instance for programmatic lookup, as defined in the `SeContainer` interface, which is described at `https://jakarta.ee/specifications/cdi/2.0/cdi-spec-2.0.html#se_container`.
+

0 comments on commit 06ac437

Please sign in to comment.