| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ScalarDataModel |
|
| 2.4444444444444446;2.444 |
| 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 | /** | |
| 19 | * @author shot | |
| 20 | */ | |
| 21 | public class ScalarDataModel extends DataModel { | |
| 22 | ||
| 23 | 12 | private Object scalar = null; |
| 24 | ||
| 25 | 12 | private int index = -1; |
| 26 | ||
| 27 | public ScalarDataModel() { | |
| 28 | 12 | this(null); |
| 29 | 12 | } |
| 30 | ||
| 31 | public ScalarDataModel(Object scalar) { | |
| 32 | 12 | super(); |
| 33 | 12 | setWrappedData(scalar); |
| 34 | 12 | } |
| 35 | ||
| 36 | public int getRowCount() { | |
| 37 | 2 | return (scalar != null) ? 1 : -1; |
| 38 | } | |
| 39 | ||
| 40 | public Object getRowData() { | |
| 41 | 3 | if (scalar == null) { |
| 42 | 1 | return null; |
| 43 | } | |
| 44 | 2 | if (!isRowAvailable()) { |
| 45 | 1 | throw new IllegalArgumentException(); |
| 46 | } | |
| 47 | 1 | return scalar; |
| 48 | } | |
| 49 | ||
| 50 | public int getRowIndex() { | |
| 51 | 4 | return (scalar != null) ? 0 : -1; |
| 52 | } | |
| 53 | ||
| 54 | public Object getWrappedData() { | |
| 55 | 0 | return scalar; |
| 56 | } | |
| 57 | ||
| 58 | public boolean isRowAvailable() { | |
| 59 | 5 | if (scalar == null) { |
| 60 | 2 | return false; |
| 61 | } | |
| 62 | 3 | return (index == 0) ? true : false; |
| 63 | } | |
| 64 | ||
| 65 | public void setRowIndex(int rowIndex) { | |
| 66 | 24 | if (rowIndex < -1) { |
| 67 | 0 | throw new IllegalArgumentException(); |
| 68 | } | |
| 69 | ||
| 70 | 24 | int oldIndex = index; |
| 71 | 24 | index = rowIndex; |
| 72 | ||
| 73 | 24 | if (scalar == null) { |
| 74 | 16 | return; |
| 75 | } | |
| 76 | ||
| 77 | 8 | DataModelListener[] listeners = getDataModelListeners(); |
| 78 | 8 | if ((oldIndex != index) && (listeners != null)) { |
| 79 | 7 | DataModelEvent event = new DataModelEvent(this, index, scalar); |
| 80 | 7 | for (int i = 0; i < listeners.length; i++) { |
| 81 | 0 | listeners[i].rowSelected(event); |
| 82 | } | |
| 83 | } | |
| 84 | 8 | } |
| 85 | ||
| 86 | public void setWrappedData(Object data) { | |
| 87 | 21 | if (data == null) { |
| 88 | 15 | scalar = null; |
| 89 | 15 | setRowIndex(-1); |
| 90 | } else { | |
| 91 | 6 | scalar = data; |
| 92 | 6 | setRowIndex(0); |
| 93 | } | |
| 94 | 21 | } |
| 95 | } |