001: /*
002: * Copyright (c) 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.binding.tests.beans;
032:
033: import java.beans.PropertyVetoException;
034:
035: import com.jgoodies.binding.beans.Model;
036:
037: /**
038: * A Java Bean that provides a bunch of properties.
039: * The property types are: Object, boolean and int;
040: * the access types are: read-write, read-only and write-only.
041: * In addition, there's a property that doesn't check for changes
042: * - and may cause problems with event notification cycles.
043: * This class is intended to be used by the Binding unit test suite.
044: *
045: * @author Karsten Lentzsch
046: * @version $Revision: 1.18 $
047: */
048: public class TestBean extends Model {
049:
050: public Object readWriteObjectProperty;
051: public boolean readWriteBooleanProperty;
052: public int readWriteIntProperty;
053: public Integer readWriteIntegerProperty;
054: public String readWriteUpperCaseProperty;
055:
056: public Object readOnlyObjectProperty;
057: public boolean readOnlyBooleanProperty;
058: public int readOnlyIntProperty;
059:
060: public Object writeOnlyObjectProperty;
061: public boolean writeOnlyBooleanProperty;
062: public int writeOnlyIntProperty;
063:
064: public Object nullOldValueProperty;
065: public Object nullNewValueProperty;
066: public Object nullOldAndNewValueProperty;
067:
068: public String constrainedProperty;
069:
070: // Getters and Setters for the Read/Write Properties **********************
071:
072: public Object getReadWriteObjectProperty() {
073: return readWriteObjectProperty;
074: }
075:
076: public void setReadWriteObjectProperty(Object newValue) {
077: setReadWriteObjectProperty(newValue, false);
078: }
079:
080: public void setReadWriteObjectProperty(Object newValue,
081: boolean checkIdentity) {
082: Object oldValue = getReadWriteObjectProperty();
083: readWriteObjectProperty = newValue;
084: firePropertyChange("readWriteObjectProperty", oldValue,
085: newValue, checkIdentity);
086: }
087:
088: public boolean isReadWriteBooleanProperty() {
089: return readWriteBooleanProperty;
090: }
091:
092: public void setReadWriteBooleanProperty(boolean newValue) {
093: boolean oldValue = isReadWriteBooleanProperty();
094: readWriteBooleanProperty = newValue;
095: firePropertyChange("readWriteBooleanProperty", oldValue,
096: newValue);
097: }
098:
099: public int getReadWriteIntProperty() {
100: return readWriteIntProperty;
101: }
102:
103: public void setReadWriteIntProperty(int newValue) {
104: int oldValue = getReadWriteIntProperty();
105: readWriteIntProperty = newValue;
106: firePropertyChange("readWriteIntProperty", oldValue, newValue);
107: }
108:
109: public Integer getReadWriteIntegerProperty() {
110: return readWriteIntegerProperty;
111: }
112:
113: public void setReadWriteIntegerProperty(Integer newValue) {
114: Integer oldValue = getReadWriteIntegerProperty();
115: readWriteIntegerProperty = newValue;
116: firePropertyChange("readWriteIntegerProperty", oldValue,
117: newValue);
118: }
119:
120: public String getReadWriteUpperCaseProperty() {
121: return readWriteUpperCaseProperty;
122: }
123:
124: public void setReadWriteUpperCaseProperty(String newValue) {
125: String oldValue = getReadWriteUpperCaseProperty();
126: String newUpperCaseValue = newValue == null ? null : newValue
127: .toUpperCase();
128: readWriteUpperCaseProperty = newUpperCaseValue;
129: firePropertyChange("readWriteUpperCaseProperty", oldValue,
130: newUpperCaseValue);
131: }
132:
133: // Getters for the Read-Only Properties ***********************************
134:
135: public Object getReadOnlyObjectProperty() {
136: return readOnlyObjectProperty;
137: }
138:
139: public boolean isReadOnlyBooleanProperty() {
140: return readOnlyBooleanProperty;
141: }
142:
143: public int getReadOnlyIntProperty() {
144: return readOnlyIntProperty;
145: }
146:
147: // Setters for the Write-Only Properties **********************************
148:
149: public void setWriteOnlyObjectProperty(Object newValue) {
150: writeOnlyObjectProperty = newValue;
151: firePropertyChange("writeOnlyObjectProperty", null, newValue);
152: }
153:
154: public void setWriteOnlyBooleanProperty(boolean newValue) {
155: writeOnlyBooleanProperty = newValue;
156: firePropertyChange("writeOnlyBooleanProperty", null, Boolean
157: .valueOf(newValue));
158: }
159:
160: public void setWriteOnlyIntProperty(int newValue) {
161: writeOnlyIntProperty = newValue;
162: firePropertyChange("writeOnlyIntProperty", null, new Integer(
163: newValue));
164: }
165:
166: // Accessors for Properties that fire events with old or new value == null
167:
168: public Object getNullOldValueProperty() {
169: return nullOldValueProperty;
170: }
171:
172: public void setNullOldValueProperty(Object newValue) {
173: nullOldValueProperty = newValue;
174: firePropertyChange("nullOldValueProperty", null, newValue);
175: }
176:
177: public Object getNullNewValueProperty() {
178: return nullNewValueProperty;
179: }
180:
181: public void setNullNewValueProperty(Object newValue) {
182: Object oldValue = getNullNewValueProperty();
183: nullNewValueProperty = newValue;
184: firePropertyChange("nullNewValueProperty", oldValue, null);
185: }
186:
187: public Object getNullOldAndNewValueProperty() {
188: return nullOldAndNewValueProperty;
189: }
190:
191: public void setNullOldAndNewValueProperty(Object newValue) {
192: nullOldAndNewValueProperty = newValue;
193: firePropertyChange("nullOldAndNewValueProperty", null, null);
194: }
195:
196: // Getters and Setters that Throw Runtime Exceptions **********************
197:
198: /**
199: * Throws a runtime exception.
200: *
201: * @return nothing - won't return
202: */
203: public Object getNoAccess() {
204: return new Integer(3 / 0);
205: }
206:
207: /**
208: * Throws a runtime exception.
209: *
210: * @param object an arbitrary object
211: */
212: public void setNoAccess(Object object) {
213: if (3 / 0 < 4 || object == null)
214: return;
215: }
216:
217: // Multiple Updates *******************************************************
218:
219: public void setReadWriteObjectProperties(Object object, boolean b,
220: int i) {
221: readWriteObjectProperty = object;
222: readWriteBooleanProperty = b;
223: readWriteIntProperty = i;
224: fireMultiplePropertiesChanged();
225: }
226:
227: // Firing Changes on the Read-Only Properties *****************************
228:
229: public void fireChangeOnReadOnlyBooleanProperty(boolean newValue) {
230: boolean oldValue = isReadOnlyBooleanProperty();
231: readOnlyBooleanProperty = newValue;
232: firePropertyChange("readOnlyBooleanProperty", oldValue,
233: newValue);
234: }
235:
236: public void fireChangeOnReadOnlyObjectProperty(Object newValue) {
237: Object oldValue = getReadOnlyObjectProperty();
238: readOnlyObjectProperty = newValue;
239: firePropertyChange("readOnlyObjectProperty", oldValue, newValue);
240: }
241:
242: // Constrained Properties *************************************************
243:
244: public String getConstrainedProperty() {
245: return constrainedProperty;
246: }
247:
248: public void setConstrainedProperty(String newValue)
249: throws PropertyVetoException {
250: String oldValue = getConstrainedProperty();
251: fireVetoableChange("constrainedProperty", oldValue, newValue);
252: constrainedProperty = newValue;
253: firePropertyChange("constrainedProperty", oldValue, newValue);
254: }
255:
256: }
|