KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > searchindex > CmsHookList


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/searchindex/CmsHookList.java,v $
3  * Date : $Date: 2006/03/27 14:52:21 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.searchindex;
33
34 import java.util.Collection JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.LinkedList JavaDoc;
37
38 /**
39  * A list intended for sublclassing that triggers "listlet" operations that may
40  * access a on a "peer" object
41  * that is provided by a template method to implement in subclasses. <p>
42  *
43  * This is inteded to react on modifications on <code>{@link java.util.List}</code> instances
44  * performed by <code>{@link org.opencms.workplace.CmsWidgetDialogParameter}</code> instances
45  * linked to them. Using normal list implementations makes it impossible to intervene in those
46  * list modification by the widget technology.<p>
47  *
48  * "Listlet" operations are operations that are triggered upon modification of this
49  * list. They are called "on&lt;methodName(&gt;[e]d(&lt;peerObject&gt;, &lt;argList&gt;)"
50  * where &lt;methodName&gt; is the name of the original list operation that took place,
51  * "[e]d" stands for the past (operation took place), &lt;peerObject&gt; is the
52  * given class to perform reactions on (see constructors) and
53  * &lt;argList&gt; are the arguments of the orginal list method in that order. <p>
54  *
55  * Currently only the operations used by <code>{@link org.opencms.workplace.CmsWidgetDialog}</code>
56  * (see implementation of <code>{@link org.opencms.workplace.CmsWidgetDialog#actionToggleElement()}</code>)
57  * are supported and sufficient for this purpose. More general usability enforces extending
58  * the pattern shown here. <p>
59  *
60  * @author Achim Westermann
61  *
62  * @version $Revision: 1.2 $
63  *
64  * @since 6.0.0
65  */

66 public abstract class CmsHookList extends LinkedList JavaDoc {
67
68     /** The object operations are made upon. This design cries for 1.5 generics. **/
69     private Object JavaDoc m_peer;
70
71     /**
72      * Creates an empty list. <p>
73      *
74      * Subclasses should increase "safety by design" by narrowing the type of peer.<p>
75      *
76      * @param peer the object reactions on operations shall be made on in the "listlet" methods of subclasses
77      *
78      */

79     public CmsHookList(Object JavaDoc peer) {
80
81         super();
82         m_peer = peer;
83     }
84
85     /**
86      * Creates a list filled with all elements of the given argument. <p>
87      *
88      * Subclasses should increase "safety by design" by narrowing the type of peer.<p>
89      *
90      * @param peer the object reactions on operations shall be made on in the "listlet" methods of subclasses
91      *
92      * @param c a collection with all values for this list
93      */

94     public CmsHookList(Object JavaDoc peer, Collection JavaDoc c) {
95
96         super(c);
97         m_peer = peer;
98     }
99
100     /**
101      *
102      * @see java.util.List#add(int, java.lang.Object)
103      */

104     public void add(int index, Object JavaDoc element) {
105
106         super.add(index, element);
107         onAdded(m_peer, index, element);
108
109     }
110
111     /**
112      *
113      * @see java.util.Collection#add(java.lang.Object)
114      */

115     public boolean add(Object JavaDoc o) {
116
117         if (super.add(o)) {
118             this.onAdded(m_peer, o);
119             return true;
120         }
121         return false;
122     }
123
124     /**
125      *
126      * @see java.util.Collection#clear()
127      */

128     public void clear() {
129
130         onClear(m_peer);
131         super.clear();
132         onCleared(m_peer);
133     }
134
135     /**
136      *
137      * @see java.util.List#get(int)
138      */

139     public Object JavaDoc get(int index) {
140
141         Object JavaDoc ret = super.get(index);
142         onGetCall(m_peer, index);
143         return ret;
144     }
145
146     /**
147      *
148      * @see java.util.Collection#iterator()
149      */

150     public Iterator JavaDoc iterator() {
151
152         Iterator JavaDoc it = super.iterator();
153         onIteratorCall(m_peer);
154         return it;
155     }
156
157     /**
158      *
159      * @see java.util.List#remove(int)
160      */

161     public Object JavaDoc remove(int index) {
162
163         Object JavaDoc ret = null;
164         // get an IndexOutOfBoundsException just like list interfaces contract
165
ret = super.remove(index);
166         return ret;
167     }
168
169     /**
170      * React on the performed operation <code>{@link java.util.List#add(int, java.lang.Object)}</code>
171      * by informing argument peer. <p>
172      *
173      * @param peer the object reactions on operations shall be made on in this "listlet" method
174      * @param index the index the element was added at
175      * @param element the element that was added
176      */

177     protected abstract void onAdded(Object JavaDoc peer, int index, Object JavaDoc element);
178
179     /**
180      * React on the performed operation <code>{@link java.util.List#add(java.lang.Object)}</code>
181      * by informing argument peer. <p>
182      *
183      * @param peer the object reactions on operations shall be made on in this "listlet" method
184      * @param o the element that was successfully added
185      */

186     protected abstract void onAdded(Object JavaDoc peer, Object JavaDoc o);
187
188     /**
189      * React on the operation to come <code>{@link java.util.List#clear()}</code>
190      * by informing argument peer. <p>
191      *
192      * This is called before the actual clear operation takes place.<p>
193      *
194      * @param peer the object reactions on operations shall be made on in this "listlet" method
195      */

196     protected abstract void onClear(Object JavaDoc peer);
197
198     /**
199      * React on the performed operation <code>{@link java.util.List#clear()}</code>
200      * by informing argument peer. <p>
201      *
202      * This is called after the actual clear operation has taken place.<p>
203      *
204      * @param peer the object reactions on operations shall be made on in this "listlet" method
205      */

206     protected abstract void onCleared(Object JavaDoc peer);
207
208     /**
209      * React on the performed operation <code>{@link java.util.List#get(int)}</code>
210      * by informing argument peer. <p>
211      *
212      * Note that the call reult is only obtained in this instance but not given to the
213      * requesting client when this handler is invoked.<p>
214      *
215      * @param peer the object reactions on operations shall be made on in this "listlet" method
216      * @param index the index of the Object to get
217      */

218     protected abstract void onGetCall(Object JavaDoc peer, int index);
219
220     /**
221      * React on the performed operation <code>{@link java.util.List#iterator()}</code>
222      * by informing argument peer. <p>
223      *
224      * Note that the iterator is only obtained but not given to the requesting
225      * client when this handler is invoked.<p>
226      *
227      * @param peer the object reactions on operations shall be made on in this "listlet" method
228      */

229     protected abstract void onIteratorCall(Object JavaDoc peer);
230
231     /**
232      * React on the performed operation <code>{@link java.util.List#remove(int)}</code>
233      * by informing argument peer. <p>
234      *
235      * This is only invoked if the list operation was successful.<p>
236      *
237      * @param peer the object reactions on operations shall be made on in this "listlet" method
238      * @param index the index where the value has been removed
239      */

240     protected abstract void onRemoved(Object JavaDoc peer, int index);
241
242 }
243
Popular Tags