KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > stateless > containermanaged > invocationcontext > SLSBInvocationContext01


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SLSBInvocationContext01.java 880 2006-07-17 11:51:17Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.invocationcontext;
26
27 import javax.ejb.Remote JavaDoc;
28 import javax.ejb.Stateless JavaDoc;
29 import javax.interceptor.AroundInvoke;
30 import javax.interceptor.ExcludeClassInterceptors;
31 import javax.interceptor.InvocationContext;
32
33 import org.objectweb.easybeans.tests.common.ejbs.base.invocationcontext.ItfInvocation00;
34
35 /**
36  * This bean is used to manipulate the invocation context object.
37  * @author Eduardo Studzinski E. de Castro
38  * @author Gisele Pinheiro Souza
39  */

40 @Stateless JavaDoc
41 @Remote JavaDoc
42 public class SLSBInvocationContext01 implements ItfInvocation00 {
43
44     /**
45      * Information from interceptor.
46      */

47     private Integer JavaDoc interceptorInfo = null;
48
49     /**
50      * Verifies if the Interceptor.getTarget() returns an object with the same
51      * hashcode of the bean instance.
52      */

53     public void check() {
54         if (interceptorInfo.intValue() != this.hashCode()) {
55             throw new IllegalStateException JavaDoc("The referenced bean is not equal as the invocation context reference.");
56         }
57     }
58
59     /**
60      * Allows the interceptor to store an information in the bean.
61      * @param o information
62      */

63     @ExcludeClassInterceptors
64     public void setInterceptorInfo(final Object JavaDoc o) {
65         interceptorInfo = (Integer JavaDoc) o;
66     }
67
68     /**
69      * Interceptor that checks the invocation context object, it's compares the
70      * bean descriptor. <li>The first parameter of the intercepted method must
71      * be a BeanDescriptor.</li>
72      * @param ic contains attributes of invocation
73      * @return method's invocation result
74      * @throws Exception if invocation fails
75      */

76     @SuppressWarnings JavaDoc("unused")
77     @AroundInvoke
78     private Object JavaDoc checkDescriptor(final InvocationContext ic) throws Exception JavaDoc {
79         interceptorInfo = new Integer JavaDoc(ic.getTarget().hashCode());
80         return ic.proceed();
81     }
82
83 }
84
Popular Tags