01: /*
02: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * Resin Open Source is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License version 2
11: * as published by the Free Software Foundation.
12: *
13: * Resin Open Source is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
16: * of NON-INFRINGEMENT. See the GNU General Public License for more
17: * details.
18: *
19: * You should have received a copy of the GNU General Public License
20: * along with Resin Open Source; if not, write to the
21: *
22: * Free Software Foundation, Inc.
23: * 59 Temple Place, Suite 330
24: * Boston, MA 02111-1307 USA
25: *
26: * @author Scott Ferguson
27: */
28:
29: package javax.faces.model;
30:
31: public class ScalarDataModel extends DataModel {
32: private Object _value;
33: private int _rowIndex = -1;
34:
35: public ScalarDataModel() {
36: }
37:
38: public ScalarDataModel(Object value) {
39: _value = value;
40: setRowIndex(0);
41: }
42:
43: public int getRowCount() {
44: if (_value != null)
45: return 1;
46: else
47: return -1;
48: }
49:
50: public Object getRowData() {
51: if (_value == null)
52: return null;
53: else if (getRowIndex() < 1)
54: return _value;
55: else
56: throw new IllegalArgumentException();
57: }
58:
59: public boolean isRowAvailable() {
60: return _value != null && getRowIndex() < 1;
61: }
62:
63: public Object getWrappedData() {
64: return _value;
65: }
66:
67: public void setWrappedData(Object data) {
68: _value = data;
69: setRowIndex(0);
70: }
71:
72: public int getRowIndex() {
73: return _rowIndex;
74: }
75:
76: public void setRowIndex(int index) {
77: if (_value != null && index < -1)
78: throw new IllegalArgumentException("rowIndex '" + index
79: + "' cannot be less than -1.");
80:
81: DataModelListener[] listeners = getDataModelListeners();
82:
83: if (listeners.length > 0 && _value != null
84: && _rowIndex != index) {
85: DataModelEvent event = new DataModelEvent(this , index,
86: _value);
87:
88: for (int i = 0; i < listeners.length; i++) {
89: listeners[i].rowSelected(event);
90: }
91: }
92:
93: _rowIndex = index;
94: }
95: }
|