001: //
002: // Informa -- RSS Library for Java
003: // Copyright (c) 2002 by Niko Schmuck
004: //
005: // Niko Schmuck
006: // http://sourceforge.net/projects/informa
007: // mailto:niko_schmuck@users.sourceforge.net
008: //
009: // This library is free software.
010: //
011: // You may redistribute it and/or modify it under the terms of the GNU
012: // Lesser General Public License as published by the Free Software Foundation.
013: //
014: // Version 2.1 of the license should be included with this distribution in
015: // the file LICENSE. If the license is not included with this distribution,
016: // you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
017: // or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
018: // MA 02139 USA.
019: //
020: // This library is distributed in the hope that it will be useful,
021: // but WITHOUT ANY WARRANTY; without even the implied waranty of
022: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
023: // Lesser General Public License for more details.
024: //
025:
026: // $Id: ChannelGroup.java,v 1.12 2006/12/04 23:43:27 italobb Exp $
027:
028: package de.nava.informa.impl.hibernate;
029:
030: import de.nava.informa.core.ChannelGroupIF;
031: import de.nava.informa.core.ChannelIF;
032:
033: import java.util.ArrayList;
034: import java.util.Collection;
035: import java.util.Collections;
036: import java.util.HashSet;
037: import java.util.Iterator;
038: import java.util.Set;
039:
040: /**
041: * Hibernate implementation of the ChannelGroupIF interface.
042: *
043: * @author Niko Schmuck (niko@nava.de)
044: */
045: public class ChannelGroup implements ChannelGroupIF {
046:
047: private static final long serialVersionUID = -4572648595088013842L;
048:
049: private long id = -1;
050: private String title;
051: private ChannelGroupIF parent;
052:
053: private Set<ChannelIF> channels;
054: private Collection<ChannelGroupIF> children;
055:
056: public ChannelGroup() {
057: this ("Unnamed channel group");
058: }
059:
060: public ChannelGroup(String title) {
061: this (null, title);
062: }
063:
064: public ChannelGroup(ChannelGroupIF parent, String title) {
065: this .title = title;
066: this .channels = Collections
067: .synchronizedSet(new HashSet<ChannelIF>());
068: this .parent = parent;
069: this .children = new ArrayList<ChannelGroupIF>();
070: }
071:
072: // --------------------------------------------------------------
073: // implementation of ChannelGroupIF interface
074: // --------------------------------------------------------------
075:
076: /**
077: * @return integer representation of identity.
078: */
079: public long getId() {
080: return id;
081: }
082:
083: public void setId(long id) {
084: this .id = id;
085: }
086:
087: /**
088: * @return title.
089: */
090: public String getTitle() {
091: return title;
092: }
093:
094: public void setTitle(String aTitle) {
095: this .title = aTitle;
096: }
097:
098: /**
099: * @return channels.
100: */
101: public Set<ChannelIF> getChannels() {
102: return channels;
103: }
104:
105: public void setChannels(Set<ChannelIF> aChannels) {
106: this .channels = Collections.synchronizedSet(aChannels);
107: }
108:
109: public void add(ChannelIF channel) {
110: channels.add(channel);
111: }
112:
113: public void remove(ChannelIF channel) {
114: channels.remove(channel);
115: }
116:
117: public Collection<ChannelIF> getAll() {
118: return getChannels();
119: }
120:
121: public ChannelIF getById(long channelId) {
122: Iterator it = getChannels().iterator();
123: while (it.hasNext()) {
124: ChannelIF channel = (ChannelIF) it.next();
125: if (channel.getId() == channelId) {
126: return channel;
127: }
128: }
129: return null;
130: }
131:
132: /**
133: * @return parent group.
134: */
135: public ChannelGroupIF getParent() {
136: return parent;
137: }
138:
139: public void setParent(ChannelGroupIF group) {
140: this .parent = group;
141: }
142:
143: /**
144: * @return children.
145: */
146: public Collection<ChannelGroupIF> getChildren() {
147: return children;
148: }
149:
150: public void setChildren(Collection<ChannelGroupIF> aChildren) {
151: this .children = aChildren;
152: }
153:
154: public void addChild(ChannelGroupIF child) {
155: getChildren().add(child);
156: child.setParent(this );
157: }
158:
159: public void removeChild(ChannelGroupIF child) {
160: getChildren().remove(child);
161: }
162:
163: // ----------------------------------------------------------------------
164: // overwrite default method implementation from Object
165: // ----------------------------------------------------------------------
166:
167: /**
168: * Returns a string representation of the object.
169: *
170: * @return a string representation of the object.
171: */
172: public String toString() {
173: return "[Hibernate ChannelGroup \"" + getTitle() + "\"(id="
174: + id + ")]";
175: }
176:
177: }
|