Coverage Report - javax.faces.model.ResultDataModel
 
Classes in this File Line Coverage Branch Coverage Complexity
ResultDataModel
0%
0/39
0%
0/28
2.7
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package javax.faces.model;
 20  
 
 21  
 import java.util.SortedMap;
 22  
 
 23  
 import javax.servlet.jsp.jstl.sql.Result;
 24  
 
 25  
 //import javax.servlet.jsp.
 26  
 /**
 27  
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
 28  
  *
 29  
  * @author Thomas Spiegl (latest modification by $Author: skitching $)
 30  
  * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Sun, 13 Jul 2008) $
 31  
  */
 32  
 public class ResultDataModel extends DataModel
 33  
 {
 34  
     // FIELDS
 35  0
     private int _rowIndex = -1;
 36  
     private Result _data;
 37  
 
 38  
     // CONSTRUCTORS
 39  
     public ResultDataModel()
 40  
     {
 41  0
         super();
 42  0
     }
 43  
 
 44  
     public ResultDataModel(Result result)
 45  0
     {
 46  0
         if (result == null) throw new NullPointerException("result");
 47  0
         setWrappedData(result);
 48  0
     }
 49  
 
 50  
     // METHODS
 51  
     public int getRowCount()
 52  
     {
 53  0
         if (getRows() == null)
 54  
         {
 55  0
             return -1;
 56  
         }
 57  0
         return getRows().length;
 58  
     }
 59  
 
 60  
     public Object getRowData()
 61  
     {
 62  0
         if (getRows() == null)
 63  
         {
 64  0
             return null;
 65  
         }
 66  0
         if (!isRowAvailable())
 67  
         {
 68  0
             throw new IllegalArgumentException("row is unavailable");
 69  
         }
 70  0
         return getRows()[_rowIndex];
 71  
     }
 72  
 
 73  
     public int getRowIndex()
 74  
     {
 75  0
         return _rowIndex;
 76  
     }
 77  
 
 78  
     public Object getWrappedData()
 79  
     {
 80  0
         return _data;
 81  
     }
 82  
 
 83  
     public boolean isRowAvailable()
 84  
     {
 85  0
         if (getRows() == null)
 86  
         {
 87  0
             return false;
 88  
         }
 89  0
         return _rowIndex >= 0 && _rowIndex < getRows().length;
 90  
     }
 91  
 
 92  
     public void setRowIndex(int rowIndex)
 93  
     {
 94  0
         if (rowIndex < -1)
 95  
         {
 96  0
             throw new IllegalArgumentException("illegal rowIndex " + rowIndex);
 97  
         }
 98  0
         int oldRowIndex = _rowIndex;
 99  0
         _rowIndex = rowIndex;
 100  0
         if (getRows() != null && oldRowIndex != _rowIndex)
 101  
         {
 102  0
             Object data = isRowAvailable() ? getRowData() : null;
 103  0
             DataModelEvent event = new DataModelEvent(this, _rowIndex, data);
 104  0
             DataModelListener[] listeners = getDataModelListeners();
 105  0
             for (int i = 0; i < listeners.length; i++)
 106  
             {
 107  0
                 listeners[i].rowSelected(event);
 108  
             }
 109  
         }
 110  0
     }
 111  
 
 112  
     private SortedMap[] getRows()
 113  
     {
 114  0
         if(_data==null)
 115  0
             return null;
 116  
 
 117  0
         return _data.getRows();
 118  
     }
 119  
 
 120  
     public void setWrappedData(Object data)
 121  
     {
 122  0
         if (data == null)
 123  
         {
 124  0
             setRowIndex(-1);
 125  
         }
 126  
         else
 127  
         {
 128  0
             _data = ((Result)data);
 129  0
             setRowIndex(0);
 130  
         }
 131  0
     }
 132  
 
 133  
 }