Coverage Report - javax.faces.model.ResultDataModel
 
Classes in this File Line Coverage Branch Coverage Complexity
ResultDataModel
100%
40/40
88%
23/26
2.556
 
 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.model;
 17  
 
 18  
 import java.util.SortedMap;
 19  
 
 20  
 import javax.servlet.jsp.jstl.sql.Result;
 21  
 
 22  
 public class ResultDataModel extends DataModel {
 23  
 
 24  14
     private Result result = null;
 25  
 
 26  14
     private int index = -1;
 27  
 
 28  14
     private SortedMap[] rows_ = null;
 29  
 
 30  
     public ResultDataModel() {
 31  6
         this(null);
 32  6
     }
 33  
 
 34  
     public ResultDataModel(Result result) {
 35  14
         super();
 36  14
         setWrappedData(result);
 37  14
     }
 38  
 
 39  
     public int getRowCount() {
 40  2
         return (result != null) ? rows_.length : -1;
 41  
     }
 42  
 
 43  
     public Object getRowData() {
 44  17
         if (result == null) {
 45  1
             return null;
 46  
         }
 47  
 
 48  16
         if (!isRowAvailable()) {
 49  1
             throw new IllegalArgumentException();
 50  
         }
 51  15
         return rows_[index];
 52  
     }
 53  
 
 54  
     public int getRowIndex() {
 55  3
         return index;
 56  
     }
 57  
 
 58  
     public Object getWrappedData() {
 59  3
         return result;
 60  
     }
 61  
 
 62  
     public boolean isRowAvailable() {
 63  36
         if (result == null) {
 64  1
             return false;
 65  
         }
 66  35
         return (index >= 0 && index < rows_.length);
 67  
     }
 68  
 
 69  
     public void setRowIndex(int rowIndex) {
 70  
 
 71  24
         if (rowIndex < -1) {
 72  1
             throw new IllegalArgumentException();
 73  
         }
 74  
 
 75  23
         int oldIndex = index;
 76  23
         index = rowIndex;
 77  
 
 78  23
         if (result == null) {
 79  7
             return;
 80  
         }
 81  
 
 82  16
         DataModelListener[] listeners = getDataModelListeners();
 83  16
         if ((oldIndex != index) && (listeners != null)) {
 84  16
             Object rowData = null;
 85  16
             if (isRowAvailable()) {
 86  13
                 rowData = getRowData();
 87  
             }
 88  
 
 89  16
             DataModelEvent event = new DataModelEvent(this, index, rowData);
 90  18
             for (int i = 0; i < listeners.length; i++) {
 91  2
                 listeners[i].rowSelected(event);
 92  
             }
 93  
         }
 94  
 
 95  16
     }
 96  
 
 97  
     public void setWrappedData(Object data) {
 98  15
         if (data == null) {
 99  6
             setRowIndex(-1);
 100  
         } else {
 101  9
             result = (Result) data;
 102  9
             rows_ = result.getRows();
 103  9
             setRowIndex(0);
 104  
         }
 105  15
     }
 106  
 
 107  
 }