Coverage Report - org.seasar.teeda.core.render.DefaultDecoder
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultDecoder
66%
19/29
50%
4/8
1.833
 
 1  
 /*
 2  
  * Copyright 2004-2011 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.teeda.core.render;
 17  
 
 18  
 import java.util.Map;
 19  
 
 20  
 import javax.faces.component.EditableValueHolder;
 21  
 import javax.faces.component.UIComponent;
 22  
 import javax.faces.context.FacesContext;
 23  
 
 24  
 import org.seasar.framework.util.AssertionUtil;
 25  
 import org.seasar.teeda.core.exception.NoEditableValueHolderRuntimeException;
 26  
 
 27  
 /**
 28  
  * @author shot
 29  
  */
 30  8
 public class DefaultDecoder implements Decoder {
 31  
 
 32  
     public void decode(FacesContext context, UIComponent component) {
 33  5
         AssertionUtil.assertNotNull("context is null.", context);
 34  4
         AssertionUtil.assertNotNull("component is null.", component);
 35  3
         EditableValueHolder evh = getEditableHolder(component);
 36  2
         Map paramMap = getRequestParameterMap(context);
 37  2
         String clientId = getClientId(component, context);
 38  2
         if (paramMap.containsKey(clientId)) {
 39  1
             Object submittedValue = paramMap.get(clientId);
 40  1
             evh.setSubmittedValue(submittedValue);
 41  
         }
 42  2
     }
 43  
 
 44  
     public void decodeMany(FacesContext context, UIComponent component) {
 45  3
         AssertionUtil.assertNotNull("context is null.", context);
 46  2
         AssertionUtil.assertNotNull("component is null.", component);
 47  1
         EditableValueHolder evh = getEditableHolder(component);
 48  0
         Map paramValuesMap = getRequestParameterValuesMap(context);
 49  0
         String clientId = getClientId(component, context);
 50  0
         String[] value = null;
 51  0
         if (paramValuesMap.containsKey(clientId)) {
 52  0
             value = (String[]) paramValuesMap.get(clientId);
 53  
         }
 54  0
         if (value != null) {
 55  0
             evh.setSubmittedValue(value);
 56  
         } else {
 57  0
             evh.setSubmittedValue(new String[0]);
 58  
         }
 59  0
     }
 60  
 
 61  
     protected Map getRequestParameterMap(FacesContext context) {
 62  2
         return context.getExternalContext().getRequestParameterMap();
 63  
     }
 64  
 
 65  
     protected Map getRequestParameterValuesMap(FacesContext context) {
 66  0
         return context.getExternalContext().getRequestParameterValuesMap();
 67  
     }
 68  
 
 69  
     protected String getClientId(UIComponent component, FacesContext context) {
 70  2
         return component.getClientId(context);
 71  
     }
 72  
 
 73  
     protected EditableValueHolder getEditableHolder(UIComponent component) {
 74  4
         AssertionUtil.assertNotNull("component is null.", component);
 75  4
         if (!(component instanceof EditableValueHolder)) {
 76  2
             throw new NoEditableValueHolderRuntimeException(component
 77  
                     .getClass());
 78  
         }
 79  2
         return (EditableValueHolder) component;
 80  
 
 81  
     }
 82  
 }