Coverage Report - org.seasar.teeda.core.util.UIParameterUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
UIParameterUtil
91%
21/23
67%
8/12
3
 
 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.util;
 17  
 
 18  
 import java.util.Iterator;
 19  
 import java.util.List;
 20  
 
 21  
 import javax.faces.component.UIComponent;
 22  
 import javax.faces.component.UIParameter;
 23  
 import javax.faces.context.FacesContext;
 24  
 
 25  
 import org.seasar.framework.beans.BeanDesc;
 26  
 import org.seasar.framework.beans.PropertyDesc;
 27  
 import org.seasar.framework.beans.factory.BeanDescFactory;
 28  
 import org.seasar.framework.util.AssertionUtil;
 29  
 
 30  
 public class UIParameterUtil {
 31  
 
 32  0
     private UIParameterUtil() {
 33  0
     }
 34  
 
 35  
     public static void saveParametersToRequest(UIComponent component,
 36  
             FacesContext context) {
 37  1
         List children = component.getChildren();
 38  3
         for (int i = 0; i < children.size(); ++i) {
 39  2
             Object o = (UIComponent) children.get(i);
 40  2
             if (o instanceof UIParameter) {
 41  2
                 UIParameter param = (UIParameter) o;
 42  2
                 context.getExternalContext().getRequestMap().put(
 43  
                         param.getName(), param.getValue());
 44  
             }
 45  
         }
 46  1
     }
 47  
 
 48  
     public static void saveParametersToInstance(UIComponent component,
 49  
             Object obj) {
 50  1
         AssertionUtil.assertNotNull("component", component);
 51  1
         AssertionUtil.assertNotNull("obj", obj);
 52  1
         for (Iterator itr = component.getChildren().iterator(); itr.hasNext();) {
 53  2
             Object o = itr.next();
 54  2
             if (o instanceof UIParameter) {
 55  2
                 UIParameter param = (UIParameter) o;
 56  2
                 String name = param.getName();
 57  2
                 Object value = param.getValue();
 58  2
                 BeanDesc beanDesc = BeanDescFactory.getBeanDesc(obj.getClass());
 59  2
                 if (beanDesc.hasPropertyDesc(name)) {
 60  2
                     PropertyDesc propertyDesc = beanDesc.getPropertyDesc(name);
 61  2
                     if (propertyDesc.isWritable()) {
 62  2
                         propertyDesc.setValue(obj, value);
 63  
                     }
 64  
                 }
 65  
             }
 66  
         }
 67  1
     }
 68  
 
 69  
 }