KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > base > invocationcontext > BaseInvocationParameter01


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: BaseInvocationParameter01.java 880 2006-07-17 11:51:17Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.base.invocationcontext;
26
27 import java.lang.reflect.Method JavaDoc;
28
29 import javax.interceptor.AroundInvoke;
30 import javax.interceptor.InvocationContext;
31
32 import org.objectweb.easybeans.log.JLog;
33 import org.objectweb.easybeans.log.JLogFactory;
34 import org.objectweb.easybeans.tests.common.helper.InvocationContextHelper;
35 import org.objectweb.easybeans.tests.common.interceptors.invocationcontext.ComplexObject00;
36
37 /**
38  * Used to manipulate the invocation context object.
39  * @author Eduardo Studzinski Estima de Castro
40  * @author Gisele Pinheiro Souza
41  */

42 public class BaseInvocationParameter01 implements ItfInvocationParameter00{
43
44     /**
45      * Logger.
46      */

47     private JLog logger = JLogFactory.getLog(BaseInvocationParameter01.class);
48
49     /**
50      * Intercepts the method and modifies the method parameters.
51      * @param ic contains attributes of invocation, the first
52      * parameter of the intercepted method must be a list.
53      * @return method's invocation result
54      * @throws Exception if invocation fails
55      */

56     @SuppressWarnings JavaDoc("unused")
57     @AroundInvoke
58     private Object JavaDoc intercept(final InvocationContext ic) throws Exception JavaDoc{
59         Method JavaDoc mIC = ic.getMethod();
60
61         if (mIC.toString().contains("getObjects00")){
62             //Sets all parameters to null.
63
return InvocationContextHelper.setParametersNull(ic);
64         } else if (mIC.toString().contains("getObjects01")) {
65             //Do not modify the parameters.
66
return InvocationContextHelper.getParametersArray(ic);
67         } else if (mIC.toString().contains("getObjects02")) {
68             //Modify the parameters.
69
return InvocationContextHelper.modifyParameters(ic);
70         }else{
71             throw new Exception JavaDoc("Invalid method to intercept.");
72         }
73     }
74
75     /**
76      * Returns objects passed as parameters with null references. There is an interceptor
77      * that sets to null the parameters reference.
78      * @param objCP complex object
79      * @return array with the objects passed as parameters.
80      * @throws Exception if a problem occurs.
81      */

82     public Object JavaDoc[] getObjects00(ComplexObject00 objCP) throws Exception JavaDoc {
83         Object JavaDoc[] arObjs = {objCP};
84         logger.debug("after interceptors, parameters: {0}", objCP);
85         return arObjs;
86     }
87
88     /**
89      * Returns objects passed as parameters without modification. There is an interceptor
90      * that creates a new array to return, but it doesn't modify the objects passed as parameters.
91      * @param objCP complex object
92      * @return array with the objects passed as parameters.
93      * @throws Exception if a problem occurs.
94      */

95     public Object JavaDoc[] getObjects01(ComplexObject00 objCP) throws Exception JavaDoc {
96         Object JavaDoc[] arObjs = {objCP};
97         logger.debug("after interceptors, parameters: {0}, {1}", objCP);
98         return arObjs;
99     }
100
101     /**
102      * Returns objects passed as parameters with modifications.
103      * There is an interceptor that modifies the parameters.
104      * @param objCP complex object
105      * @return array with the objects passed as parameters.
106      * @throws Exception if a problem occurs.
107      */

108     public Object JavaDoc[] getObjects02(ComplexObject00 objCP) throws Exception JavaDoc {
109         Object JavaDoc[] arObjs = {objCP};
110         logger.debug("after interceptors, parameters: {0}", objCP);
111         return arObjs;
112     }
113
114 }
115
Popular Tags