KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > enterprise > interceptor_stateless_ejb > ArgumentsChecker


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package enterprise.interceptor_stateless_ejb;
24
25 import java.lang.reflect.Method JavaDoc;
26
27 import javax.interceptor.AroundInvoke;
28 import javax.interceptor.InvocationContext;
29
30 public class ArgumentsChecker {
31
32     @AroundInvoke
33     public Object JavaDoc checkArgument(InvocationContext ctx) throws Exception JavaDoc {
34         Method JavaDoc method = ctx.getMethod();
35         if (method.getName().equals("initUpperCase")) {
36             String JavaDoc param = (String JavaDoc) (ctx.getParameters()[0]);
37             // Note that param cannot be null because
38
// it has been validated by the previous interceptor
39
char c = param.charAt(0);
40             if (!Character.isLetter(c)) {
41                 // An interceptor can throw any runtime exception or
42
// application exceptions that are allowed in the
43
// throws clause of the business method
44
throw new BadArgumentException("Illegal argument: " + param);
45             }
46         }
47
48         // Proceed to call the business method
49
return ctx.proceed();
50     }
51
52 }
53
Popular Tags