Coverage Report - javax.faces.internal.UIDataUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
UIDataUtil
53%
9/17
57%
8/14
4
 
 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 javax.faces.internal;
 17  
 
 18  
 import java.sql.ResultSet;
 19  
 import java.util.Collections;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.faces.model.ArrayDataModel;
 23  
 import javax.faces.model.DataModel;
 24  
 import javax.faces.model.ListDataModel;
 25  
 import javax.faces.model.ResultDataModel;
 26  
 import javax.faces.model.ResultSetDataModel;
 27  
 import javax.faces.model.ScalarDataModel;
 28  
 import javax.servlet.jsp.jstl.sql.Result;
 29  
 
 30  
 /**
 31  
  * @author shot
 32  
  * 
 33  
  * This class might be changed without notice. Please do not use it
 34  
  * excluding the JSF specification part.
 35  
  */
 36  
 public class UIDataUtil {
 37  
 
 38  0
     private UIDataUtil() {
 39  0
     }
 40  
 
 41  
     public static DataModel getSuitableDataModel(Object obj) {
 42  47
         DataModel model = null;
 43  47
         if (obj == null) {
 44  4
             model = new ListDataModel(Collections.EMPTY_LIST);
 45  43
         } else if (obj instanceof DataModel) {
 46  18
             model = (DataModel) obj;
 47  25
         } else if (obj instanceof List) {
 48  0
             model = new ListDataModel((List) obj);
 49  26
         } else if (Object[].class.isAssignableFrom(obj.getClass())) {
 50  25
             model = new ArrayDataModel((Object[]) obj);
 51  0
         } else if (obj instanceof ResultSet) {
 52  0
             model = new ResultSetDataModel((ResultSet) obj);
 53  0
         } else if (obj instanceof Result) {
 54  0
             model = new ResultDataModel((Result) obj);
 55  
         } else {
 56  0
             model = new ScalarDataModel(obj);
 57  
         }
 58  47
         return model;
 59  
     }
 60  
 
 61  
 }