KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > interceptors > business > base > PrintOrderWithAllCallbackMethods


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: PrintOrderWithAllCallbackMethods.java 772 2006-06-26 09:24:37Z pinheirg $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.interceptors.business.base;
26
27 import static org.objectweb.easybeans.tests.common.helper.InterceptorHelper.addValue;
28
29 import javax.ejb.EJB JavaDoc;
30 import javax.interceptor.InvocationContext;
31
32 import org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType;
33 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess;
34
35 /**
36  * Has the definition for all lifecycle callback methods, but is has not
37  * annotations. The methods are defined as callback methods by deployment
38  * descriptor.
39  * @author Gisele Pinheiro Souza
40  * @author Eduardo Studzinski Estima de Castro
41  */

42 public class PrintOrderWithAllCallbackMethods {
43
44     /**
45      * Bean used to log the callback loger.
46      */

47     @EJB JavaDoc(beanName = "SLSBCallbackLoggerAccess")
48     private ItfCallbackLoggerAccess clBean;
49
50     /**
51      * Constant to add into list.
52      */

53     public static final Integer JavaDoc ORDER = new Integer JavaDoc(5);
54
55     /**
56      * Intercepts the method and adds the ORDER value in the list that was get
57      * from InvocationContext.
58      * @param invocationContext contains attributes of invocation, the first
59      * parameter of the intercepted method must be a list.
60      * @return method's invocation result
61      * @throws Exception if invocation fails
62      */

63     public Object JavaDoc addOrder(final InvocationContext invocationContext) throws Exception JavaDoc {
64         return addValue(invocationContext, ORDER, this.getClass().toString());
65     }
66
67     /**
68      * Sets a variable as true.
69      * @param invocationContext contains attributes of invocation.
70      * @throws Exception if an error in the interceptor chain occurs.
71      */

72     public void postConstruct(final InvocationContext invocationContext) throws Exception JavaDoc {
73         clBean.insertCallbackLogger(invocationContext.getTarget().getClass().getName(), CallbackType.POST_CONSTRUCT,
74                 this.getClass().getName());
75         invocationContext.proceed();
76     }
77
78     /**
79      * Registers in the database that the method was called.
80      * @param invocationContext contains attributes of invocation.
81      * @throws Exception if an error in the interceptor chain occurs.
82      */

83     public void preDestroy(final InvocationContext invocationContext) throws Exception JavaDoc {
84         clBean.insertCallbackLogger(invocationContext.getTarget().getClass().getName(), CallbackType.PRE_DESTROY, this
85                 .getClass().getName());
86         invocationContext.proceed();
87     }
88
89     /**
90      * Used to verify if a prePassivate callback method can be defined by the
91      * deployment descriptor.
92      * * @param invocationContext contains attributes of invocation.
93      * @throws Exception if an error in the interceptor chain occurs.
94      */

95     public void prePassivate(final InvocationContext invocationContext) throws Exception JavaDoc {
96         // TODO - how to test the pre-passivate?
97
invocationContext.proceed();
98     }
99
100     /**
101      * Used to verify if a postActivate callback method can be defined by the
102      * deployment descriptor.
103      * * @param invocationContext contains attributes of invocation.
104      * @throws Exception if an error in the interceptor chain occurs.
105      */

106     public void postActivate(final InvocationContext invocationContext) throws Exception JavaDoc {
107         // TODO - how to test the post-activate?
108
invocationContext.proceed();
109     }
110
111 }
112
Popular Tags