KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > enhancer > interceptors > lifecycle > bean > MyLifeCycleInterceptorStateful


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: MyLifeCycleInterceptorStateful.java 450 2006-05-12 15:30:25Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.tests.enhancer.interceptors.lifecycle.bean;
27
28 import javax.annotation.PostConstruct;
29 import javax.annotation.PreDestroy;
30 import javax.ejb.PostActivate JavaDoc;
31 import javax.ejb.PrePassivate JavaDoc;
32 import javax.interceptor.InvocationContext;
33
34 /**
35  * Defines some callback methods for a stateful bean.
36  * @author Florent Benoit
37  */

38 public class MyLifeCycleInterceptorStateful {
39
40     /**
41      * @{@link javax.ejb.PostConstruct} method.
42      * @param invocationContext the invocation context
43      */

44     @PostConstruct
45     public void xxPostxxxConstruct(final InvocationContext invocationContext) {
46         Object JavaDoc o = invocationContext.getTarget();
47         if (o instanceof StatefulBean) {
48             StatefulBean bean = (StatefulBean) o;
49             bean.calledPostConstruct();
50             try {
51                 invocationContext.proceed();
52             } catch (Exception JavaDoc e) {
53                 throw new RuntimeException JavaDoc("Cannot proceed invocationContext", e);
54             }
55
56         }
57     }
58
59     /**
60      * @{@link javax.ejb.PreDestroy} method.
61      * @param invocationContext the invocation context
62      */

63     @PreDestroy
64     public void theGreatDestroyMethod(final InvocationContext invocationContext) {
65         Object JavaDoc o = invocationContext.getTarget();
66         if (o instanceof StatefulBean) {
67             StatefulBean bean = (StatefulBean) o;
68             bean.calledPreDestroy();
69             try {
70                 invocationContext.proceed();
71             } catch (Exception JavaDoc e) {
72                 throw new RuntimeException JavaDoc("Cannot proceed invocationContext", e);
73             }
74         }
75     }
76
77     /**
78      * @{@link javax.ejb.PrePassivate} method.
79      * @param invocationContext the invocation context
80      */

81     @PrePassivate JavaDoc
82     public void testingPrePassivate(final InvocationContext invocationContext) {
83         Object JavaDoc o = invocationContext.getTarget();
84         if (o instanceof StatefulBean) {
85             StatefulBean bean = (StatefulBean) o;
86             bean.calledPrePassivate();
87             try {
88                 invocationContext.proceed();
89             } catch (Exception JavaDoc e) {
90                 throw new RuntimeException JavaDoc("Cannot proceed invocationContext", e);
91             }
92         }
93     }
94
95     /**
96      * @{@link javax.ejb.PostActivate} method.
97      * @param invocationContext the invocation context
98      */

99     @PostActivate JavaDoc
100     public void activating(final InvocationContext invocationContext) {
101         Object JavaDoc o = invocationContext.getTarget();
102         if (o instanceof StatefulBean) {
103             StatefulBean bean = (StatefulBean) o;
104             bean.calledPostActivate();
105             try {
106                 invocationContext.proceed();
107             } catch (Exception JavaDoc e) {
108                 throw new RuntimeException JavaDoc("Cannot proceed invocationContext", e);
109             }
110
111         }
112     }
113
114 }
115
Popular Tags