001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: BeanImpl.java 3714 2007-04-08 02:57:38Z gbevin $
007: */
008: package com.uwyn.rife.engine.testelements.submission;
009:
010: import com.uwyn.rife.config.RifeConfig;
011: import com.uwyn.rife.site.ConstrainedProperty;
012: import com.uwyn.rife.site.Validation;
013: import java.io.InputStream;
014: import java.io.Serializable;
015: import java.text.SimpleDateFormat;
016: import java.util.Date;
017:
018: public class BeanImpl extends Validation {
019: public enum Day {
020: SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
021: }
022:
023: private Day mEnum;
024: private String mString;
025: private StringBuffer mStringbuffer;
026: private int mInt;
027: private Integer mInteger;
028: private char mChar;
029: private Character mCharacter;
030: private boolean mBoolean;
031: private Boolean mBooleanObject;
032: private byte mByte;
033: private Byte mByteObject;
034: private double mDouble;
035: private Double mDoubleObject;
036: private float mFloat;
037: private Float mFloatObject;
038: private long mLong;
039: private Long mLongObject;
040: private short mShort = -24;
041: private Short mShortObject;
042: private String mStringFile;
043: private byte[] mBytesFile;
044: private InputStream mStreamFile;
045: private Date mDate;
046: private Date mDateFormatted;
047: private Date[] mDatesFormatted;
048: private SerializableParam mSerializableParam;
049: private SerializableParam[] mSerializableParams;
050:
051: public void activateValidation() {
052: addConstraint(new ConstrainedProperty("character")
053: .editable(false));
054: addConstraint(new ConstrainedProperty("byte").editable(false));
055: addConstraint(new ConstrainedProperty("stringFile").file(true));
056: addConstraint(new ConstrainedProperty("bytesFile").file(true));
057: addConstraint(new ConstrainedProperty("streamFile").file(true));
058:
059: addGroup("somegroup").addConstraint(
060: new ConstrainedProperty("enum")).addConstraint(
061: new ConstrainedProperty("string")).addConstraint(
062: new ConstrainedProperty("int")).addConstraint(
063: new ConstrainedProperty("longObject")).addConstraint(
064: new ConstrainedProperty("short"));
065:
066: addGroup("anothergroup").addConstraint(
067: new ConstrainedProperty("double")).addConstraint(
068: new ConstrainedProperty("long")).addConstraint(
069: new ConstrainedProperty("shortObject"));
070:
071: SimpleDateFormat sf = new SimpleDateFormat(
072: "EEE d MMM yyyy HH:mm:ss");
073: sf.setTimeZone(RifeConfig.Tools.getDefaultTimeZone());
074: addConstraint(new ConstrainedProperty("dateFormatted")
075: .format(sf));
076: addConstraint(new ConstrainedProperty("datesFormatted")
077: .format(sf));
078: }
079:
080: public void setEnum(Day day) {
081: mEnum = day;
082: }
083:
084: public Day getEnum() {
085: return mEnum;
086: }
087:
088: public String getString() {
089: return mString;
090: }
091:
092: public void setString(String string) {
093: mString = string;
094: }
095:
096: public StringBuffer getStringbuffer() {
097: return mStringbuffer;
098: }
099:
100: public void setStringbuffer(StringBuffer stringbuffer) {
101: mStringbuffer = stringbuffer;
102: }
103:
104: public int getInt() {
105: return mInt;
106: }
107:
108: public void setInt(int anInt) {
109: mInt = anInt;
110: }
111:
112: public Integer getInteger() {
113: return mInteger;
114: }
115:
116: public void setInteger(Integer integer) {
117: mInteger = integer;
118: }
119:
120: public char getChar() {
121: return mChar;
122: }
123:
124: public void setChar(char aChar) {
125: mChar = aChar;
126: }
127:
128: public Character getCharacter() {
129: return mCharacter;
130: }
131:
132: public void setCharacter(Character character) {
133: mCharacter = character;
134: }
135:
136: public boolean isBoolean() {
137: return mBoolean;
138: }
139:
140: public void setBoolean(boolean aBoolean) {
141: mBoolean = aBoolean;
142: }
143:
144: public Boolean getBooleanObject() {
145: return mBooleanObject;
146: }
147:
148: public void setBooleanObject(Boolean aBooleanObject) {
149: mBooleanObject = aBooleanObject;
150: }
151:
152: public byte getByte() {
153: return mByte;
154: }
155:
156: public void setByte(byte aByte) {
157: mByte = aByte;
158: }
159:
160: public Byte getByteObject() {
161: return mByteObject;
162: }
163:
164: public void setByteObject(Byte byteObject) {
165: mByteObject = byteObject;
166: }
167:
168: public double getDouble() {
169: return mDouble;
170: }
171:
172: public void setDouble(double aDouble) {
173: mDouble = aDouble;
174: }
175:
176: public Double getDoubleObject() {
177: return mDoubleObject;
178: }
179:
180: public void setDoubleObject(Double doubleObject) {
181: mDoubleObject = doubleObject;
182: }
183:
184: public float getFloat() {
185: return mFloat;
186: }
187:
188: public void setFloat(float aFloat) {
189: mFloat = aFloat;
190: }
191:
192: public Float getFloatObject() {
193: return mFloatObject;
194: }
195:
196: public void setFloatObject(Float floatObject) {
197: mFloatObject = floatObject;
198: }
199:
200: public long getLong() {
201: return mLong;
202: }
203:
204: public void setLong(long aLong) {
205: mLong = aLong;
206: }
207:
208: public Long getLongObject() {
209: return mLongObject;
210: }
211:
212: public void setLongObject(Long longObject) {
213: mLongObject = longObject;
214: }
215:
216: public short getShort() {
217: return mShort;
218: }
219:
220: public void setShort(short aShort) {
221: mShort = aShort;
222: }
223:
224: public Short getShortObject() {
225: return mShortObject;
226: }
227:
228: public void setShortObject(Short shortObject) {
229: mShortObject = shortObject;
230: }
231:
232: public void setStringFile(String stringFile) {
233: mStringFile = stringFile;
234: }
235:
236: public String getStringFile() {
237: return mStringFile;
238: }
239:
240: public void setBytesFile(byte[] bytesFile) {
241: mBytesFile = bytesFile;
242: }
243:
244: public byte[] getBytesFile() {
245: return mBytesFile;
246: }
247:
248: public void setStreamFile(InputStream streamFile) {
249: mStreamFile = streamFile;
250: }
251:
252: public InputStream getStreamFile() {
253: return mStreamFile;
254: }
255:
256: public void setDate(Date date) {
257: mDate = date;
258: }
259:
260: public Date getDate() {
261: return mDate;
262: }
263:
264: public void setDateFormatted(Date dateFormatted) {
265: mDateFormatted = dateFormatted;
266: }
267:
268: public Date getDateFormatted() {
269: return mDateFormatted;
270: }
271:
272: public void setDatesFormatted(Date[] datesFormatted) {
273: mDatesFormatted = datesFormatted;
274: }
275:
276: public Date[] getDatesFormatted() {
277: return mDatesFormatted;
278: }
279:
280: public void setSerializableParam(SerializableParam serializableParam) {
281: mSerializableParam = serializableParam;
282: }
283:
284: public SerializableParam getSerializableParam() {
285: return mSerializableParam;
286: }
287:
288: public void setSerializableParams(
289: SerializableParam[] serializableParams) {
290: mSerializableParams = serializableParams;
291: }
292:
293: public SerializableParam[] getSerializableParams() {
294: return mSerializableParams;
295: }
296:
297: public static class SerializableParam implements Serializable {
298: private int mNumber = -1;
299: private String mString = null;
300:
301: public SerializableParam(int number, String string) {
302: mNumber = number;
303: mString = string;
304: }
305:
306: public void setNumber(int number) {
307: mNumber = number;
308: }
309:
310: public int getNumber() {
311: return mNumber;
312: }
313:
314: public void setString(String string) {
315: mString = string;
316: }
317:
318: public String getString() {
319: return mString;
320: }
321:
322: public String toString() {
323: return mNumber + ":" + mString;
324: }
325:
326: public boolean equals(Object other) {
327: if (this == other) {
328: return true;
329: }
330:
331: if (null == other) {
332: return false;
333: }
334:
335: if (!(other instanceof SerializableParam)) {
336: return false;
337: }
338:
339: SerializableParam other_datalink = (SerializableParam) other;
340: if (!other_datalink.getString().equals(getString())) {
341: return false;
342: }
343: if (other_datalink.getNumber() != getNumber()) {
344: return false;
345: }
346:
347: return true;
348: }
349: }
350: }
|