Coverage Report - javax.faces.model.ResultDataModel
 
Classes in this File Line Coverage Branch Coverage Complexity
ResultDataModel
0%
0/41
0%
0/28
2.9
 
 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  0
 public class ResultDataModel extends DataModel<SortedMap<String, Object>>
 30  
 {
 31  
     // FIELDS
 32  0
     private int _rowIndex = -1;
 33  
     private Result _data;
 34  
 
 35  
     // CONSTRUCTORS
 36  
     public ResultDataModel()
 37  
     {
 38  0
         super();
 39  0
     }
 40  
 
 41  
     public ResultDataModel(Result result)
 42  0
     {
 43  0
         if (result == null)
 44  
         {
 45  0
             throw new NullPointerException("result");
 46  
         }
 47  0
         setWrappedData(result);
 48  0
     }
 49  
 
 50  
     // METHODS
 51  
     @Override
 52  
     public int getRowCount()
 53  
     {
 54  0
         if (getRows() == null)
 55  
         {
 56  0
             return -1;
 57  
         }
 58  0
         return getRows().length;
 59  
     }
 60  
 
 61  
     @Override
 62  
     public SortedMap<String, Object> getRowData()
 63  
     {
 64  0
         if (getRows() == null)
 65  
         {
 66  0
             return null;
 67  
         }
 68  0
         if (!isRowAvailable())
 69  
         {
 70  0
             throw new IllegalArgumentException("row is unavailable");
 71  
         }
 72  0
         return getRows()[_rowIndex];
 73  
     }
 74  
 
 75  
     @Override
 76  
     public int getRowIndex()
 77  
     {
 78  0
         return _rowIndex;
 79  
     }
 80  
 
 81  
     @Override
 82  
     public Object getWrappedData()
 83  
     {
 84  0
         return _data;
 85  
     }
 86  
 
 87  
     @Override
 88  
     public boolean isRowAvailable()
 89  
     {
 90  0
         return getRows() != null && _rowIndex >= 0 && _rowIndex < getRows().length;
 91  
     }
 92  
 
 93  
     @Override
 94  
     public void setRowIndex(int rowIndex)
 95  
     {
 96  0
         if (rowIndex < -1)
 97  
         {
 98  0
             throw new IllegalArgumentException("illegal rowIndex " + rowIndex);
 99  
         }
 100  0
         int oldRowIndex = _rowIndex;
 101  0
         _rowIndex = rowIndex;
 102  0
         if (getRows() != null && oldRowIndex != _rowIndex)
 103  
         {
 104  0
             SortedMap<String, Object> data = isRowAvailable() ? getRowData() : null;
 105  0
             DataModelEvent event = new DataModelEvent(this, _rowIndex, data);
 106  0
             DataModelListener[] listeners = getDataModelListeners();
 107  0
             for (int i = 0; i < listeners.length; i++)
 108  
             {
 109  0
                 listeners[i].rowSelected(event);
 110  
             }
 111  
         }
 112  0
     }
 113  
 
 114  
     private SortedMap<String, Object>[] getRows()
 115  
     {
 116  0
         if (_data == null)
 117  
         {
 118  0
             return null;
 119  
         }
 120  
 
 121  0
         return _data.getRows();
 122  
     }
 123  
 
 124  
     @Override
 125  
     public void setWrappedData(Object data)
 126  
     {
 127  0
         if (data == null)
 128  
         {
 129  0
             setRowIndex(-1);
 130  0
             _data = null;
 131  
         }
 132  
         else
 133  
         {
 134  0
             _data = ((Result)data);
 135  0
             _rowIndex = -1;
 136  0
             setRowIndex(0);
 137  
         }
 138  0
     }
 139  
 
 140  
 }