KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > om > profile > psml > PsmlPortlets


1 /*
2  * Copyright 2000-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.om.profile.psml;
18
19 // Java imports
20
import java.util.Vector JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 // Jetspeed imports
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 JavaDoc
40 {
41     private Controller controller = null;
42
43     private Security security = null;
44
45     private Vector JavaDoc portlets = new Vector JavaDoc();
46
47     private Vector JavaDoc entries = new Vector JavaDoc();
48
49     private Vector JavaDoc refs = new Vector JavaDoc();
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 JavaDoc getEntries()
80     {
81         return this.entries;
82     }
83
84     public void setEntries(Vector JavaDoc 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 JavaDoc getPortlets()
96     {
97         Vector JavaDoc v = new Vector JavaDoc();
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                 // Do not want to include portlets that where added via reference
104
continue;
105             }
106             v.add(p);
107         }
108         return v;
109     }
110
111     public void setPortlets(Vector JavaDoc portlets)
112     {
113         this.portlets = portlets;
114     }
115
116     public Vector JavaDoc 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 JavaDoc
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 JavaDoc obj = entries.elementAt(index);
157         entries.removeElementAt(index);
158         return (Entry) obj;
159     }
160
161     public Portlets removePortlets(int index)
162     {
163         Object JavaDoc 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 JavaDoc 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 JavaDoc
188     {
189         //-- check bounds for index
190
if ((index < 0) || (index > entries.size()))
191         {
192             throw new IndexOutOfBoundsException JavaDoc();
193         }
194         
195         return (Entry) entries.elementAt(index);
196     }
197
198     public Portlets getPortlets(int index)
199         throws java.lang.IndexOutOfBoundsException JavaDoc
200     {
201         //-- check bounds for index
202
if ((index < 0) || (index > portlets.size()))
203         {
204             throw new IndexOutOfBoundsException JavaDoc();
205         }
206         
207         return (Portlets) portlets.elementAt(index);
208     }
209
210     public Reference getReference(int index)
211         throws java.lang.IndexOutOfBoundsException JavaDoc
212     {
213         if ((index < 0) || (index > refs.size()))
214         {
215             throw new IndexOutOfBoundsException JavaDoc();
216         }
217         
218         return (Reference) refs.elementAt(index);
219     }
220
221     public Iterator JavaDoc getEntriesIterator()
222     {
223         return entries.iterator();
224     }
225
226     public Iterator JavaDoc getPortletsIterator()
227     {
228         return portlets.iterator();
229     }
230
231     public Iterator JavaDoc getReferenceIterator()
232     {
233         return refs.iterator();
234     }
235
236     public void addEntry(Entry entry)
237         throws java.lang.IndexOutOfBoundsException JavaDoc
238     {
239         entries.addElement(entry);
240     }
241
242     public void addPortlets(Portlets p)
243         throws java.lang.IndexOutOfBoundsException JavaDoc
244     {
245         portlets.addElement(p);
246         // STW make sure layout gets set
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 JavaDoc clone()
310         throws java.lang.CloneNotSupportedException JavaDoc
311     {
312         Object JavaDoc 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 JavaDoc(this.portlets.size());
320             Iterator JavaDoc 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 JavaDoc(this.entries.size());
330             Iterator JavaDoc 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 JavaDoc(this.refs.size());
340             Iterator JavaDoc 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     } // clone
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 // public Skin getSkin()
375
// {
376
// Skin useSkin = super.getSkin();
377
// if(useSkin == null && parentPortlets != null)
378
// {
379
// useSkin = parentPortlets.getSkin();
380
// }
381
//
382
// return useSkin;
383
// }
384

385 }
Popular Tags