KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.annotation.Resource;
25 import javax.ejb.EJBContext JavaDoc;
26 import javax.interceptor.InvocationContext;
27 import javax.ejb.PostActivate JavaDoc;
28 import javax.annotation.PostConstruct;
29 import javax.annotation.PreDestroy;
30 import javax.ejb.PrePassivate JavaDoc;
31 import javax.naming.InitialContext JavaDoc;
32 import javax.naming.NamingException JavaDoc;
33
34 /**
35  *
36  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
37  * @version $Revision: 44679 $
38  */

39 public class XMLMethodInterceptor
40 {
41    @Resource
42    EJBContext JavaDoc ejbCtx;
43
44    public Object JavaDoc intercept(InvocationContext ctx) throws Exception JavaDoc
45    {
46       System.out.println("XMLMethodInterceptor intercepting!");
47       StatusRemote status = findStatusRemote();
48       status.addInterception(new Interception(this, "intercept"));
49       return ctx.proceed();
50    }
51
52    private StatusRemote findStatusRemote()
53    {
54       try
55       {
56          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
57          StatusRemote status = (StatusRemote)ctx.lookup("StatusBean/remote");
58          return status;
59       }
60       catch (NamingException JavaDoc e)
61       {
62          throw new RuntimeException JavaDoc(e);
63       }
64    }
65
66    public void ignored(InvocationContext ctx)
67    {
68       throw new RuntimeException JavaDoc("Should be ignored!!!");
69    }
70
71    public void postConstruct(InvocationContext ctx)
72    {
73       StatusRemote status = findStatusRemote();
74       status.addLifecycle(PostConstruct.class, new Interception(this, "postConstruct"));
75       try
76       {
77          ctx.proceed();
78       }
79       catch (Exception JavaDoc e)
80       {
81          throw new RuntimeException JavaDoc(e);
82       }
83    }
84
85    public void postActivate(InvocationContext ctx)
86    {
87       StatusRemote status = findStatusRemote();
88       status.addLifecycle(PostActivate JavaDoc.class, new Interception(this, "postActivate"));
89       try
90       {
91          ctx.proceed();
92       }
93       catch (Exception JavaDoc e)
94       {
95          throw new RuntimeException JavaDoc(e);
96       }
97    }
98
99    public void prePassivate(InvocationContext ctx)
100    {
101       StatusRemote status = findStatusRemote();
102       status.addLifecycle(PrePassivate JavaDoc.class, new Interception(this, "prePassivate"));
103       try
104       {
105          ctx.proceed();
106       }
107       catch (Exception JavaDoc e)
108       {
109          throw new RuntimeException JavaDoc(e);
110       }
111    }
112
113    public void preDestroy(InvocationContext ctx)
114    {
115       StatusRemote status = findStatusRemote();
116       status.addLifecycle(PreDestroy.class, new Interception(this, "preDestroy"));
117       try
118       {
119          ctx.proceed();
120       }
121       catch (Exception JavaDoc e)
122       {
123          throw new RuntimeException JavaDoc(e);
124       }
125    }
126
127 }
128
Popular Tags