KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > pojo > Category


1 /*
2  * $Id: Category.java,v 1.2 2004/12/30 19:11:19 keyboardsamurai Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com
5  * Koeln / Duesseldorf , Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.pojo;
27
28 import java.io.Serializable JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.TreeSet JavaDoc;
32
33 import com.j2biz.blogunity.util.EntryComparator;
34
35 /**
36  * @hibernate.class table="CATEGORIES" dynamic-insert = "true"
37  * dynamic-update = "true"
38  *
39  * @author michelson
40  * @version $$
41  * @since 0.1
42  *
43  *
44  */

45 public class Category implements Serializable JavaDoc{
46
47     /**
48      * Comment for <code>serialVersionUID</code>
49      */

50     private static final long serialVersionUID = 3546084648699312176L;
51
52     public static final int GLOBAL = 0;
53
54     public static final int LOCAL = 1;
55
56     private Long JavaDoc id;
57
58     private String JavaDoc name;
59
60     private String JavaDoc description;
61
62     private int type = GLOBAL;
63
64     //private Blog blog;
65

66     private Set JavaDoc /* <Entry> */blogs = new TreeSet JavaDoc(
67             new EntryComparator());
68
69     private Set JavaDoc /* <Entry> */entries = new TreeSet JavaDoc(
70             new EntryComparator());
71
72     /**
73      *
74      */

75     public Category() {
76         super();
77     }
78
79     public Category(String JavaDoc name, int type) {
80         this.name = name;
81         this.type = type;
82     }
83
84     public Category(String JavaDoc name, String JavaDoc description, int type) {
85         this.name = name;
86         this.description = description;
87         this.type = type;
88     }
89
90     /**
91      * @hibernate.property name="description" column="DESCRIPTION"
92      * type="text" not-null="false" unique="false"
93      *
94      * @return Returns the description.
95      */

96     public String JavaDoc getDescription() {
97         return description;
98     }
99
100     /**
101      * @param description
102      * The description to set.
103      */

104     public void setDescription(String JavaDoc description) {
105         this.description = description;
106     }
107
108     /**
109      * @hibernate.set name="blogs"
110      * sort="com.j2biz.blogunity.util.BlogComparator"
111      * table="BLOG_CATEGORIES" inverse="true"
112      * lazy="true"
113      * @hibernate.collection-key column="CATEGORY_ID"
114      * @hibernate.collection-many-to-many class="com.j2biz.blogunity.pojo.Blog"
115      * column="BLOG_ID"
116      *
117      * @return Returns the entries.
118      */

119     public Set JavaDoc getBlogs() {
120         return blogs;
121     }
122
123     /**
124      * @param entries
125      * The entries to set.
126      */

127     public void setBlogs(Set JavaDoc blogs) {
128         this.blogs = blogs;
129     }
130
131     public void addBlog(Blog blog) {
132         blogs.add(blog);
133     }
134
135     /**
136      * @hibernate.set name="entries"
137      * sort="com.j2biz.blogunity.util.EntryComparator"
138      * table="ENTRY_CATEGORIES" inverse="true"
139      * lazy="true"
140      * @hibernate.collection-key column="CATEGORY_ID"
141      * @hibernate.collection-many-to-many class="com.j2biz.blogunity.pojo.Entry"
142      * column="ENTRY_ID"
143      *
144      * @return Returns the entries.
145      */

146     public Set JavaDoc getEntries() {
147         return entries;
148     }
149
150     /**
151      * @param entries
152      * The entries to set.
153      */

154     public void setEntries(Set JavaDoc entries) {
155         this.entries = entries;
156     }
157
158     public void addEntry(Entry entry) {
159         entries.add(entry);
160     }
161
162     /**
163      * @hibernate.id generator-class="increment" type="long"
164      * column="ID" unsaved-value="null"
165      *
166      * @return Returns the id.
167      */

168     public Long JavaDoc getId() {
169         return id;
170     }
171
172     /**
173      * @param id
174      * The id to set.
175      */

176     public void setId(Long JavaDoc id) {
177         this.id = id;
178     }
179
180     /**
181      *
182      * @hibernate.property name="getName" column="NAME" type="string"
183      * not-null="true" unique="false"
184      * @return Returns the name.
185      */

186     public String JavaDoc getName() {
187         return name;
188     }
189
190     /**
191      * @param name
192      * The name to set.
193      */

194     public void setName(String JavaDoc name) {
195         this.name = name;
196     }
197
198     /**
199      * @hibernate.property name="type" column="TYPE" type="integer"
200      * not-null="true" unique="false"
201      *
202      * @return Returns the type.
203      */

204     public int getType() {
205         return type;
206     }
207
208     /**
209      * @param type
210      * The type to set.
211      */

212     public void setType(int type) {
213         this.type = type;
214     }
215
216     public boolean containsBlog(Blog b) {
217
218         Iterator JavaDoc it = getBlogs().iterator();
219         while (it.hasNext()) {
220             Blog bl = (Blog) it.next();
221             if (bl.getId().longValue() == b.getId().longValue())
222                 return true;
223
224         }
225
226         return false;
227     }
228 }
Popular Tags