KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > interceptors2 > AnnotatedClassInterceptor3


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb3.test.interceptors2;
23
24 import java.io.Serializable JavaDoc;
25
26 import javax.annotation.Resource;
27 import javax.annotation.PostConstruct;
28 import javax.interceptor.AroundInvoke;
29 import javax.ejb.EJBContext JavaDoc;
30 import javax.interceptor.InvocationContext;
31 import javax.ejb.PostActivate JavaDoc;
32 import javax.annotation.PreDestroy;
33 import javax.ejb.PrePassivate JavaDoc;
34 import javax.naming.InitialContext JavaDoc;
35 import javax.naming.NamingException JavaDoc;
36
37 /**
38  *
39  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
40  * @version $Revision: 44679 $
41  */

42 public class AnnotatedClassInterceptor3 implements Serializable JavaDoc
43 {
44    @Resource
45    EJBContext JavaDoc ejbCtx;
46
47    static int currentInstance;
48    int instance = ++currentInstance;
49
50    @AroundInvoke
51    public Object JavaDoc intercept3(InvocationContext ctx) throws Exception JavaDoc
52    {
53       StatusRemote status = findStatusRemote();
54       status.addInterception(new Interception(this, "intercept3", instance));
55       return ctx.proceed();
56    }
57
58    private StatusRemote findStatusRemote()
59    {
60       try
61       {
62          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
63          StatusRemote status = (StatusRemote)ctx.lookup("StatusBean/remote");
64          return status;
65       }
66       catch (NamingException JavaDoc e)
67       {
68          throw new RuntimeException JavaDoc(e);
69       }
70    }
71
72    @PostConstruct
73    public void postConstruct3(InvocationContext ctx)
74    {
75       StatusRemote status = findStatusRemote();
76       status.addLifecycle(PostConstruct.class, new Interception(this, "postConstruct3", instance));
77       try
78       {
79          ctx.proceed();
80       }
81       catch (Exception JavaDoc e)
82       {
83          throw new RuntimeException JavaDoc(e);
84       }
85    }
86
87    @PostActivate JavaDoc
88    public void postActivate3(InvocationContext ctx)
89    {
90       StatusRemote status = findStatusRemote();
91       status.addLifecycle(PostActivate JavaDoc.class, new Interception(this, "postActivate3", instance));
92       try
93       {
94          ctx.proceed();
95       }
96       catch (Exception JavaDoc e)
97       {
98          throw new RuntimeException JavaDoc(e);
99       }
100    }
101
102    @PrePassivate JavaDoc
103    public void prePassivate3(InvocationContext ctx)
104    {
105       StatusRemote status = findStatusRemote();
106       status.addLifecycle(PrePassivate JavaDoc.class, new Interception(this, "prePassivate3", instance));
107       try
108       {
109          ctx.proceed();
110       }
111       catch (Exception JavaDoc e)
112       {
113          throw new RuntimeException JavaDoc(e);
114       }
115    }
116
117    @PreDestroy
118    public void preDestroy3(InvocationContext ctx)
119    {
120       StatusRemote status = findStatusRemote();
121       status.addLifecycle(PreDestroy.class, new Interception(this, "preDestroy3", instance));
122       try
123       {
124          ctx.proceed();
125       }
126       catch (Exception JavaDoc e)
127       {
128          throw new RuntimeException JavaDoc(e);
129       }
130    }
131 }
132
Popular Tags