KickJava   Java API By Example, From Geeks To Geeks.

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


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

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