KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > base > interceptororder > MethodInterceptorTest


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: MethodInterceptorTest.java 821 2006-07-04 13:28:52Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.base.interceptororder;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import javax.annotation.PostConstruct;
31 import javax.interceptor.Interceptors;
32
33 import org.objectweb.easybeans.tests.common.ejbs.base.ItfMethodInterceptor;
34 import org.objectweb.easybeans.tests.common.interceptors.business.basic.PackageInterceptor;
35 import org.objectweb.easybeans.tests.common.interceptors.business.basic.PrivateInterceptor;
36 import org.objectweb.easybeans.tests.common.interceptors.business.basic.ProtectedInterceptor;
37 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder01Interceptor;
38 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder02Interceptor;
39 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder03Interceptor;
40 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder04Interceptor;
41 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder05Interceptor;
42
43 /**
44  * Implements an interface that all methods append an Integer with value 0. The
45  * difference between each method is the number of method interceptors used in
46  * each one. There are not class interceptor and default interceptor specified.
47  * @author Gisele Pinheiro Souza
48  * @author Eduardo Studzinski E. de Castro
49  */

50 public class MethodInterceptorTest implements ItfMethodInterceptor<Integer JavaDoc> {
51
52     /**
53      * List used to test postconstruct callback.
54      */

55     private List JavaDoc<Integer JavaDoc> lstPostconstruct;
56
57     /**
58      * Appends an Integer with the value 0 in the par. This method has 5
59      * interceptors that must be call in order.
60      * @param par array used to append the value
61      * @return the array with modified
62      */

63     @Interceptors({PrintOrder01Interceptor.class, PrintOrder02Interceptor.class, PrintOrder03Interceptor.class,
64             PrintOrder04Interceptor.class, PrintOrder05Interceptor.class})
65     public List JavaDoc<Integer JavaDoc> withFiveMethodInterceptors(final List JavaDoc<Integer JavaDoc> par) {
66         par.add(ORDER);
67         return par;
68     }
69
70     /**
71      * Appends an Integer with the value 0 in the par. This method has 5
72      * interceptors that must be call in order. The interceptor order is
73      * inverse.
74      * @param par array used to append the value
75      * @return the array with modified
76      */

77     @Interceptors({PrintOrder05Interceptor.class, PrintOrder04Interceptor.class, PrintOrder03Interceptor.class,
78             PrintOrder02Interceptor.class, PrintOrder01Interceptor.class})
79     public List JavaDoc<Integer JavaDoc> withFiveMethodInterceptorsInverse(final List JavaDoc<Integer JavaDoc> par) {
80         par.add(ORDER);
81         return par;
82     }
83
84     /**
85      * Appends an Integer with the value 0 in the par. This method has 1
86      * interceptor that must be call in order.
87      * @param par array used to append the value
88      * @return the array with modified
89      */

90     @Interceptors({PrintOrder01Interceptor.class})
91     public List JavaDoc<Integer JavaDoc> withOneMethodInterceptor(final List JavaDoc<Integer JavaDoc> par) {
92         par.add(ORDER);
93         return par;
94     }
95
96     /**
97      * Appends an Integer with the value 0 in the par. This method has no
98      * interceptors.
99      * @param par array used to append the value
100      * @return the array with modified
101      */

102     public List JavaDoc<Integer JavaDoc> withoutInterceptor(final List JavaDoc<Integer JavaDoc> par) {
103         par.add(ORDER);
104         return par;
105     }
106
107     /**
108      * Appends an Integer with the value 0 in the par. This method has 2
109      * interceptors that must be call in order.
110      * @param par array used to append the value
111      * @return the array with modified
112      */

113     @Interceptors({PrintOrder01Interceptor.class, PrintOrder02Interceptor.class})
114     public List JavaDoc<Integer JavaDoc> withTwoMethodInterceptors(final List JavaDoc<Integer JavaDoc> par) {
115         par.add(ORDER);
116         return par;
117     }
118
119     /**
120      * Verifies the list status. The list must be not null, because the PostConstruct callback will initializate this variable.
121      * @return true if the list is properly configured to use.
122      */

123     public boolean checkPostbackInterceptors(){
124         return (lstPostconstruct != null);
125     }
126
127     /**
128      * Creates a list that will be used.
129      */

130     @PostConstruct
131     public void postConstruct(){
132         lstPostconstruct = new ArrayList JavaDoc<Integer JavaDoc>();
133     }
134
135     /**
136      * Appends an Integer with the value 0 in the par. This method has 8
137      * interceptors that must be call in order.
138      * @param par array used to append the value
139      * @return the array with modified
140      */

141     @Interceptors({PrivateInterceptor.class, ProtectedInterceptor.class, PrintOrder01Interceptor.class,
142             PrivateInterceptor.class, PrintOrder03Interceptor.class, PrivateInterceptor.class, ProtectedInterceptor.class,
143             ProtectedInterceptor.class})
144     public List JavaDoc<Integer JavaDoc> withPrivateProtectedPublicInterceptors(final List JavaDoc<Integer JavaDoc> par) {
145         par.add(ORDER);
146         return par;
147     }
148
149     /**
150      * Appends an Integer with the value 0 in the par. This method has 3
151      * interceptors with a private method that must be call in order.
152      * @param par array used to append the value
153      * @return the array with modified
154      */

155     @Interceptors({PrivateInterceptor.class, PrivateInterceptor.class, PrivateInterceptor.class})
156     public List JavaDoc<Integer JavaDoc> withPrivateInterceptors(final List JavaDoc<Integer JavaDoc> par) {
157         par.add(ORDER);
158         return par;
159     }
160
161     /**
162      * Appends an Integer with the value 0 in the par. This method has 2
163      * interceptors with a protected method that must be call in order.
164      * @param par array used to append the value
165      * @return the array with modified
166      */

167     @Interceptors({ProtectedInterceptor.class, ProtectedInterceptor.class})
168     public List JavaDoc<Integer JavaDoc> withProtectedInterceptors(final List JavaDoc<Integer JavaDoc> par) {
169         par.add(ORDER);
170         return par;
171     }
172
173     /**
174      * Appends an Integer with the value 0 in the par. This method has 4
175      * interceptors with a package method that must be call in order.
176      * @param par array used to append the value
177      * @return the array with modified
178      */

179     @Interceptors({PackageInterceptor.class, PackageInterceptor.class, PackageInterceptor.class, PackageInterceptor.class})
180     public List JavaDoc<Integer JavaDoc> withPackageInterceptors(final List JavaDoc<Integer JavaDoc> par) {
181         par.add(ORDER);
182         return par;
183     }
184 }
185
Popular Tags