KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > pojos > PlanetGroupData


1 /*
2  * Copyright 2005 Sun Microsystems, Inc.
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 package org.roller.pojos;
17
18 import java.io.Serializable JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Set JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25 import java.util.TreeSet JavaDoc;
26
27
28 /**
29  * @struts.form include-all="true"
30  * @ejb:bean name="PlanetGroupData"
31  * @hibernate.class table="rag_group"
32  */

33 public class PlanetGroupData extends PersistentObject implements Serializable JavaDoc
34 {
35     transient private String JavaDoc[] catArray = null;
36
37     /** Database ID */
38     protected String JavaDoc id;
39     
40     /** Unique handle by which group may be fetched */
41     protected String JavaDoc handle;
42     
43     /** Title of this group */
44     protected String JavaDoc title;
45     
46     /** Description of this group */
47     protected String JavaDoc description;
48     
49     /** Restrict group by this list of comma separated category names */
50     protected String JavaDoc categoryRestriction;
51     
52     /** Max number of entries to show in HTML representation of this group */
53     protected int maxPageEntries = 45;
54     
55     /** Max number of entries to show in feed representation of this group */
56     protected int maxFeedEntries = 45;
57     
58     /** Subscriptions in this group */
59     protected List JavaDoc subscriptionAssocs = new ArrayList JavaDoc();
60
61     //------------------------------------------------------- persistent fields
62

63     /**
64      * @ejb:persistent-field
65      * @hibernate.id column="id" type="string"
66      * generator-class="uuid.hex" unsaved-value="null"
67      */

68     public String JavaDoc getId()
69     {
70         return id;
71     }
72     public void setId(String JavaDoc id)
73     {
74         this.id = id;
75     }
76     /**
77      * @hibernate.bag lazy="false" inverse="true" cascade="delete"
78      * @hibernate.collection-key column="group_id"
79      * @hibernate.collection-one-to-many
80      * class="org.roller.pojos.PlanetGroupSubscriptionAssoc"
81      */

82     public List JavaDoc getGroupSubscriptionAssocs()
83     {
84         return subscriptionAssocs;
85     }
86     public void setGroupSubscriptionAssocs(List JavaDoc subscriptionAssocs)
87     {
88         this.subscriptionAssocs = subscriptionAssocs;
89     }
90     /**
91      * @hibernate.property column="cat_restriction" non-null="false" unique="false"
92      */

93     public String JavaDoc getCategoryRestriction()
94     {
95         return categoryRestriction;
96     }
97     public void setCategoryRestriction(String JavaDoc categoryRestriction)
98     {
99         this.categoryRestriction = categoryRestriction;
100         catArray = null;
101     }
102     /**
103      * @hibernate.property column="description" non-null="false" unique="false"
104      */

105     public String JavaDoc getDescription()
106     {
107         return description;
108     }
109     public void setDescription(String JavaDoc description)
110     {
111         this.description = description;
112     }
113     /**
114      * @hibernate.property column="handle" non-null="false" unique="false"
115      */

116     public String JavaDoc getHandle()
117     {
118         return handle;
119     }
120     public void setHandle(String JavaDoc handle)
121     {
122         this.handle = handle;
123     }
124     /**
125      * @hibernate.property column="max_feed_entries" non-null="false" unique="false"
126      */

127     public int getMaxFeedEntries()
128     {
129         return maxFeedEntries;
130     }
131     public void setMaxFeedEntries(int maxFeedEntries)
132     {
133         this.maxFeedEntries = maxFeedEntries;
134     }
135     /**
136      * @hibernate.property column="max_page_entries" non-null="false" unique="false"
137      */

138     public int getMaxPageEntries()
139     {
140         return maxPageEntries;
141     }
142     public void setMaxPageEntries(int maxPageEntries)
143     {
144         this.maxPageEntries = maxPageEntries;
145     }
146     /**
147      * @hibernate.property column="title" non-null="false" unique="false"
148      */

149     public String JavaDoc getTitle()
150     {
151         return title;
152     }
153     public void setTitle(String JavaDoc title)
154     {
155         this.title = title;
156     }
157
158     //--------------------------------------------------------------- app logic
159

160     /**
161      * Returns true if entry is qualified for inclusion in this group.
162      */

163     public boolean qualified(PlanetEntryData entry)
164     {
165         String JavaDoc[] cats = getCategoryRestructionAsArray();
166         if (cats == null || cats.length == 0) return true;
167         for (int i=0; i<cats.length; i++)
168         {
169             if (entry.inCategory(cats[i])) return true;
170         }
171         return false;
172     }
173     
174     //------------------------------------------------------------- convenience
175

176     private String JavaDoc[] getCategoryRestructionAsArray()
177     {
178         if (catArray == null && categoryRestriction != null)
179         {
180             StringTokenizer JavaDoc toker = new StringTokenizer JavaDoc(categoryRestriction,",");
181             catArray = new String JavaDoc[toker.countTokens()];
182             int i = 0;
183     
184             while (toker.hasMoreTokens())
185             {
186                 catArray[i++] = toker.nextToken();
187             }
188         }
189         return catArray;
190     }
191     /** no-op to please XDoclet generated form */
192     private void setCategoryRestructionAsArray(String JavaDoc[] ignored)
193     {
194     }
195     
196     //---------------------------------------------------------- implementation
197

198     public void removeSubscription(PlanetSubscriptionData sub)
199     {
200         Set JavaDoc set = new TreeSet JavaDoc();
201         Iterator JavaDoc assocs = getGroupSubscriptionAssocs().iterator();
202         PlanetGroupSubscriptionAssoc target = null;
203         while (assocs.hasNext())
204         {
205             PlanetGroupSubscriptionAssoc assoc =
206                     (PlanetGroupSubscriptionAssoc)assocs.next();
207             if (assoc.getSubscription().getFeedUrl().equals(sub.getFeedUrl()))
208             {
209                 target = assoc;
210                 break;
211             }
212         }
213         subscriptionAssocs.remove(target);
214     }
215     public void addSubscription(PlanetSubscriptionData sub)
216     {
217         PlanetGroupSubscriptionAssoc assoc =
218                 new PlanetGroupSubscriptionAssoc();
219         assoc.setGroup(this);
220         assoc.setSubscription(sub);
221         subscriptionAssocs.add(assoc);
222     }
223     public void addSubscriptions(Collection JavaDoc subsList)
224     {
225         Iterator JavaDoc subs = subsList.iterator();
226         while (subs.hasNext())
227         {
228             PlanetSubscriptionData sub = (PlanetSubscriptionData)subs.next();
229             addSubscription(sub);
230         }
231     }
232     public Set JavaDoc getSubscriptions()
233     {
234         Set JavaDoc set = new TreeSet JavaDoc();
235         Iterator JavaDoc assocs = getGroupSubscriptionAssocs().iterator();
236         while (assocs.hasNext())
237         {
238             PlanetGroupSubscriptionAssoc assoc =
239                     (PlanetGroupSubscriptionAssoc)assocs.next();
240             set.add(assoc.getSubscription());
241         }
242         return set;
243     }
244     public void setData(PersistentObject vo)
245     {
246         // TODO Auto-generated method stub
247
}
248 }
249
Popular Tags