KickJava   Java API By Example, From Geeks To Geeks.

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


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.naming.InitialContext JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29
30 /**
31  *
32  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
33  * @version $Revision: 44679 $
34  */

35 public class XMLClassInterceptor extends XMLClassInterceptor2
36 {
37    @Resource
38    EJBContext JavaDoc ejbCtx;
39
40    private StatusRemote findStatusRemote()
41    {
42       try
43       {
44          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
45          StatusRemote status = findStatusRemote();
46          return status;
47       }
48       catch (NamingException JavaDoc e)
49       {
50          throw new RuntimeException JavaDoc(e);
51       }
52    }
53
54
55
56    public Object JavaDoc intercept(InvocationContext ctx) throws Exception JavaDoc
57    {
58       System.out.println("XMLClassInterceptor intercepting!");
59   // StatusRemote status = (StatusRemote)ejbCtx.lookup("StatusBean/remote");
60
StatusRemote status = (StatusRemote)new InitialContext JavaDoc().lookup("StatusBean/remote");
61       status.addInterception(new Interception(this, "intercept"));
62       return ctx.proceed();
63    }
64
65    public void postConstruct(InvocationContext ctx)
66    {
67       System.out.println("XMLClassInterceptor pc!");
68       StatusBean.addPostConstruct(new Interception(this, "postConstruct", instance));
69       try
70       {
71          ctx.proceed();
72       }
73       catch (Exception JavaDoc e)
74       {
75          throw new RuntimeException JavaDoc(e);
76       }
77    }
78
79    public void postActivate(InvocationContext ctx)
80    {
81       System.out.println("XMLClassInterceptor pa!");
82       StatusBean.addPostActivate(new Interception(this, "postActivate", instance));
83       try
84       {
85          ctx.proceed();
86       }
87       catch (Exception JavaDoc e)
88       {
89          throw new RuntimeException JavaDoc(e);
90       }
91    }
92
93    public void prePassivate(InvocationContext ctx)
94    {
95       System.out.println("XMLClassInterceptor pp!");
96       StatusBean.addPrePassivate(new Interception(this, "prePassivate", instance));
97       try
98       {
99          ctx.proceed();
100       }
101       catch (Exception JavaDoc e)
102       {
103          throw new RuntimeException JavaDoc(e);
104       }
105    }
106
107    public void preDestroy(InvocationContext ctx)
108    {
109       System.out.println("XMLClassInterceptor pd!");
110       StatusBean.addPreDestroy(new Interception(this, "preDestroy", instance));
111       try
112       {
113          ctx.proceed();
114       }
115       catch (Exception JavaDoc e)
116       {
117          throw new RuntimeException JavaDoc(e);
118       }
119    }
120
121    public Object JavaDoc intercept2(InvocationContext ctx) throws Exception JavaDoc
122    {
123       throw new RuntimeException JavaDoc("Should not be called");
124    }
125
126    public void postConstruct2(InvocationContext ctx)
127    {
128       throw new RuntimeException JavaDoc("Should not be called");
129    }
130
131    public void postActivate2(InvocationContext ctx)
132    {
133       throw new RuntimeException JavaDoc("Should not be called");
134    }
135
136    public void prePassivate2(InvocationContext ctx)
137    {
138       throw new RuntimeException JavaDoc("Should not be called");
139    }
140
141    public void preDestroy2(InvocationContext ctx)
142    {
143       throw new RuntimeException JavaDoc("Should not be called");
144    }
145
146 }
147
Popular Tags