KickJava   Java API By Example, From Geeks To Geeks.

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


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

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