Sunteți pe pagina 1din 5

JAVA EE 6 Platform.

JAVA EE 6 is a standard platform comprised of managed components and services.


Business Logic also considered as components with features like less code, higher
signal-to-noise ratio, powerful mechanism and portable.

Technology Terminology.
 CDI (JSR-299)
 Contexts & dependency injection for the Java EE platform
 Weld
 JSR-299 Reference Implementation
 CDI support outside Java EE (Servlet, Java SE)
 Seam 3
 Portable extensions for Java EE
 Integrations with non-Java EE technologies
 Akin to ecosystem of JSF components
CDI (JSR-299)

What CDI provides


 Services for Java EE components
 Lifecycle management of stateful beans bound to well-defined contexts
(including conversation context)
 A type-safe approach to dependency injection
 Interaction via an event notification facility
 Reduced coupling between interceptors and beans
 Decorators (intercept specific bean instances)
 Unified EL integration (bean names)
 SPI for developing extensions for the Java EE platform
 Extensions are portable and integration cleanly

The services defined by this specification allow Java EE components to be bound to


lifecycle contexts, to be injected, and to interact in a loosely coupled fashion by firing
and observing events. Various kinds of objects are injectable, including EJB 3 session
beans, JavaBeans and Java EE resources. These objects in general terms as beans
and to instances of beans that are bound to contexts as contextual instances.
Contextual instances may be injected into other objects by the dependency injection
service.

This specification defines the responsibilities of:


 The application developer who
uses these services, and
 The vendor who implements the functionality defined by this specification and
provides a runtime environment in which the application executes.

An application developer creates Java EE components such as EJBs, servlets and


JavaBeans and then provides additional metadata that declares additional behavior
defined by this specification.
Java EE 6 and embeddable EJB Lite containers must support all functionality defined
by this specification.

In addition, this specification defines an SPI that allows alternative, non-platform


technologies to integrate with the container, for example, alternative web
presentation technologies.

The relationship with the different Components is as follows.

EJB:
This specification enhances the EJB component model with contextual lifecycle
management and with extensibility, since lifecycle contexts are not limited to those
described and defined by this specification. Any session bean instance obtained via
the dependency injection service is a contextual instance. It is bound to a lifecycle
context and is available to other objects that execute in that context. The container
automatically creates the instance when it is needed by a client. When the context
ends, the container automatically destroys the instance.

The container performs dependency injection on all EJB instances, even those which
are not contextual instances.

Message-driven and entity beans are by nature non-contextual objects and may not
be injected into other objects.

JSF:
This specification allows any bean to fulfill the role of the managed bean in a JSF
application. Thus, a JSF application may take advantage of the more sophisticated
context and dependency injection model defined by this specification. JSF pages
directly access beans, including EJB session beans, using Unified EL.

Servlets/JSP:
Servlets may inject beans via the dependency injection service.
JSP pages directly access beans using Unified EL.

JSR-299 theme
 Loose coupling
 Strong typing
Loose coupling
 Decouple server and client
 Using well-defined types and “qualifiers”
 Allows server implementation to vary
 Decouple lifecycle of collaborating components
 Automatic contextual lifecycle management
 Stateful components interact like services
 Decouple orthogonal concerns (AOP)
 Interceptors & decorators
 Decouple message producer from consumer
 Events

Strong typing
 Type-based injection
 Eliminate reliance on string-based names
 Compiler can detect typing errors
 No special authoring tools required
 Casting mostly eliminated
 Semantic code errors detected at application startup
 Tooling can detect ambiguous dependencies

What can be injected?


 Almost any plain Java class (managed beans)
 Objects returned by producer methods or fields
 EJB session beans (local & remote)
 Java EE resources (DataSource, UserTransaction, ...)
 Persistence units and persistence contexts
 Security principal
 Bean Validation validator factory
 Web service references
 Additional resources introduced through SPI

Weld
Weld, the JSR-299 Reference Implementation (RI), is being developed as part of the
Seam project.

Weld provides complete SPI allowing Java EE containers such as JBoss AS 6 and
GlassFish V3 to use Weld as their built-in CDI implementation. Weld also runs in
servlet engines like Tomcat and Jetty, or even in a plain Java SE environment.

Seam 3.0
To provide a fully integrated development platform for building rich Internet
applications based upon the Java EE environment

Seam 3.0 Key themes


 Modularity
 Seam à la carte
 Portability
 Run on any CDI implementation
 Full stack
 Similar to Eclipse’s coordinated release

Producer methods
Producer methods let us overcome certain limitations that arise when a container,
instead of the application, is responsible for instantiating objects. They're also the
easiest way to integrate objects which are not beans into the CDI environment.
According to the spec:
A producer method acts as a source of objects to be injected, where:
 the objects to be injected are not required to be instances of beans,
 the concrete type of the objects to be injected may vary at runtime or
 the objects require some custom initialization that is not performed by the bean
constructor
 For example, producer methods let us:
 expose a JPA entity as a bean,
 expose any JDK class as a bean,
 define multiple beans, with different scopes or initialization, for the same
implementation class, or
 Vary the implementation of a bean type at runtime.

Interceptors
CDI enhances the interceptor functionality with a more sophisticated, semantic,
annotation-based approach to binding interceptors to beans
The Interceptors specification defines two kinds of interception points:
Business method interception: A business method interceptor
applies to invocations of methods of the bean by clients of the
bean
Lifecycle callback interception: A lifecycle callback interceptor
applies to invocations of lifecycle callbacks by the container
The EJB specification defines timeout method interception: A
timeout method interceptor applies to invocations of EJB
timeout methods by the container

Decorators
A decorator intercepts invocations only for a certain Java interface, and is therefore
aware of all the semantics attached to that interface. Since decorators directly
implement operations with business semantics, it makes them the perfect tool for
modeling some kinds of business concerns.

Events
Events allow beans to interact with no compile time dependency at all. Event
producers raise events that are delivered to event observers by the container.

This basic schema might sound like the familiar observer/observable pattern, but
there are a couple of twists:
Not only are event producers decoupled from observers;
observers are completely decoupled from producers,
Observers can specify a combination of "selectors" to narrow
the set of event notifications they will receive, and
Observers can be notified immediately, or can specify that
delivery of the event should be delayed until the end of the
current transaction.

The CDI event notification facility uses more or less the same type safe approach that
we've already seen with the dependency injection service.

Stereotypes
In many systems, use of architectural patterns produces a set of recurring bean roles.
A stereotype allows a framework developer to identify such a role and declare some
common metadata for beans with that role in a central place.

A stereotype encapsulates any combination of:


A default scope, and
A set of interceptor bindings.

A stereotype may also specify that:


All beans with the stereotype have defaulted bean EL names, or
that
All beans with the stereotype are alternatives.

A bean may declare zero, one or multiple stereotypes. Stereotype annotations may
be applied to a bean class or producer method or field.

References.
For more information, see:
• CDI (JSR-299) - http://www.jsfsummit.com/conference/orlando/2009/12/session?
id=16624
• Redhat News - http://press.redhat.com/2010/10/12/now-that-java-ee-6-is-here-do-i-
still-need-those-proprietary-frameworks/
• Portlet Specification - http://www.jcp.org/en/jsr/detail?id=168
• Redhat Conference - http://www-waa-akam.thomson-webcast.net/us/dispatching/?
event_id=1a0c6f59bf1e233f7a388ce7995c903c&portal_id=af9b227bf07c733390c27
38ee0330646

S-ar putea să vă placă și