exploring java ee 6 - oracle · exploring java ee 6 ... –eg. bean validation integrated into jsf,...
TRANSCRIPT
![Page 1: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/1.jpg)
<Insert Picture Here>
Exploring Java EE 6 The Programming Model Explained
Lee Chuk Munn
![Page 2: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/2.jpg)
The following is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into
any contract. It is not a commitment to deliver any
material, code, or functionality, and should not be
relied upon in making purchasing decisions. The
development, release, and timing of any features or
functionality described for Oracle’s products
remains at the sole discretion of Oracle.
![Page 3: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/3.jpg)
What comes to your
mind when you
think of JavaEE?
![Page 4: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/4.jpg)
What People Think...
![Page 5: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/5.jpg)
![Page 6: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/6.jpg)
What Developers Wanted...
![Page 7: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/7.jpg)
What They Got...
![Page 8: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/8.jpg)
Key Themes for JavaEE 6
Developer
Productivity
Flexible
and
Lightweight Extensible
Web Profile
Pruning
Embrace open source
frameworks
Enables Drag & Drop
framework installation
More annotations
POJO development
Less XML configuration
Java EE
![Page 9: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/9.jpg)
What's New in the Java EE 6 Platform?
• EJB 3.1 (+Lite)
• JPA 2.0
• Servlet 3.0
• JSF 2.0
• JAX-RS 1.1
• Bean Validation 1.0
• DI 1.0
• CDI 1.0
• Connectors 1.6
• Managed Beans 1.0
• Interceptors 1.1
• JSP 2.2
• EL 2.2
• JSR 250 1.1
• JASPIC 1.1
• JACC 1.5
• JAX-WS 2.2
• JSR 109 1.3
New and updated components
![Page 10: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/10.jpg)
Changes in Java EE 6
http://blog.eisele.net/2010/12/who-is-afraid-of-java-ee-6-get-rid-of.html
52%
11%
14%
23%
![Page 11: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/11.jpg)
Java EE 6 Web Profile
JPA 2.0 / JTA 1.1
Managed Beans 1.0 EJB 3.1
DI 1.0 / CDI 1.0 / Interceptors 1.1 / JSR 250 1.1
Servlet 3.0 / EL 2.2
JAX-RS 1.1 JSF 2.0 JSP 2.2 JSTL 1.2
Web Container
Extensions CDI
Extensions
Bean
Valid
atio
n 1
.0
![Page 12: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/12.jpg)
Simplfied Packaging
foo.ear
foo_web.war
WEB-INF/web.xml
WEB-INF/classes
com.sun.FooServlet
com.sun.TickTock
foo_ejb.jar
com.sun.FooBean
com.sun.FooHelper
foo.war
WEB-INF/classes
com.sun.FooServlet
com.sun.TickTock
com.sun.FooBean
com.sun.FooHelper
Java EE 5 Java EE 6
![Page 13: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/13.jpg)
Web Apps Simplified Packaging
WEB-INF/classes com/acme/MyServlet.class com/acme/MyFilter.class
WEB-INF/web.xml
index.html main.css jquery-1.4.2.js ui/jquery.ui.core.js ui/jquery.ui.widget.js
Web Application
WEB-INF/lib someframework.jar
![Page 14: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/14.jpg)
Web Apps Simplified Packaging Web Application
@WebServlet(urlPatterns=”/foo”) public class MyServlet { … } @WebFilter(urlPatterns=”/foo”) public class MyFilter { … }
WEB-INF/classes com/acme/MyServlet.class com/acme/MyFilter.class
WEB-INF/web.xml
index.html main.css jquery-1.4.2.js ui/jquery.ui.core.js ui/jquery.ui.widget.js
WEB-INF/lib someframework.jar
![Page 15: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/15.jpg)
Web Apps Simplified Packaging
WEB-INF/classes com/acme/MyServlet.class com/acme/MyFilter.class
index.html main.css jquery-1.4.2.js ui/jquery.ui.core.js ui/jquery.ui.widget.js
Web Application
WEB-INF/lib someframework.jar
META-INF/web-fragment.xml com/fw/FwServlet.class com/fw/FwFilter.class
Framework Jar
![Page 16: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/16.jpg)
Web Apps Simplified Packaging
WEB-INF/classes com/acme/MyServlet.class com/acme/MyFilter.class
index.html main.css
Web Application
WEB-INF/lib someframework.jar jquery-ui-1.8.4.jar META-INF/resources/jquery-1.4.2.js
META-INF/resources/ui/jquery.ui.core.js META-INF/resources/ui/jquery.ui.widget.js
jQuery Resource Jar
![Page 17: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/17.jpg)
Web Apps Simplified Packaging
WEB-INF/classes com/acme/MyServlet.class com/acme/MyFilter.class
index.html main.css
Web Application
WEB-INF/lib someframework.jar jquery-ui-1.8.4.jar
• Simpler packaging
• Drag and drop self
configuring frameworks
• Resource JARs
![Page 18: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/18.jpg)
Managed Bean as the Foundation • Plain Java objects (POJOs)
– Lifecycle managed by container
• Foundation for other component types
– Not something that developers would use directly
• Supports injections
– @Resource, @Inject
• Lifecycle callbacks
– @PostConstruct, @PreDestroy
• Optional name
• Interceptors
![Page 19: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/19.jpg)
Managed Bean Example
@ManagedBean(“MyCustomer”)
public class Customer {
@Resource DataSource db;
//Inject another managed bean
@Resource Address address;
@PostConsturct
private void init() {
//
}
}
![Page 20: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/20.jpg)
EJB Components as Managed Beans
• All managed beans core services are available in EJB
• EJB component model extends managed beans by
providing
– State – @Stateful, @Stateless, @Singleton
– Transaction – @TransactionAttribute
– Security – @RolesAllowed, @DenyAll, @PermitAll
– Access semantics – @Remote, @WebService
• EJBs can now be view as features on managed beans
– Just as other types of components
![Page 21: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/21.jpg)
Incremental Programming Model • Application changes over time
– Requirement change, functions of classes/objects changes
• Allows you to evolve your application gracefully
– Start with POJOs @ManagedBean
– Use all the basic services – lifecycle, resource injection, etc
– Turn them in to EJBs, Enitites, etc to take advantage of new
capabilities
– No change to (local) client
![Page 22: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/22.jpg)
EJB 2.1 – Step 1
public interface Converter extends EJBObject {
public BigDecimal dollarToYen(BigDecimal dollars)
throws RemoteException;
public BigDecimal yenToEuro(BigDecimal yen)
throws RemoteException;
}
public interface ConverterHome extends EJBHome {
Converter create()
throws RemoteException, CreateException;
}
![Page 23: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/23.jpg)
EJB 2.1 – Step 2 public class ConverterBean implements SessionBean {
...
public BigDecimal dollarToYen(BigDecimal dollars) {
...
}
public BigDecimal yenToEuro(BigDecimal yen) {
...
}
public ConverterBean() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}
![Page 24: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/24.jpg)
EJB 2.1 – Step 3
...
<session >
<display-name>Converter Session Bean</display-name>
<ejb-name>SimpleConverter</ejb-name>
<home>examples.ConverterHome</home>
<remote>examples.Converter</remote>
<ejb-class>examples.ConverterBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
...
![Page 25: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/25.jpg)
Consuming EJB 2.1
Context initial = new InitialContext();
Context myEnv = (Context)initial.lookup("java:comp/env");
Object objref = myEnv.lookup("ejb/SimpleConverter");
ConverterHome home =(ConverterHome)PortableRemoteObject
.narrow(objref, ConverterHome.class);
Converter currencyConverter = home.create();
![Page 26: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/26.jpg)
EJB as POJO
@Stateless
public class ConverterBean {
...
public BigDecimal dollarToYen(BigDecimal dollars) {
...
}
public BigDecimal yenToEuro(BigDecimal yen) {
...
}
}
@EJB ConverterBean converterBean;
![Page 27: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/27.jpg)
Common Injection Service Framework
• Injection services available to all objects
– Not restricted to specific components eg. EJB
• Context and Dependency Injection
– Managed beans on steroids
• Opt-in technology on per-module basis
– WEB-INF/beans.xml, META-INF/beans.xml
• Key CDI concepts
– Strongly typed for typesafety
– Loose coupling – events, interceptors, decorators
– Context and scope management
– Integration with EL
• Bridge EJB (business) to JSF (presentation)
![Page 28: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/28.jpg)
CDI Example
@Inject User user;
![Page 29: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/29.jpg)
CDI Example
@Inject User user;
Type describes the capability of the user
![Page 30: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/30.jpg)
CDI Example
@Inject User user;
What type of User?
![Page 31: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/31.jpg)
CDI Example
@Inject @LoggedIn User user;
Qualifier describes the characteristic of the user
![Page 32: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/32.jpg)
Uniformity • Annotations are additive
• New behaviour refine pre-existing ones
– Unless annotation conflicts with the semantics of component
– Eg. session scoped for JAX-RS components
• Eg. JAX-RS resource classes are POJOs
– Use JAX-RS specific injection capabilities
– Additional annotations to turn resource classes into CDI
managed beans or EJBs
– Use the new services with REST
![Page 33: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/33.jpg)
JAX-RS Example
@Path(“root”)
public class RootResource {
@Context UriInfo info;
@Path(“{id}”)
public SubResource find(
@PathParam(“id”) String id) {
return (new SubResource(id));
}
}
![Page 34: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/34.jpg)
JAX-RS Example
@RequestScoped
@Path(“root”)
public class RootResource {
@Context UriInfo info;
@Inject @CustomerDB DataSource myDB;
@Path(“{id}”)
public SubResource find(
@PathParam(“id”) String id) {
return (new SubResource(id));
}
}
As a CDI bean, using @Inject and scoped annotations
![Page 35: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/35.jpg)
APIs That Work Better Together • Previous versions have a bunch of APIs that are quite
independent of each other
• Java EE 5/6 introduces lots of 'services' API
– Managed bean, CDI, validation, interceptors, etc
• Aiming to get API to work better together
– Eg. Bean Validation integrated into JSF, JPA
– But not so well with CDI – working on it
– Use of SPI to provide integration to other frameworks
![Page 36: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/36.jpg)
Java EE 6
![Page 37: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/37.jpg)
After Frameworks
![Page 38: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/38.jpg)
Java EE 6 Platform Extensions
![Page 39: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/39.jpg)
Extensibility • Integrating 3rd party frameworks
• Pluggability contracts make extension look like build-
in technologies
• Two main extension points in Java EE 6
– Servlet 3.0 pluggability
– CDI extensions
![Page 40: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/40.jpg)
Servlet 3.0 Pluggability • Primary to address 3rd party web frames
– Drag and drop model
– Dynamic or static registration for frameworks
– Configuration, initialization, code generation, etc
• Results in ready to use framework JARs
• Modular web.xml and web-fragment.xml
– Framework contains a fragment of web.xml
– META-INF/web-fragment.xml
• Extension can discover and process annotated
classes
![Page 41: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/41.jpg)
Pluggability Example
@MyWebFramework
public class DoSomething {
Register with service loader framework
myframework.jar
META-INF/services/
javax.servlet.ServletContainerInitializer
myframework.FrameworkLoader
![Page 42: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/42.jpg)
Pluggability Example @HandlesTypes(MyWebFramework.class)
public class FrameworkLoader
implements ServletContainerInitializer {
public void onStartup(Set<Class<?>> c
, ServletContext ctx) {
//Load framework controller
ServletRegistration.Dynamic reg = ctx.addServlet(
“MyFrameworkController”
, “myframework.controller.FrameworkController”);
reg.setInitParameter(“config”
, “/WEB-INF/config.properties”);
//Other processing – eg. Code generation
...
}
}
![Page 43: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/43.jpg)
Extending CDI • Portable extension framework provides standard way
of extending CDI
• Drag and drop
• Extensions can process any annotated types
• What can you do with portable extensions
– Introduce new bean types
– Satisfy injection points
– Introduce custom scopes
– Augment or substitute bean's annotations and/or metadata
– Limited by your imagination
![Page 44: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/44.jpg)
Portable Extension Example
@RequestScope
@Message
public class HandleMessage {
@Inject @From JID from;
@PersistenceContext EntityManager em;
@Body(“{body}”)
public Object handle(@Named(“body”) int custId) {
return (em.find(Customer.class, custId));
}
}
New component type
New bean type
Integrates well
Export a named bean to handle method only
![Page 45: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/45.jpg)
Conclusion – A Better Platform • Less boilerplate code
• Simpler packaging
• Uniform use of annotations
• Consistent programming model
• Extensible
Simple things should be simple
complex things should be possible
Alan Kay
![Page 46: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/46.jpg)
![Page 47: Exploring Java EE 6 - Oracle · Exploring Java EE 6 ... –Eg. Bean Validation integrated into JSF, JPA –But not so well with CDI – working on it ... Integrates well](https://reader035.vdocuments.site/reader035/viewer/2022081517/5af7ea567f8b9ad2208bd6cb/html5/thumbnails/47.jpg)
For More Information
search.oracle.com
or
oracle.com