Best viewed in 1024 X 800 resolution... Leave a comment if u like an article...
Google
 
Web tezcols.blogspot.com

Wednesday, December 16, 2009

Some Java EE6 Updates

Contexts and Dependency Injection for the Java EE Platform

CDI unifies and simplifies the EJB and JSF programming models. It allows enterprise beans to replace JSF managed beans in a JSF application.

Bean Validation

To meet the objective of sharing the same set of validations across all the layers of an application, Bean Validation is integrated across the Java EE 6 platform.

public class Address {

@NotNull @Size(max=30)

private String addressline1;

@Size(max=30)

private String addressline2;

...

public String getAddressline1() {

return addressline1;

}

public void setAddressline1(String addressline1) {

this.addressline1 = addressline1;

}

...

}

==========è Customized Validation

   @Size(min=5, max=5)
   @ConstraintValidator(ZipcodeValidator.class)
   @Documented
   @Target({ANNOTATION_TYPE, METHOD, FIELD})
   @Retention(RUNTIME)
   public @interface ZipCode {
       String message() default "Wrong zipcode";
       String[] groups() default {};
   }

An object graph is an object composed of other objects. If you specify the @Valid annotation on the root object of an object graph, it directs the pertinent validator to recursively validate the associated objects in the object graph. Consider the following example:

public class Order {

@OrderNumber private String orderNumber;

@Valid @NotNull private Address delivery;

}

When an Order object is validated, the Address object and the associated objects in its object graph are validated too.

Support for Web Fragments in Servlet 3.0

Now we can have logical divisions of web.xml configurations. Not just in web.xml that way we can maintain a web-fragment file for each framework (Configuring Listeners, Servlets).

web.xml

webfragment1

webfragment2

The following annotations are applicable starting from Servlet 3.0 specification,

· @WebServlet

· @WebServletContextListener

· @ServletFilter

· @InitParam

package net.javabeat.servlet30.newfeatures;

import javax.servlet.annotation.InitParam;

import javax.servlet.annotation.WebServlet;

@WebServlet(

name = "SimpleServlet",

urlPatterns = {"/simple"},

initParams = {

@InitParam(name = "param1", value = "value1"),

@InitParam(name = "param2", value = "value2")}

)

public class SimpleServlet {

}

Some improvements made in EJB 3.1 are as follows:

  • No-interface view. Allows you to specify an enterprise bean using only a bean class without having to write a separate business interface. (If using EJBs locally)
  • Singletons. Lets you easily share state between multiple instances of an enterprise bean component or between multiple enterprise bean components in an application.
  • Asynchronous session bean invocation. Enables you to invoke session bean methods asynchronously by specifying an annotation. (@Asynchronous, Future , javax.ejb.AsyncResult)
  • Simplified Packaging. Removes the restriction that enterprise bean classes must be packaged in an ejb-jar file. You can now place EJB classes directly in a WAR file. (Looks like Tomcat can also exec EJBs now... hehe)
  • EJB Lite. Is a subset of EJB 3.1 for inclusion in a variety of Java EE profiles.

Labels:

0 Comments:

Post a Comment

<< Home