KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > impl > hibernate > ChannelGroup


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: ChannelGroup.java,v 1.9 2004/09/02 09:07:56 spyromus Exp $
28

29 package de.nava.informa.impl.hibernate;
30
31 import de.nava.informa.core.ChannelGroupIF;
32 import de.nava.informa.core.ChannelIF;
33
34 import java.util.ArrayList JavaDoc;
35 import java.util.Collection JavaDoc;
36 import java.util.HashSet JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.Set JavaDoc;
39
40 /**
41  * Hibernate implementation of the ChannelGroupIF interface.
42  *
43  * @author Niko Schmuck (niko@nava.de)
44  *
45  * @hibernate.class
46  * table="CHANNEL_GROUPS"
47  */

48 public class ChannelGroup implements ChannelGroupIF, java.io.Serializable JavaDoc {
49
50   private int id = -1;
51   private String JavaDoc title;
52   private ChannelGroupIF parent;
53
54   private Set JavaDoc channels;
55   private Collection JavaDoc children;
56
57   public ChannelGroup() {
58     this("Unnamed channel group");
59   }
60
61   public ChannelGroup(String JavaDoc title) {
62     this(null, title);
63   }
64
65   public ChannelGroup(ChannelGroupIF parent, String JavaDoc title) {
66     this.title = title;
67     this.channels = new HashSet JavaDoc();
68     this.parent = parent;
69     this.children = new ArrayList JavaDoc();
70   }
71
72   // --------------------------------------------------------------
73
// implementation of ChannelGroupIF interface
74
// --------------------------------------------------------------
75

76   /**
77    * @hibernate.id
78    * generator-class="native"
79    * column="CHANNEL_GROUP_ID"
80    * type="integer"
81    * unsaved-value="-1"
82    *
83    * @return integer representation of identity.
84    */

85   public int getIntId() {
86     return id;
87   }
88
89   public void setIntId(int anId) {
90     this.id = anId;
91   }
92
93   public long getId() {
94     return id;
95   }
96
97   public void setId(long longid) {
98     this.id = (int) longid;
99   }
100
101   /**
102    * @hibernate.property
103    * column="TITLE"
104    * not-null="true"
105    *
106    * @return title.
107    */

108   public String JavaDoc getTitle() {
109     return title;
110   }
111
112   public void setTitle(String JavaDoc aTitle) {
113     this.title = aTitle;
114   }
115
116   /**
117    * @hibernate.set
118    * table="CAT_GROUP_CHANNEL"
119    * lazy="true"
120    * cascade="all"
121    * @hibernate.collection-key
122    * column="GROUP_ID"
123    * @hibernate.collection-many-to-many
124    * class="de.nava.informa.impl.hibernate.Channel"
125    * column="CHANNEL_ID"
126    *
127    * @return channels.
128    */

129   public Set JavaDoc getChannels() {
130     return channels;
131   }
132
133   public void setChannels(Set JavaDoc aChannels) {
134     this.channels = aChannels;
135   }
136
137   public void add(ChannelIF channel) {
138     channels.add(channel);
139   }
140
141   public void remove(ChannelIF channel) {
142     channels.remove(channel);
143   }
144
145   public Collection JavaDoc getAll() {
146     return getChannels();
147   }
148
149   public ChannelIF getById(long channelId) {
150     Iterator JavaDoc it = getChannels().iterator();
151     while (it.hasNext()) {
152       ChannelIF channel = (ChannelIF) it.next();
153       if (channel.getId() == channelId) {
154         return channel;
155       }
156     }
157     return null;
158   }
159
160   /**
161    * @hibernate.many-to-one
162    * class="de.nava.informa.impl.hibernate.ChannelGroup"
163    * column="PARENT_ID"
164    *
165    * @return parent group.
166    */

167   public ChannelGroupIF getParent() {
168     return parent;
169   }
170
171   public void setParent(ChannelGroupIF group) {
172     this.parent = group;
173   }
174
175   /**
176    * @hibernate.bag
177    * lazy="true"
178    * order-by="CHANNEL_GROUP_ID"
179    * @hibernate.collection-key
180    * column="PARENT_ID"
181    * @hibernate.collection-one-to-many
182    * class="de.nava.informa.impl.hibernate.ChannelGroup"
183    *
184    * @return children.
185    */

186   public Collection JavaDoc getChildren() {
187     return children;
188   }
189
190   public void setChildren(Collection JavaDoc aChildren) {
191     this.children = aChildren;
192   }
193
194   public void addChild(ChannelGroupIF child) {
195     getChildren().add(child);
196     child.setParent(this);
197   }
198
199   public void removeChild(ChannelGroupIF child) {
200     getChildren().remove(child);
201   }
202
203   // ----------------------------------------------------------------------
204
// overwrite default method implementation from Object
205
// ----------------------------------------------------------------------
206

207   /**
208    * Returns a string representation of the object.
209    *
210    * @return a string representation of the object.
211    */

212   public String JavaDoc toString() {
213     return "[Hibernate ChannelGroup \"" + getTitle() + "\"(id=" + id + ")]";
214   }
215 }
216
Popular Tags