1 /*
2 * Copyright 2004-2008 the Seasar Foundation and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.seasar.cubby.interceptor;
17
18 import java.lang.reflect.Method;
19
20 import org.aopalliance.intercept.Interceptor;
21 import org.aopalliance.intercept.Invocation;
22 import org.aopalliance.intercept.MethodInvocation;
23 import org.seasar.cubby.action.Action;
24
25 /**
26 * {@link Interceptor} で使用するユーティリティクラスです。
27 *
28 * @author baba
29 */
30 class InterceptorUtils {
31
32 /**
33 * アクションを取得します。
34 *
35 * @param invocation
36 * 実行メソッドの定義
37 * @return アクション
38 */
39 static Action getAction(final MethodInvocation invocation) {
40 return (Action) invocation.getThis();
41 }
42
43 /**
44 * アクションクラスを取得します。
45 *
46 * @param invocation
47 * 実行メソッドの定義
48 * @return アクションクラス
49 */
50 @SuppressWarnings("unchecked")
51 static Class<? extends Action> getActionClass(
52 final MethodInvocation invocation) {
53 return (Class<? extends Action>) getTargetClass(invocation);
54 }
55
56 /**
57 * アクションメソッドを取得します。
58 *
59 * @param invocation
60 * 実行メソッドの定義
61 * @return アクションメソッド
62 */
63 static Method getMethod(final MethodInvocation invocation) {
64 return invocation.getMethod();
65 }
66
67 /**
68 * バイトコードがエンハンスされる前のクラスを返します。
69 *
70 * @param invocation
71 * invocation
72 * @return エンハンス前のクラス
73 * @since 1.0.2
74 */
75 private static Class<?> getTargetClass(final Invocation invocation) {
76 final Class<?> thisClass = invocation.getThis().getClass();
77 final Class<?> superClass = thisClass.getSuperclass();
78 if (superClass == Object.class) {
79 return thisClass.getInterfaces()[0];
80 }
81 return superClass;
82 }
83
84 }