dev@grizzly.java.net

Re: Discussion about Annotations support in GWSD

From: Hubert Iwaniuk <neotyk_at_kungfoo.pl>
Date: Mon, 21 Sep 2009 21:18:39 +0200

Hi Sebastien,

Please take a look at "SRV.14.5 Annotations and Resource Injection" from
Servlet 2.5 spec.
Classes that annotation can be applied to:

   - javax.servlet.Servlet
   - javax.servlet.Filter
   - javax.servlet.ServletContextListener
   - javax.servlet.ServletContextAttributeListener
   - javax.servlet.ServletRequestListener
   - javax.servlet.ServletRequestAttributeListener
   - javax.servlet.http.HttpSessionListener
   - javax.servlet.http.HttpSessionAttributeListener

Annotations to be processed:
SRV.14.5.1 @DeclaresRoles . . . . . . . . . . . . . . . . . . . . . . . .
156
SRV.14.5.2 @EJB Annotation . . . . . . . . . . . . . . . . . . . . . . . 157
SRV.14.5.3 @EJBs Annotation . . . . . . . . . . . . . . . . . . . . . . 157
SRV.14.5.4 @Resource Annotation . . . . . . . . . . . . . . . . . . . 158
SRV.14.5.5 @PersistenceContext Annotation . . . . . . . . . . . 158
SRV.14.5.6 @PersistenceContexts Annotation . . . . . . . . . . 159
SRV.14.5.7 @PersistenceUnit Annotation . . . . . . . . . . . . . . 159
SRV.14.5.8 @PersistenceUnits Annotation . . . . . . . . . . . . . 159
SRV.14.5.9 @PostConstruct Annotation . . . . . . . . . . . . . . . 160
SRV.14.5.10 @PreDestroy Annotation . . . . . . . . . . . . . . . . . 160
SRV.14.5.11 @Resources Annotation . . . . . . . . . . . . . . . . . . 161
SRV.14.5.12 @RunAs Annotation . . . . . . . . . . . . . . . . . . . . 161
SRV.14.5.13 @WebServiceRef Annotation . . . . . . . . . . . . . 162
SRV.14.5.14 @WebServiceRefs Annotation . . . . . . . . . . . . 162

I think that you could build WebApp out of annotations and merge it with one
from web.xml.
Same as we do now with webdefault WebApps.

Do we have a ticket for it?

HTH,
   Hubert.


On Sun, Sep 20, 2009 at 10:53 PM, Survivant 00 <survivant00_at_gmail.com>wrote:

> here a snippet of the Annotations for Servlet 2.5 and descriptions took
> from
>
> Java™ Servlet Specification Version 2.5 MR6
>
>
> Question. Do we parse classes for all theses annotations and populate the
> web.xml from it theses (only if the web.xml doesn't already ready define
> some segments) ?
>
>
>
>
> package grizzly;
>
> public class AnnotationParser {
>
> /*
> * This annotation is used to define the security roles that comprise
> the
> * security model of the application. This annotation is specified on a
> * class, and it typically would be used to define roles that could be
> * tested (i.e., by calling isUserInRole) from within the methods of
> the
> * annotated class. It could also be used to declare application roles
> that
> * are not implicitly declared as the result of their use in a
> *
> * @DeclaresRoles annotation on the class implementing the
> javax.servlet.
> * Servlet interface or a subclass thereof. Following is an example of
> how
> * this annotation would be used.
> *
> * @DeclaresRoles("BusinessAdmin") public class CalculatorServlet {
> //... }
> * Declaring @DeclaresRoles ("BusinessAdmin") is equivalent to defining
> the
> * following in the web.xml. <web-app> <security-role>
> * <role-name>BusinessAdmin</role-name> </security-role> </web-app>
> *
> * JSR-250
> */
> public void parseDeclaresRoles() throws Exception {
>
> }
>
> /*
> * The @EJBs annotation allows more than one @EJB annotations to be
> declared
> * on a single resource. An example:
> *
> * @EJBs({_at_EJB(Calculator), @EJB(ShoppingCart)}) public class
> * ShoppingCartServlet { //... } The example above the EJB components
> * ShoppingCart and Calculator are made available to
> ShoppingCartServlet.
> * The ShoppingCartServlet must still look up the references using JNDI
> but
> * the EJBs do not need to declared in the web.xml file.
> *
> * The @EJBs annotation is discussed in further detailed in section
> 15.5 of
> * the EJB 3.0 specification (JSR220).
> */
> public void parseEJB() throws Exception {
>
> }
>
> /*
> * The @Resource annotation is used to declare a reference to a
> resource
> * such as a data source, Java Messaging Service (JMS) destination, or
> * environment entry. This annotation is equivalent to declaring a
> * resource-ref, message-destinationref or env-ref, or resource-env-ref
> * element in the deployment descriptor. The @Resource annotation is
> * specified on a class, method or field. The container is responsible
> * injecting references to resources declared by the
> *
> * @Resource annotation and mapping it to the proper JNDI resources.
> See the
> * Java EE Specification Chapter 5 for further details. An example of a
> * @Resource annotation follows:
> *
> * @Resource private javax.sql.DataSource catalogDS; public
> * getProductsByCategory() { // get a connection and execute the query
> * Connection conn = catalogDS.getConnection(); .. }
> *
> * JSR-250
> */
> public void parseResource() throws Exception {
>
> }
>
> /*
> * The PersistenceContexts annotation allows more than one
> * @PersistenceContext to be declared on a resource. The behavior the
> * @PersistenceContext annotation is further detailed in section 8.4.1
> of
> * the Java Persistence document which is part of the EJB 3.0
> specification
> * (JSR220) and in section 15.11 of the EJB 3.0 specification
> *
> * @PersistenceContext (type=EXTENDED) EntityManager em;
> */
> public void parsePersistenceContext() throws Exception {
>
> }
>
> /*
> * The @PersistenceUnit annotation provides Enterprise Java Beans
> components
> * declared in a servlet a reference to a entity manager factory. The
> entity
> * manager factory is bound to a separate persistence.xml configuration
> file
> * as described in section 5.10 of the EJB 3.0 specification (JSR220).
> An
> * example:
> *
> * @PersistenceUnit EntityManagerFactory emf; The behavior the
> * @PersistenceUnit annotation is further detailed in section 8.4.2 of
> the
> * Java Persistence document which is part of the EJB 3.0 specification
> * (JSR220) and in section 15.10 of the EJB 3.0 specification.
> */
> public void parsePersistenceUnit() throws Exception {
>
> }
>
> /*
> * The @PostConstruct annotation is declared on a method that does not
> take
> * any arguments, and must not throw any checked expections. The return
> * value must be void. The method MUST be called after the resources
> * injections have been completed and before any lifecycle methods on
> the
> * component are called. An example:
> *
> * @PostConstruct public void postConstruct() { ... } The example above
> * shows a method using the @PostConstruct annotation.
> */
> public void parsePostConstruct() throws Exception {
>
> }
>
> /*
> * The @PreDestroy annotation is declared on a method of a container
> managed
> * component. The method is called prior to component being reomvoed by
> the
> * container. An example:
> *
> * @PreDestroy public void cleanup() { // clean up any open resources
> ... }
> * The method annotated with @PreDestroy must return void and must not
> throw
> * a checked exception. The method may be public, protected, package
> private
> * or private. The method must not be static however it may be final.
> *
> * JSR-250
> */
> public void parsePreDestroy() throws Exception {
>
> }
>
> /*
> * The @Resources annotation acts as a container for multiple @Resource
> * annotations because the Java MetaData specification does not allow
> for
> * multiple annotations with the same name on the same annotation
> target. An
> * example:
> *
> * @Resources ({
> *
> * @Resource(name=”myDB” type=javax.sql.DataSource),
> *
> * @Resource(name=”myMQ” type=javax.jms.ConnectionFactory) }) public
> class
> * CalculatorServlet { //... } In the example above a JMS connection
> factory
> * and a data source are made available to the CalculatorServlet by
> means of
> * an @Resources annotation. The semantics of the @Resources annotation
> are
> * further detailed in the Common Annotations for the JavaTM PlatformTM
> * specifcation (JSR 250) section 2.4.
> */
> public void parseResources() throws Exception {
>
> }
>
> /*
> * The @RunAs annotation is equivalent to the run-as element in the
> * deployment descriptor. The @RunAs annotation may only be defined in
> * classes implementing the javax.servlet.Servlet interface or a
> subclass
> * thereof. An example:
> *
> * @RunAs(“Admin”) public class CalculatorServlet {
> *
> * @EJB private ShoppingCart myCart; public void
> doGet(HttpServletRequest,
> * req, HttpServletResponse res) { //.... myCart.getTotal(); //.... } }
> * //.... } The @RunAs(“Admin”) statement would be equivalent to
> defining
> * the following in the web.xml. <servlet>
> * <servlet-name>CalculatorServlet</servlet-name>
> <run-as>Admin</run-as>
> * </servlet> The example above shows how a servlet uses the @RunAs
> * annotation to propagate the security identity “Admin” to an EJB
> component
> * when the myCart.getTotal() method is called. For further details on
> * propagating identities see SRV.14.3.1. For further details on the
> @RunAs
> * annotation refer to the Common Annotations for the JavaTM PlatformTM
> * specifcation (JSR 250) section 2.6
> */
> public void parseRunAs() throws Exception {
>
> }
>
> /*
> * The @WebServiceRef annotation provides a reference to a web service
> in a
> * web component in same way as a resource-ref element would in the
> * deployment descriptor. An example:
> *
> * @WebServiceRef private MyService service; In this example a
> reference to
> * the web service “MyService” will be injected to the class declaring
> the
> * annotation. This annotation and behavior are further detailed in the
> * JAX-WS Specification (JSR 224) section 7.
> */
> public void parseWebServiceRef() throws Exception {
>
> }
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> // TODO Auto-generated method stub
>
> }
>
> }
>
>