001: /*
002: * ====================================================================
003: * JAFFA - Java Application Framework For All
004: *
005: * Copyright (C) 2002 JAFFA Development Group
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Redistribution and use of this software and associated documentation ("Software"),
022: * with or without modification, are permitted provided that the following conditions are met:
023: * 1. Redistributions of source code must retain copyright statements and notices.
024: * Redistributions must also contain a copy of this document.
025: * 2. Redistributions in binary form must reproduce the above copyright notice,
026: * this list of conditions and the following disclaimer in the documentation
027: * and/or other materials provided with the distribution.
028: * 3. The name "JAFFA" must not be used to endorse or promote products derived from
029: * this Software without prior written permission. For written permission,
030: * please contact mail to: jaffagroup@yahoo.com.
031: * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
032: * appear in their names without prior written permission.
033: * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
034: *
035: * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: */
049:
050: package org.jaffa.components.maint;
051:
052: import org.jaffa.presentation.portlet.component.Component;
053: import java.util.Collection;
054: import java.util.HashSet;
055: import java.util.Iterator;
056: import java.util.EventObject;
057:
058: /** This is an abstract implementation of the IMaintComponent interface.
059: * All the Maintenance components should extend this component.
060: *
061: * @author GautamJ
062: * @deprecated This class is required by the object_maintenance_1_0 pattern. The object_maintenance_2_0 pattern has made this class redundant.
063: */
064: public abstract class MaintComponent extends Component implements
065: IMaintComponent {
066:
067: private int m_mode;
068: private Collection m_createListeners;
069: private Collection m_updateListeners;
070: private Collection m_deleteListeners;
071:
072: /** Getter for property mode.
073: * @return Value of property mode.
074: */
075: public int getMode() {
076: return m_mode;
077: }
078:
079: /** Setter for property mode.
080: * @param mode New value of property mode.
081: */
082: public void setMode(int mode) {
083: m_mode = mode;
084: }
085:
086: /** Returns true if this is create mode.
087: * @return true if this is create mode.
088: */
089: public boolean isCreateMode() {
090: return getMode() == MODE_CREATE;
091: }
092:
093: /** Returns true if this is update mode.
094: * @return true if this is update mode.
095: */
096: public boolean isUpdateMode() {
097: return getMode() == MODE_UPDATE;
098: }
099:
100: /** Returns true if this is delete mode.
101: * @return true if this is delete mode.
102: */
103: public boolean isDeleteMode() {
104: return getMode() == MODE_DELETE;
105: }
106:
107: /** Adds a listener.
108: * @param listener the listener.
109: */
110: public void addCreateListener(ICreateListener listener) {
111: if (m_createListeners == null)
112: m_createListeners = new HashSet();
113: m_createListeners.add(listener);
114: }
115:
116: /** Removes a listener.
117: * @param listener the listener.
118: * @return true if the listener was removed.
119: */
120: public boolean removeCreateListener(ICreateListener listener) {
121: if (m_createListeners != null)
122: return m_createListeners.remove(listener);
123: else
124: return false;
125: }
126:
127: /** Adds a listener.
128: * @param listener the listener.
129: */
130: public void addUpdateListener(IUpdateListener listener) {
131: if (m_updateListeners == null)
132: m_updateListeners = new HashSet();
133: m_updateListeners.add(listener);
134: }
135:
136: /** Removes a listener.
137: * @param listener the listener.
138: * @return true if the listener was removed.
139: */
140: public boolean removeUpdateListener(IUpdateListener listener) {
141: if (m_updateListeners != null)
142: return m_updateListeners.remove(listener);
143: else
144: return false;
145: }
146:
147: /** Adds a listener.
148: * @param listener the listener.
149: */
150: public void addDeleteListener(IDeleteListener listener) {
151: if (m_deleteListeners == null)
152: m_deleteListeners = new HashSet();
153: m_deleteListeners.add(listener);
154: }
155:
156: /** Removes a listener.
157: * @param listener the listener.
158: * @return true if the listener was removed.
159: */
160: public boolean removeDeleteListener(IDeleteListener listener) {
161: if (m_deleteListeners != null)
162: return m_deleteListeners.remove(listener);
163: else
164: return false;
165: }
166:
167: /** This clears the internal collection of listeners.
168: * It then invokes the quit() method of the base class.
169: */
170: public void quit() {
171: if (m_createListeners != null) {
172: m_createListeners.clear();
173: m_createListeners = null;
174: }
175: if (m_updateListeners != null) {
176: m_updateListeners.clear();
177: m_updateListeners = null;
178: }
179: if (m_deleteListeners != null) {
180: m_deleteListeners.clear();
181: m_deleteListeners = null;
182: }
183: super .quit();
184: }
185:
186: /** Returns a Collection of ICreateListener objects.
187: * @return a Collection of ICreateListener objects.
188: */
189: protected Collection getCreateListeners() {
190: return m_createListeners;
191: }
192:
193: /** Returns a Collection of IUpdateListener objects.
194: * @return a Collection of IUpdateListener objects.
195: */
196: protected Collection getUpdateListeners() {
197: return m_updateListeners;
198: }
199:
200: /** Returns a Collection of IDeleteListener objects.
201: * @return a Collection of IDeleteListener objects.
202: */
203: protected Collection getDeleteListeners() {
204: return m_deleteListeners;
205: }
206:
207: /** Invokes the createDone() method of the registered ICreateListener objects in the same thread.
208: */
209: protected void invokeCreateListeners() {
210: invokeCreateListeners(null);
211: }
212:
213: /** Invokes the createDone() method of the registered ICreateListener objects in the same thread.
214: * @param eventObject The EventObject which will probably contain the component itself.
215: */
216: protected void invokeCreateListeners(EventObject eventObject) {
217: if (m_createListeners != null) {
218: if (eventObject == null)
219: eventObject = new EventObject(this );
220:
221: for (Iterator i = m_createListeners.iterator(); i.hasNext();)
222: ((ICreateListener) i.next()).createDone(eventObject);
223: }
224: }
225:
226: /** Invokes the updateDone() method of the registered IUpdateListener objects in the same thread.
227: */
228: protected void invokeUpdateListeners() {
229: invokeUpdateListeners(null);
230: }
231:
232: /** Invokes the updateDone() method of the registered IUpdateListener objects in the same thread.
233: * @param eventObject The EventObject which will probably contain the component itself.
234: */
235: protected void invokeUpdateListeners(EventObject eventObject) {
236: if (m_updateListeners != null) {
237: if (eventObject == null)
238: eventObject = new EventObject(this );
239:
240: for (Iterator i = m_updateListeners.iterator(); i.hasNext();)
241: ((IUpdateListener) i.next()).updateDone(eventObject);
242: }
243: }
244:
245: /** Invokes the deleteDone() method of the registered IDeleteListener objects in the same thread.
246: */
247: protected void invokeDeleteListeners() {
248: invokeDeleteListeners(null);
249: }
250:
251: /** Invokes the deleteDone() method of the registered IDeleteListener objects in the same thread.
252: * @param eventObject The EventObject which will probably contain the component itself.
253: */
254: protected void invokeDeleteListeners(EventObject eventObject) {
255: if (m_deleteListeners != null) {
256: if (eventObject == null)
257: eventObject = new EventObject(this );
258:
259: for (Iterator i = m_deleteListeners.iterator(); i.hasNext();)
260: ((IDeleteListener) i.next()).deleteDone(eventObject);
261: }
262: }
263:
264: }
|