KickJava   Java API By Example, From Geeks To Geeks.

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


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

47 public class AllLifeCallbackEMFactoryAccess00 extends EMFactoryTester{
48
49     /**
50      * Logger.
51      */

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

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

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

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

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

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

101     protected void intercept(final InvocationContext ic, final CallbackType type){
102         try {
103             String JavaDoc beanClassName = ic.getTarget().getClass().getName();
104
105             logger.debug("{0} - Testing access - Instance: {1}.", type.name(), beanClassName);
106             super.access00();
107             beanLogger.insertCallbackLogger(beanClassName, type, AllLifeCallbackEMFactoryAccess00.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