Coverage Report - org.seasar.cubby.interceptor.InitializeInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
InitializeInterceptor
0%
0/25
0%
0/4
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.CubbyConstants.ATTR_PARAMS;
 19  
 
 20  
 import java.util.Map;
 21  
 
 22  
 import javax.servlet.http.HttpServletRequest;
 23  
 
 24  
 import org.aopalliance.intercept.MethodInterceptor;
 25  
 import org.aopalliance.intercept.MethodInvocation;
 26  
 import org.seasar.cubby.action.Action;
 27  
 import org.seasar.cubby.action.ActionResult;
 28  
 import org.seasar.cubby.controller.ActionContext;
 29  
 import org.seasar.cubby.controller.CubbyConfiguration;
 30  
 import org.seasar.cubby.controller.RequestParser;
 31  
 import org.seasar.cubby.controller.ThreadContext;
 32  
 import org.seasar.cubby.dxo.FormDxo;
 33  
 
 34  
 /**
 35  
  * コントローラの初期化や実行結果のrequest/sessionへの反映などを行うインターセプタです。
 36  
  * {@link Action#initialize()}、{@link Action#prerender()} の実行を行います。
 37  
  * 
 38  
  * @author agata
 39  
  * @author baba
 40  
  * @since 1.0
 41  
  */
 42  0
 public class InitializeInterceptor implements MethodInterceptor {
 43  
 
 44  
         private HttpServletRequest request;
 45  
 
 46  
         private ActionContext context;
 47  
 
 48  
         public void setRequest(final HttpServletRequest request) {
 49  0
                 this.request = request;
 50  0
         }
 51  
 
 52  
         public void setActionContext(final ActionContext context) {
 53  0
                 this.context = context;
 54  0
         }
 55  
 
 56  
         public Object invoke(final MethodInvocation invocation) throws Throwable {
 57  0
                 setupParams(context, request);
 58  0
                 setupForm(context, request);
 59  
 
 60  0
                 final Action action = context.getAction();
 61  0
                 action.initialize();
 62  
 
 63  0
                 final ActionResult result = (ActionResult) invocation.proceed();
 64  0
                 if (result != null) {
 65  0
                         result.prerender(context);
 66  
                 }
 67  
 
 68  0
                 return result;
 69  
         }
 70  
 
 71  
         void setupParams(final ActionContext context,
 72  
                         final HttpServletRequest request) {
 73  0
                 final CubbyConfiguration configuration = ThreadContext
 74  
                                 .getConfiguration();
 75  0
                 final RequestParser requestParser = configuration.getRequestParser();
 76  0
                 final Map<String, Object[]> parameterMap = requestParser
 77  
                                 .getParameterMap(request);
 78  0
                 request.setAttribute(ATTR_PARAMS, parameterMap);
 79  0
         }
 80  
 
 81  
         private void setupForm(final ActionContext context,
 82  
                         final HttpServletRequest request) {
 83  0
                 final Object formBean = context.getFormBean();
 84  0
                 if (formBean != null) {
 85  0
                         final FormDxo formDxo = context.getFormDxo();
 86  0
                         final Map<String, Object[]> params = getParams(request);
 87  0
                         formDxo.convert(params, formBean);
 88  
                 }
 89  0
         }
 90  
 
 91  
         @SuppressWarnings("unchecked")
 92  
         private static Map<String, Object[]> getParams(
 93  
                         final HttpServletRequest request) {
 94  0
                 return (Map<String, Object[]>) request.getAttribute(ATTR_PARAMS);
 95  
         }
 96  
 
 97  
 }