001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com> and
003: * JR Boyens <gnu-jrb[remove] at gmx dot net>
004: * Distributed under the terms of either:
005: * - the common development and distribution license (CDDL), v1.0; or
006: * - the GNU Lesser General Public License, v2.1 or later
007: * $Id: CallbacksBean.java 3634 2007-01-08 21:42:24Z gbevin $
008: */
009: package com.uwyn.rife.database.querymanagers.generic.beans;
010:
011: import com.uwyn.rife.database.querymanagers.generic.Callbacks;
012: import com.uwyn.rife.database.querymanagers.generic.beans.CallbacksBean;
013: import com.uwyn.rife.site.ConstrainedProperty;
014: import com.uwyn.rife.site.Validation;
015: import java.util.ArrayList;
016: import java.util.List;
017:
018: public class CallbacksBean extends Validation implements
019: Callbacks<CallbacksBean> {
020: private int mId = -1;
021: private String mTestString = null;
022:
023: static private List<String> sExecutedCallbacks = new ArrayList<String>();
024:
025: private boolean mBeforeValidateReturn = true;
026: private boolean mBeforeInsertReturn = true;
027: private static boolean sBeforeDeleteReturn = true;
028: private boolean mBeforeSaveReturn = true;
029: private boolean mBeforeUpdateReturn = true;
030: private boolean mAfterValidateReturn = true;
031: private boolean mAfterInsertReturn = true;
032: private static boolean sAfterDeleteReturn = true;
033: private boolean mAfterSaveReturn = true;
034: private boolean mAfterUpdateReturn = true;
035: private static boolean sAfterRestoreReturn = true;
036:
037: public CallbacksBean() {
038: }
039:
040: protected void activateValidation() {
041: addConstraint(new ConstrainedProperty("id").identifier(true)
042: .notNull(true));
043: addConstraint(new ConstrainedProperty("testString")
044: .notNull(true));
045: }
046:
047: public void setId(int id) {
048: mId = id;
049: }
050:
051: public int getId() {
052: return mId;
053: }
054:
055: public void setTestString(String testString) {
056: this .mTestString = testString;
057: }
058:
059: public String getTestString() {
060: return mTestString;
061: }
062:
063: public String toString() {
064: return mId + ";" + mTestString;
065: }
066:
067: public static List<String> getExecutedCallbacks() {
068: return sExecutedCallbacks;
069: }
070:
071: public static void clearExecuteCallbacks() {
072: sExecutedCallbacks = new ArrayList<String>();
073: }
074:
075: public void setBeforeValidateReturn(boolean beforeValidateReturn) {
076: mBeforeValidateReturn = beforeValidateReturn;
077: }
078:
079: public void setBeforeInsertReturn(boolean beforeInsertReturn) {
080: mBeforeInsertReturn = beforeInsertReturn;
081: }
082:
083: public static void setBeforeDeleteReturn(boolean beforeDeleteReturn) {
084: sBeforeDeleteReturn = beforeDeleteReturn;
085: }
086:
087: public void setBeforeSaveReturn(boolean beforeSaveReturn) {
088: mBeforeSaveReturn = beforeSaveReturn;
089: }
090:
091: public void setBeforeUpdateReturn(boolean beforeUpdateReturn) {
092: mBeforeUpdateReturn = beforeUpdateReturn;
093: }
094:
095: public void setAfterValidateReturn(boolean afterValidateReturn) {
096: mAfterValidateReturn = afterValidateReturn;
097: }
098:
099: public void setAfterInsertReturn(boolean afterInsertReturn) {
100: mAfterInsertReturn = afterInsertReturn;
101: }
102:
103: public static void setAfterDeleteReturn(boolean afterDeleteReturn) {
104: sAfterDeleteReturn = afterDeleteReturn;
105: }
106:
107: public void setAfterSaveReturn(boolean afterSaveReturn) {
108: mAfterSaveReturn = afterSaveReturn;
109: }
110:
111: public void setAfterUpdateReturn(boolean afterUpdateReturn) {
112: mAfterUpdateReturn = afterUpdateReturn;
113: }
114:
115: public static void setAfterRestoreReturn(boolean afterRestoreReturn) {
116: sAfterRestoreReturn = afterRestoreReturn;
117: }
118:
119: public boolean beforeValidate(CallbacksBean object) {
120: sExecutedCallbacks.add("beforeValidate " + object.toString());
121: return mBeforeValidateReturn;
122: }
123:
124: public boolean beforeInsert(CallbacksBean object) {
125: sExecutedCallbacks.add("beforeInsert " + object.toString());
126: return mBeforeInsertReturn;
127: }
128:
129: public boolean beforeDelete(int objectId) {
130: sExecutedCallbacks.add("beforeDelete " + objectId);
131: return sBeforeDeleteReturn;
132: }
133:
134: public boolean beforeSave(CallbacksBean object) {
135: sExecutedCallbacks.add("beforeSave " + object.toString());
136: return mBeforeSaveReturn;
137: }
138:
139: public boolean beforeUpdate(CallbacksBean object) {
140: sExecutedCallbacks.add("beforeUpdate " + object.toString());
141: return mBeforeUpdateReturn;
142: }
143:
144: public boolean afterValidate(CallbacksBean object) {
145: sExecutedCallbacks.add("afterValidate " + object.toString());
146: return mAfterValidateReturn;
147: }
148:
149: public boolean afterInsert(CallbacksBean object, boolean success) {
150: sExecutedCallbacks.add("afterInsert " + success + " "
151: + object.toString());
152: return mAfterInsertReturn;
153: }
154:
155: public boolean afterDelete(int objectId, boolean success) {
156: sExecutedCallbacks.add("afterDelete " + success + " "
157: + objectId);
158: return sAfterDeleteReturn;
159: }
160:
161: public boolean afterSave(CallbacksBean object, boolean success) {
162: sExecutedCallbacks.add("afterSave " + success + " "
163: + object.toString());
164: return mAfterSaveReturn;
165: }
166:
167: public boolean afterUpdate(CallbacksBean object, boolean success) {
168: sExecutedCallbacks.add("afterUpdate " + success + " "
169: + object.toString());
170: return mAfterUpdateReturn;
171: }
172:
173: public boolean afterRestore(CallbacksBean object) {
174: sExecutedCallbacks.add("afterRestore " + object.toString());
175: return sAfterRestoreReturn;
176: }
177: }
|