Coverage Report - org.seasar.cubby.interceptor.ValidationInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidationInterceptor
85%
11/13
N/A
0
 
 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 static org.seasar.cubby.interceptor.InterceptorUtils.getAction;
 19  
 import static org.seasar.cubby.interceptor.InterceptorUtils.getActionClass;
 20  
 import static org.seasar.cubby.interceptor.InterceptorUtils.getMethod;
 21  
 
 22  
 import java.lang.reflect.Method;
 23  
 
 24  
 import javax.servlet.http.HttpServletRequest;
 25  
 
 26  
 import org.aopalliance.intercept.MethodInterceptor;
 27  
 import org.aopalliance.intercept.MethodInvocation;
 28  
 import org.seasar.cubby.action.Action;
 29  
 import org.seasar.cubby.validator.ValidationException;
 30  
 import org.seasar.cubby.validator.ValidationProcessor;
 31  
 
 32  
 /**
 33  
  * 入力検証を行います。
 34  
  * 
 35  
  * @author agata
 36  
  * @author baba
 37  
  * @since 1.0.0
 38  
  */
 39  
 public class ValidationInterceptor implements MethodInterceptor {
 40  
 
 41  
         /** 入力検証処理。 */
 42  
         private ValidationProcessor validationProcessor;
 43  
 
 44  
         /** リクエスト。 */
 45  
         private HttpServletRequest request;
 46  
 
 47  
         /**
 48  
          * インスタンス化します。
 49  
          */
 50  1
         public ValidationInterceptor() {
 51  1
         }
 52  
 
 53  
         /**
 54  
          * 入力検証処理を設定します。
 55  
          * 
 56  
          * @param validationProcessor
 57  
          *            入力検証処理
 58  
          */
 59  
         public void setValidationProcessor(
 60  
                         final ValidationProcessor validationProcessor) {
 61  1
                 this.validationProcessor = validationProcessor;
 62  1
         }
 63  
 
 64  
         /**
 65  
          * リクエストを設定します。
 66  
          * 
 67  
          * @param request
 68  
          *            リクエスト
 69  
          */
 70  
         public void setRequest(final HttpServletRequest request) {
 71  1
                 this.request = request;
 72  1
         }
 73  
 
 74  
         /**
 75  
          * {@inheritDoc}
 76  
          * <p>
 77  
          * メソッドの実行前に入力検証を実行します。
 78  
          * </p>
 79  
          */
 80  
         public Object invoke(final MethodInvocation invocation) throws Throwable {
 81  2
                 final Action action = getAction(invocation);
 82  2
                 final Class<? extends Action> actionClass = getActionClass(invocation);
 83  2
                 final Method method = getMethod(invocation);
 84  
                 try {
 85  2
                         validationProcessor.process(request, action, actionClass, method);
 86  2
                         return invocation.proceed();
 87  0
                 } catch (final ValidationException e) {
 88  0
                         return validationProcessor.handleValidationException(e, request,
 89  
                                         action, method);
 90  
                 }
 91  
         }
 92  
 
 93  
 }