KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > initial > FirstInterceptor


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

37 public class FirstInterceptor implements Serializable JavaDoc{
38
39    @AroundInvoke
40    public Object JavaDoc oneMethod(InvocationContext ctx) throws Exception JavaDoc
41    {
42       if (ctx.getMethod().getName().equals("testMethod"))
43       {
44          System.out.println("Intercepting in FirstInterceptor.oneMethod()");
45          int i = (Integer JavaDoc)ctx.getParameters()[0];
46          ctx.getContextData().put("DATA", new Integer JavaDoc(i + 1000));
47       }
48       return ctx.proceed();
49    }
50
51    @PostConstruct
52    public void postConstruct(InvocationContext ctx)
53    {
54       TestStatusBean.postConstruct = true;
55       try
56       {
57          ctx.proceed();
58       }
59       catch (Exception JavaDoc e)
60       {
61          throw new RuntimeException JavaDoc(e);
62       }
63    }
64
65    @PreDestroy
66    public void preDestroy(InvocationContext ctx)
67    {
68       TestStatusBean.preDestroy = true;
69       try
70       {
71          ctx.proceed();
72       }
73       catch (Exception JavaDoc e)
74       {
75          throw new RuntimeException JavaDoc(e);
76       }
77    }
78
79    @PostActivate JavaDoc
80    public void postActivate(InvocationContext ctx)
81    {
82       TestStatusBean.postActivate = true;
83       try
84       {
85          ctx.proceed();
86       }
87       catch (Exception JavaDoc e)
88       {
89          throw new RuntimeException JavaDoc(e);
90       }
91    }
92
93    @PrePassivate JavaDoc
94    public void prePassivate(InvocationContext ctx)
95    {
96       TestStatusBean.prePassivate = true;
97       try
98       {
99          ctx.proceed();
100       }
101       catch (Exception JavaDoc e)
102       {
103          throw new RuntimeException JavaDoc(e);
104       }
105    }
106 }
107
Popular Tags