1 16 package javax.faces.model; 17 18 import javax.servlet.jsp.jstl.sql.Result; 19 import java.util.SortedMap ; 20 21 25 public class ResultDataModel extends DataModel 26 { 27 private int _rowIndex = -1; 29 private SortedMap [] _data; 30 31 public ResultDataModel() 33 { 34 super(); 35 } 36 37 public ResultDataModel(Result result) 38 { 39 if (result == null) throw new NullPointerException ("result"); 40 setWrappedData(result); 41 } 42 43 public int getRowCount() 45 { 46 if (_data == null) 47 { 48 return -1; 49 } 50 return _data.length; 51 } 52 53 public Object getRowData() 54 { 55 if (_data == null) 56 { 57 return null; 58 } 59 if (!isRowAvailable()) 60 { 61 throw new IllegalArgumentException ("row is unavailable"); 62 } 63 return _data[_rowIndex]; 64 } 65 66 public int getRowIndex() 67 { 68 return _rowIndex; 69 } 70 71 public Object getWrappedData() 72 { 73 return _data; 74 } 75 76 public boolean isRowAvailable() 77 { 78 if (_data == null) 79 { 80 return false; 81 } 82 return _rowIndex >= 0 && _rowIndex < _data.length; 83 } 84 85 public void setRowIndex(int rowIndex) 86 { 87 if (rowIndex < -1) 88 { 89 throw new IllegalArgumentException ("illegal rowIndex " + rowIndex); 90 } 91 int oldRowIndex = _rowIndex; 92 _rowIndex = rowIndex; 93 if (_data != null && oldRowIndex != _rowIndex) 94 { 95 Object data = isRowAvailable() ? getRowData() : null; 96 DataModelEvent event = new DataModelEvent(this, _rowIndex, data); 97 DataModelListener[] listeners = getDataModelListeners(); 98 for (int i = 0; i < listeners.length; i++) 99 { 100 listeners[i].rowSelected(event); 101 } 102 } 103 } 104 105 public void setWrappedData(Object data) 106 { 107 if (data == null) 108 { 109 setRowIndex(-1); 110 } 111 else 112 { 113 _data = ((Result)data).getRows(); 114 setRowIndex(0); 115 } 116 } 117 118 } 119 | Popular Tags |