KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > pojos > BookmarkData


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * 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. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.pojos;
19
20 import org.apache.roller.RollerException;
21 import org.apache.roller.model.BookmarkManager;
22 import org.apache.roller.model.Roller;
23 import org.apache.roller.model.RollerFactory;
24
25 import java.io.Serializable JavaDoc;
26
27 /**
28  * <p>Represents a single URL in a user's favorite web-bookmarks collection.
29  * Don't construct one of these yourself, instead use the create method in
30  * the your BookmarkManager implementation.</p>
31  *
32  * @ejb:bean name="BookmarkData"
33  *
34  * @struts.form include-all="true"
35  * extends="org.apache.struts.validator.ValidatorForm"
36  *
37  * @hibernate.class lazy="false" table="bookmark"
38  * @hibernate.cache usage="read-write"
39  */

40 public class BookmarkData extends PersistentObject
41     implements Serializable JavaDoc, Comparable JavaDoc
42 {
43     static final long serialVersionUID = 2315131256728236003L;
44     
45     private FolderData folder;
46
47     private String JavaDoc id = null;
48     private String JavaDoc name;
49     private String JavaDoc description;
50     private String JavaDoc url;
51     private Integer JavaDoc weight;
52     private Integer JavaDoc priority;
53     private String JavaDoc image;
54     private String JavaDoc feedUrl;
55     
56     private BookmarkManager bookmarkManager = null;
57
58     //----------------------------------------------------------- Constructors
59

60     /** Default constructor, for use in form beans only. */
61     public BookmarkData()
62     {
63     }
64     
65     public BookmarkData(
66         FolderData parent,
67         String JavaDoc name,
68         String JavaDoc desc,
69         String JavaDoc url,
70         String JavaDoc feedUrl,
71         Integer JavaDoc weight,
72         Integer JavaDoc priority,
73         String JavaDoc image)
74     {
75         this.folder = parent;
76         this.name = name;
77         this.description = desc;
78         this.url = url;
79         this.feedUrl = feedUrl;
80         this.weight = weight;
81         this.priority = priority;
82         this.image = image;
83     }
84
85     /** For use by BookmarkManager implementations only. */
86     public BookmarkData(BookmarkManager bmgr)
87     {
88         bookmarkManager = bmgr;
89     }
90
91     //------------------------------------------------------------- Attributes
92

93     /**
94      * @roller.wrapPojoMethod type="simple"
95      *
96      * @ejb:persistent-field
97      *
98      * @hibernate.id column="id"
99      * generator-class="uuid.hex" unsaved-value="null"
100      */

101     public String JavaDoc getId()
102     {
103         return this.id;
104     }
105
106     /** @ejb:persistent-field */
107     public void setId(String JavaDoc id)
108     {
109         this.id = id;
110     }
111
112     /**
113      * Name of bookmark.
114      *
115      * @roller.wrapPojoMethod type="simple"
116      *
117      * @struts.validator type="required" msgkey="errors.required"
118      * @struts.validator-args arg0resource="bookmarkForm.name"
119      *
120      * @ejb:persistent-field
121      *
122      * @hibernate.property column="name" non-null="true" unique="false"
123      */

124     public String JavaDoc getName()
125     {
126         return this.name;
127     }
128
129     /** @ejb:persistent-field */
130     public void setName(String JavaDoc name)
131     {
132         this.name = name;
133     }
134
135     /**
136      * Description of bookmark.
137      *
138      * @roller.wrapPojoMethod type="simple"
139      *
140      * @ejb:persistent-field
141      *
142      * @hibernate.property column="description" non-null="true" unique="false"
143      */

144     public String JavaDoc getDescription()
145     {
146         return this.description;
147     }
148
149     /** @ejb:persistent-field */
150     public void setDescription(String JavaDoc description)
151     {
152         this.description = description;
153     }
154
155     /**
156      * URL of bookmark.
157      *
158      * @roller.wrapPojoMethod type="simple"
159      *
160      * @ejb:persistent-field
161      *
162      * @hibernate.property column="url" non-null="true" unique="false"
163      */

164     public String JavaDoc getUrl()
165     {
166         return this.url;
167     }
168
169     /** @ejb:persistent-field */
170     public void setUrl(String JavaDoc url)
171     {
172         this.url = url;
173     }
174
175     /**
176      * Weight indicates prominence of link
177      *
178      * @roller.wrapPojoMethod type="simple"
179      *
180      * @struts.validator type="required" msgkey="errors.required"
181      * @struts.validator type="integer" msgkey="errors.integer"
182      * @struts.validator-args arg0resource="bookmarkForm.weight"
183      *
184      * @ejb:persistent-field
185      *
186      * @hibernate.property column="weight" non-null="true" unique="false"
187      */

188     public java.lang.Integer JavaDoc getWeight()
189     {
190         return this.weight;
191     }
192
193     /** @ejb:persistent-field */
194     public void setWeight(java.lang.Integer JavaDoc weight)
195     {
196         this.weight = weight;
197     }
198
199     /**
200      * Priority determines order of display
201      *
202      * @roller.wrapPojoMethod type="simple"
203      *
204      * @struts.validator type="required" msgkey="errors.required"
205      * @struts.validator type="integer" msgkey="errors.integer"
206      * @struts.validator-args arg0resource="bookmarkForm.priority"
207      *
208      * @ejb:persistent-field
209      *
210      * @hibernate.property column="priority" non-null="true" unique="false"
211      */

212     public java.lang.Integer JavaDoc getPriority()
213     {
214         return this.priority;
215     }
216
217     /** @ejb:persistent-field */
218     public void setPriority(java.lang.Integer JavaDoc priority)
219     {
220         this.priority = priority;
221     }
222
223     /**
224      * @ejb:persistent-field
225      *
226      * @roller.wrapPojoMethod type="simple"
227      *
228      * @hibernate.property column="image" non-null="true" unique="false"
229      */

230     public String JavaDoc getImage()
231     {
232         return this.image;
233     }
234
235     /** @ejb:persistent-field */
236     public void setImage(String JavaDoc image)
237     {
238         this.image = image;
239     }
240
241     /**
242      * @ejb:persistent-field
243      *
244      * @roller.wrapPojoMethod type="simple"
245      *
246      * @hibernate.property column="feedurl" non-null="true" unique="false"
247      */

248     public String JavaDoc getFeedUrl()
249     {
250         return this.feedUrl;
251     }
252
253     /** @ejb:persistent-field */
254     public void setFeedUrl(String JavaDoc feedUrl)
255     {
256         this.feedUrl = feedUrl;
257     }
258
259     //---------------------------------------------------------- Relationships
260

261     /**
262      * @roller.wrapPojoMethod type="pojo"
263      * @ejb:persistent-field
264      * @hibernate.many-to-one column="folderid" cascade="none" not-null="true"
265      */

266     public org.apache.roller.pojos.FolderData getFolder()
267     {
268         return this.folder;
269     }
270
271     /** @ejb:persistent-field */
272     public void setFolder(org.apache.roller.pojos.FolderData folder)
273     {
274         this.folder = folder;
275     }
276
277     //------------------------------------------------------- Good citizenship
278

279     public String JavaDoc toString()
280     {
281         StringBuffer JavaDoc str = new StringBuffer JavaDoc("{");
282
283         str.append("id=" + id + " " + "name=" + name + " " + "description=" +
284                    description + " " + "url=" + url + " " + "weight=" +
285                    weight + " " + "priority=" + priority + " " + "folderId=" +
286                    "image=" + image + " " + "feedUrl=" +
287                    feedUrl);
288         str.append('}');
289
290         return (str.toString());
291     }
292
293     public boolean equals(Object JavaDoc pOther)
294     {
295         if (pOther instanceof BookmarkData)
296         {
297             BookmarkData lTest = (BookmarkData) pOther;
298             boolean lEquals = true;
299
300             if (this.id == null)
301             {
302                 lEquals = lEquals && (lTest.getId() == null);
303             }
304             else
305             {
306                 lEquals = lEquals && this.id.equals(lTest.getId());
307             }
308
309             if (this.name == null)
310             {
311                 lEquals = lEquals && (lTest.getName() == null);
312             }
313             else
314             {
315                 lEquals = lEquals && this.name.equals(lTest.getName());
316             }
317
318             if (this.description == null)
319             {
320                 lEquals = lEquals && (lTest.getDescription() == null);
321             }
322             else
323             {
324                 lEquals = lEquals &&
325                           this.description.equals(lTest.getDescription());
326             }
327
328             if (this.url == null)
329             {
330                 lEquals = lEquals && (lTest.getUrl() == null);
331             }
332             else
333             {
334                 lEquals = lEquals && this.url.equals(lTest.getUrl());
335             }
336
337             if (this.weight == null)
338             {
339                 lEquals = lEquals && (lTest.getWeight() == null);
340             }
341             else
342             {
343                 lEquals = lEquals && this.weight.equals(lTest.getWeight());
344             }
345
346             if (this.priority == null)
347             {
348                 lEquals = lEquals && (lTest.getPriority() == null);
349             }
350             else
351             {
352                 lEquals = lEquals && this.priority.equals(lTest.getPriority());
353             }
354
355 // if (this.mFolder == null)
356
// {
357
// lEquals = lEquals && (lTest.mFolder == null);
358
// }
359
// else
360
// {
361
// lEquals = lEquals && this.mFolder.equals(lTest.mFolder);
362
// }
363
//
364
if (this.image == null)
365             {
366                 lEquals = lEquals && (lTest.getImage() == null);
367             }
368             else
369             {
370                 lEquals = lEquals && this.image.equals(lTest.getImage());
371             }
372
373             if (this.feedUrl == null)
374             {
375                 lEquals = lEquals && (lTest.getFeedUrl() == null);
376             }
377             else
378             {
379                 lEquals = lEquals && this.feedUrl.equals(lTest.getFeedUrl());
380             }
381
382             return lEquals;
383         }
384         else
385         {
386             return false;
387         }
388     }
389
390     public int hashCode()
391     {
392         int result = 17;
393         result = (37 * result) +
394                  ((this.id != null) ? this.id.hashCode() : 0);
395         result = (37 * result) +
396                  ((this.name != null) ? this.name.hashCode() : 0);
397         result = (37 * result) +
398                  ((this.description != null) ? this.description.hashCode() : 0);
399         result = (37 * result) +
400                  ((this.url != null) ? this.url.hashCode() : 0);
401         result = (37 * result) +
402                  ((this.weight != null) ? this.weight.hashCode() : 0);
403         result = (37 * result) +
404                  ((this.priority != null) ? this.priority.hashCode() : 0);
405         result = (37 * result) +
406                  ((this.folder != null) ? this.folder.hashCode() : 0);
407         result = (37 * result) +
408                  ((this.image != null) ? this.image.hashCode() : 0);
409         result = (37 * result) +
410                  ((this.feedUrl != null) ? this.feedUrl.hashCode() : 0);
411
412         return result;
413     }
414
415     /**
416      * Setter is needed in RollerImpl.storePersistentObject()
417      */

418     public void setData(org.apache.roller.pojos.PersistentObject otherData)
419     {
420         BookmarkData other = (BookmarkData)otherData;
421         this.id = other.getId();
422         this.name = other.getName();
423         this.description = other.getDescription();
424         this.url = other.getUrl();
425         this.weight = other.getWeight();
426         this.priority = other.getPriority();
427         this.folder = other.getFolder();
428         this.image = other.getImage();
429         this.feedUrl = other.getUrl();
430     }
431
432     /**
433      * @see java.lang.Comparable#compareTo(java.lang.Object)
434      */

435     public int compareTo(Object JavaDoc o)
436     {
437         return bookmarkComparator.compare(this, o);
438     }
439     
440     private BookmarkComparator bookmarkComparator = new BookmarkComparator();
441
442     /**
443      * @param impl
444      */

445     public void setBookmarkManager(BookmarkManager bmgr)
446     {
447         bookmarkManager = bmgr;
448     }
449
450     public WebsiteData getWebsite()
451     {
452         return this.folder.getWebsite();
453     }
454
455 }
Popular Tags