KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > interceptors > lifecycle > misc > AllLifeCallbackJEnvCompAccess00


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: AllLifeCallbackJEnvCompAccess00.java 602 2006-06-08 08:40:57Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.interceptors.lifecycle.misc;
26
27 import javax.annotation.PostConstruct;
28 import javax.annotation.PreDestroy;
29 import javax.annotation.Resource;
30 import javax.ejb.EJB JavaDoc;
31 import javax.ejb.PostActivate JavaDoc;
32 import javax.ejb.PrePassivate JavaDoc;
33 import javax.interceptor.InvocationContext;
34 import javax.sql.DataSource JavaDoc;
35
36 import org.objectweb.easybeans.log.JLog;
37 import org.objectweb.easybeans.log.JLogFactory;
38 import org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType;
39 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess;
40 import org.objectweb.easybeans.tests.common.resources.JEnvCompTester;
41
42 /**
43  * This interceptor contains methods to the four lifecycle callbacks.
44  * Every method try to access the java:comp/env.
45  * @author Eduardo Studzinski Estima de Castro
46  * @author Gisele Pinheiro Souza
47  *
48  */

49 public class AllLifeCallbackJEnvCompAccess00 extends JEnvCompTester{
50
51     /**
52      * Logger.
53      */

54     private JLog logger = JLogFactory.getLog(AllLifeCallbackJEnvCompAccess00.class);
55
56     /**
57      * Resource injection.
58      */

59     @SuppressWarnings JavaDoc("unused")
60     @Resource(name="jdbc/jdbc_1", mappedName="jdbc_1")
61     private DataSource JavaDoc ds;
62
63     /**
64      * SessionFacade Callback Logger.
65      */

66     @EJB JavaDoc(beanName="SLSBCallbackLoggerAccess")
67     private ItfCallbackLoggerAccess beanLogger;
68
69     /**
70      * PostActivate that accesses the java:comp/env.
71      * @param ic contains attributes of invocation
72      */

73     @PostActivate JavaDoc
74     public void postActivate(final InvocationContext ic){
75         this.intercept(ic, CallbackType.POST_ACTIVATE);
76     }
77
78     /**
79      * PostConstruct that accesses the java:comp/env.
80      * @param ic contains attributes of invocation
81      */

82     @PostConstruct
83     public void postConstruct(final InvocationContext ic){
84         this.intercept(ic, CallbackType.POST_CONSTRUCT);
85     }
86
87     /**
88      * PreDestroy that accesses the java:comp/env.
89      * @param ic contains attributes of invocation
90      */

91     @PreDestroy
92     public void preDestroy(final InvocationContext ic){
93         this.intercept(ic, CallbackType.PRE_DESTROY);
94     }
95
96     /**
97      * PrePassivate that accesses the java:comp/env.
98      * @param ic contains attributes of invocation
99      */

100     @PrePassivate JavaDoc
101     public void prePassivate(final InvocationContext ic){
102         this.intercept(ic, CallbackType.PRE_PASSIVATE);
103     }
104
105     /**
106      * Does the access.
107      * @param ic context
108      * @param type lifecycle interceptor type
109      */

110     protected void intercept(final InvocationContext ic, final CallbackType type){
111         try {
112             String JavaDoc beanClassName = ic.getTarget().getClass().getName();
113
114             logger.debug("{0} - Testing access - Instance: {1}.", type.name(), beanClassName);
115             super.access00();
116             beanLogger.insertCallbackLogger(beanClassName, type, AllLifeCallbackJEnvCompAccess00.class.getName());
117             logger.debug("{0} - Access is ok - Instance: {1}.", type.name(), beanClassName);
118
119             ic.proceed();
120         } catch (Exception JavaDoc e) {
121             throw new IllegalStateException JavaDoc(type.name() + " Exception. ", e);
122         }
123     }
124 }
125
Popular Tags