KickJava   Java API By Example, From Geeks To Geeks.

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


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: AllLifeCallbackTimerServiceAccess00.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.ejb.EJB JavaDoc;
30 import javax.ejb.PostActivate JavaDoc;
31 import javax.ejb.PrePassivate JavaDoc;
32 import javax.interceptor.InvocationContext;
33
34 import org.objectweb.easybeans.log.JLog;
35 import org.objectweb.easybeans.log.JLogFactory;
36 import org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType;
37 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.ItfCallbackLoggerAccess;
38 import org.objectweb.easybeans.tests.common.resources.TimerServiceTester;
39
40 /**
41  * This interceptor contains methods to the four lifecycle callbacks. Every
42  * method tries to access the TimerService.
43  * @author Eduardo Studzinski Estima de Castro
44  * @author Gisele Pinheiro Souza
45  */

46 public class AllLifeCallbackTimerServiceAccess00 extends TimerServiceTester {
47
48     /**
49      * Logger.
50      */

51     private JLog logger = JLogFactory.getLog(AllLifeCallbackTimerServiceAccess00.class);
52
53     /**
54      * SessionFacade Callback Logger.
55      */

56     @EJB JavaDoc(beanName = "SLSBCallbackLoggerAccess")
57     private ItfCallbackLoggerAccess beanLogger;
58
59     /**
60      * PostActivate that accesses the TimerService.
61      * @param ic contains attributes of invocation
62      */

63     @PostActivate JavaDoc
64     public void postActivate(final InvocationContext ic) {
65         this.intercept(ic, CallbackType.POST_ACTIVATE);
66     }
67
68     /**
69      * PostConstruct that accesses the TimerService.
70      * @param ic contains attributes of invocation
71      */

72     @PostConstruct
73     public void postConstruct(final InvocationContext ic) {
74         this.intercept(ic, CallbackType.POST_CONSTRUCT);
75     }
76
77     /**
78      * PreDestroy that accesses the TimerService.
79      * @param ic contains attributes of invocation
80      */

81     @PreDestroy
82     public void preDestroy(final InvocationContext ic) {
83         this.intercept(ic, CallbackType.PRE_DESTROY);
84     }
85
86     /**
87      * PrePassivate that accesses the TimerService.
88      * @param ic contains attributes of invocation
89      */

90     @PrePassivate JavaDoc
91     public void prePassivate(final InvocationContext ic) {
92         this.intercept(ic, CallbackType.PRE_PASSIVATE);
93     }
94
95     /**
96      * Does the access.
97      * @param ic context
98      * @param type lifecycle interceptor type
99      */

100     protected void intercept(final InvocationContext ic, final CallbackType type) {
101         try {
102             String JavaDoc beanClassName = ic.getTarget().getClass().getName();
103
104             logger.debug("{0} - Testing access - Instance: {1}.", type.name(), beanClassName);
105             super.checkJNDI();
106             beanLogger.insertCallbackLogger(beanClassName, type,
107                     AllLifeCallbackTimerServiceAccess00.class.getName());
108             logger.debug("{0} - Access is ok - Instance: {1}.", type.name(), beanClassName);
109
110             ic.proceed();
111         } catch (Exception JavaDoc e) {
112             throw new IllegalStateException JavaDoc(type.name() + " Exception. ", e);
113         }
114     }
115 }
116
Popular Tags