KickJava   Java API By Example, From Geeks To Geeks.

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


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: AllLifeCallbackEJBAccess00.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
39 /**
40  * This interceptor contains methods to the four lifecycle callbacks.
41  * Every method try to access an EJB.
42  * @author Eduardo Studzinski Estima de Castro
43  * @author Gisele Pinheiro Souza
44  */

45 public class AllLifeCallbackEJBAccess00 {
46
47     /**
48      * Logger.
49      */

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

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

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

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

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

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

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