1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.profile.psml;
18
19
20 import java.util.Vector;
21 import java.util.Iterator;
22
23
24 import org.apache.jetspeed.om.SecurityReference;
25 import org.apache.jetspeed.om.profile.Controller;
26 import org.apache.jetspeed.om.profile.Entry;
27 import org.apache.jetspeed.om.profile.Layout;
28 import org.apache.jetspeed.om.profile.Portlets;
29 import org.apache.jetspeed.om.profile.Reference;
30 import org.apache.jetspeed.om.profile.Security;
31
32 /***
33 * Base simple bean-like implementation of the Portlets interface
34 * suitable for Castor XML serialization.
35 *
36 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
37 * @version $Id: PsmlPortlets.java,v 1.11 2004/02/23 03:02:54 jford Exp $
38 */
39 public class PsmlPortlets extends PsmlIdentityElement implements Portlets, java.io.Serializable
40 {
41 private Controller controller = null;
42
43 private Security security = null;
44
45 private Vector portlets = new Vector();
46
47 private Vector entries = new Vector();
48
49 private Vector refs = new Vector();
50
51 /*** Holds value of property securityRef. */
52 private SecurityReference securityRef = null;
53
54 private Portlets parentPortlets;
55
56 public PsmlPortlets()
57 { }
58
59 public Controller getController()
60 {
61 return this.controller;
62 }
63
64 public void setController(Controller controller)
65 {
66 this.controller = controller;
67 }
68
69 public void setSecurity(Security security)
70 {
71 this.security = security;
72 }
73
74 public Security getSecurity()
75 {
76 return this.security;
77 }
78
79 public Vector getEntries()
80 {
81 return this.entries;
82 }
83
84 public void setEntries(Vector entries)
85 {
86 this.entries = entries;
87 }
88
89 /***
90 * Return a list of portlet. Portlets that where added via a reference, see
91 * addReference(), are excluded.
92 *
93 * @return Vector of portlet
94 */
95 public Vector getPortlets()
96 {
97 Vector v = new Vector();
98 for (int ix = 0; ix < this.portlets.size(); ix++)
99 {
100 Portlets p = (Portlets) this.portlets.get(ix);
101 if (p instanceof Reference)
102 {
103
104 continue;
105 }
106 v.add(p);
107 }
108 return v;
109 }
110
111 public void setPortlets(Vector portlets)
112 {
113 this.portlets = portlets;
114 }
115
116 public Vector getReferences()
117 {
118 return this.refs;
119 }
120
121 public void addPortlets(PsmlPortlets p)
122 {
123 portlets.addElement(p);
124 }
125
126 public void addReference(PsmlReference ref)
127 {
128 this.refs.addElement(ref);
129 portlets.addElement(ref);
130 }
131
132 public void addReference(Reference ref)
133 throws java.lang.IndexOutOfBoundsException
134 {
135 this.refs.addElement(ref);
136 portlets.addElement(ref);
137 }
138
139 public int getEntryCount()
140 {
141 return this.entries.size();
142 }
143
144 public int getReferenceCount()
145 {
146 return this.refs.size();
147 }
148
149 public int getPortletsCount()
150 {
151 return this.portlets.size();
152 }
153
154 public Entry removeEntry(int index)
155 {
156 Object obj = entries.elementAt(index);
157 entries.removeElementAt(index);
158 return (Entry) obj;
159 }
160
161 public Portlets removePortlets(int index)
162 {
163 Object obj = portlets.elementAt(index);
164 if (null == obj)
165 {
166 return (Portlets) obj;
167 }
168
169 portlets.removeElementAt(index);
170 if (obj instanceof Reference)
171 {
172 refs.remove(obj);
173 }
174 return (Portlets) obj;
175 }
176
177 public Reference removeReference(int index)
178 {
179 Object obj = refs.elementAt(index);
180 refs.removeElementAt(index);
181 portlets.remove(obj);
182 return (Reference) obj;
183 }
184
185
186 public Entry getEntry(int index)
187 throws java.lang.IndexOutOfBoundsException
188 {
189
190 if ((index < 0) || (index > entries.size()))
191 {
192 throw new IndexOutOfBoundsException();
193 }
194
195 return (Entry) entries.elementAt(index);
196 }
197
198 public Portlets getPortlets(int index)
199 throws java.lang.IndexOutOfBoundsException
200 {
201
202 if ((index < 0) || (index > portlets.size()))
203 {
204 throw new IndexOutOfBoundsException();
205 }
206
207 return (Portlets) portlets.elementAt(index);
208 }
209
210 public Reference getReference(int index)
211 throws java.lang.IndexOutOfBoundsException
212 {
213 if ((index < 0) || (index > refs.size()))
214 {
215 throw new IndexOutOfBoundsException();
216 }
217
218 return (Reference) refs.elementAt(index);
219 }
220
221 public Iterator getEntriesIterator()
222 {
223 return entries.iterator();
224 }
225
226 public Iterator getPortletsIterator()
227 {
228 return portlets.iterator();
229 }
230
231 public Iterator getReferenceIterator()
232 {
233 return refs.iterator();
234 }
235
236 public void addEntry(Entry entry)
237 throws java.lang.IndexOutOfBoundsException
238 {
239 entries.addElement(entry);
240 }
241
242 public void addPortlets(Portlets p)
243 throws java.lang.IndexOutOfBoundsException
244 {
245 portlets.addElement(p);
246
247 int end = getEntryCount();
248 Layout layout = p.getLayout();
249 if(layout != null)
250 {
251 layout.setPosition(end);
252 layout.setSize(-1);
253 }
254 }
255
256
257 public Entry[] getEntriesArray()
258 {
259 int size = entries.size();
260 Entry[] mArray = new Entry[size];
261 for (int index = 0; index < size; index++)
262 {
263 mArray[index] = (Entry) entries.elementAt(index);
264 }
265 return mArray;
266 }
267
268 public Portlets[] getPortletsArray()
269 {
270 int size = portlets.size();
271 Portlets[] mArray = new Portlets[size];
272 for (int index = 0; index < size; index++)
273 {
274 mArray[index] = (Portlets) portlets.elementAt(index);
275 }
276 return mArray;
277 }
278
279 public Reference[] getReferenceArray()
280 {
281 int size = refs.size();
282 Reference[] mArray = new Reference[size];
283 for (int index = 0; index < size; index++)
284 {
285 mArray[index] = (Reference) refs.elementAt(index);
286 }
287 return mArray;
288 }
289
290 /*** Getter for property securityRef.
291 * @return Value of property securityRef.
292 */
293 public SecurityReference getSecurityRef()
294 {
295 return securityRef;
296 }
297
298 /*** Setter for property securityRef.
299 * @param securityRef New value of property securityRef.
300 */
301 public void setSecurityRef(SecurityReference securityRef)
302 {
303 this.securityRef = securityRef;
304 }
305
306 /***
307 * Create a clone of this object
308 */
309 public Object clone()
310 throws java.lang.CloneNotSupportedException
311 {
312 Object cloned = super.clone();
313
314 ((PsmlPortlets)cloned).controller = ((this.controller == null) ? null : (Controller) this.controller.clone());
315 ((PsmlPortlets)cloned).security = ((this.security == null) ? null : (Security) this.security.clone());
316
317 if (this.portlets != null)
318 {
319 ((PsmlPortlets)cloned).portlets = new Vector(this.portlets.size());
320 Iterator it = this.portlets.iterator();
321 while (it.hasNext())
322 {
323 ((PsmlPortlets)cloned).portlets.add(((Portlets)it.next()).clone());
324 }
325 }
326
327 if (this.entries != null)
328 {
329 ((PsmlPortlets)cloned).entries = new Vector(this.entries.size());
330 Iterator it = this.entries.iterator();
331 while (it.hasNext())
332 {
333 ((PsmlPortlets)cloned).entries.add(((Entry)it.next()).clone());
334 }
335 }
336
337 if (this.refs != null)
338 {
339 ((PsmlPortlets)cloned).refs = new Vector(this.refs.size());
340 Iterator it = this.refs.iterator();
341 while (it.hasNext())
342 {
343 ((PsmlPortlets)cloned).refs.add(((Reference)it.next()).clone());
344 }
345 }
346
347 ((PsmlPortlets)cloned).securityRef = ((this.securityRef == null) ? null : (SecurityReference) this.securityRef.clone());
348
349 return cloned;
350
351 }
352
353 /***
354 * Returns the parent.
355 * @return Portlets
356 */
357 public Portlets getParentPortlets()
358 {
359 return parentPortlets;
360 }
361
362 /***
363 * Sets the parent.
364 * @param parent The parent to set
365 */
366 public void setParentPortlets(Portlets parent)
367 {
368 this.parentPortlets = parent;
369 }
370
371 /***
372 * @see org.apache.jetspeed.om.profile.IdentityElement#getSkin()
373 */
374
375
376
377
378
379
380
381
382
383
384
385 }