KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > addressbook > person > group > tree > PersonTreeNode


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: PersonTreeNode.java,v $
31  * Revision 1.4 2005/04/29 02:48:13 colinmacleod
32  * Data bugfixes.
33  * Changed primary key back to Integer.
34  *
35  * Revision 1.3 2005/04/10 20:09:37 colinmacleod
36  * Added new themes.
37  * Changed id type to String.
38  * Changed i tag to em and b tag to strong.
39  * Improved PicoContainerFactory with NanoContainer scripts.
40  *
41  * Revision 1.2 2005/04/09 17:19:08 colinmacleod
42  * Changed copyright text to GPL v2 explicitly.
43  *
44  * Revision 1.1.1.1 2005/03/10 17:50:35 colinmacleod
45  * Restructured ivata op around Hibernate/PicoContainer.
46  * Renamed ivata groupware.
47  *
48  * Revision 1.5 2004/07/13 19:41:14 colinmacleod
49  * Moved project to POJOs from EJBs.
50  * Applied PicoContainer to services layer (replacing session EJBs).
51  * Applied Hibernate to persistence layer (replacing entity EJBs).
52  *
53  * Revision 1.4 2004/03/21 21:16:07 colinmacleod
54  * Shortened name to ivata op.
55  *
56  * Revision 1.3 2004/02/10 19:57:22 colinmacleod
57  * Changed email address.
58  *
59  * Revision 1.2 2004/02/01 22:00:32 colinmacleod
60  * Added full names to author tags
61  *
62  * Revision 1.1.1.1 2004/01/27 20:57:52 colinmacleod
63  * Moved ivata openportal to SourceForge..
64  *
65  * Revision 1.3 2003/10/17 12:36:12 jano
66  * fixing problems with building
67  * converting intranet -> portal
68  * Eclipse building
69  *
70  * Revision 1.2 2003/10/15 13:18:02 colin
71  * fixing for XDoclet
72  *
73  * Revision 1.1 2003/02/24 19:09:21 colin
74  * moved to business
75  *
76  * Revision 1.4 2003/02/04 17:43:45 colin
77  * copyright notice
78  *
79  * Revision 1.3 2002/09/17 08:38:56 colin
80  * added group tree right to make the tree faster
81  * -----------------------------------------------------------------------------
82  */

83 package com.ivata.groupware.business.addressbook.person.group.tree;
84
85
86 import java.io.IOException JavaDoc;
87 import java.io.ObjectInputStream JavaDoc;
88 import java.io.ObjectOutputStream JavaDoc;
89 import java.io.Serializable JavaDoc;
90
91 import com.ivata.groupware.business.addressbook.person.PersonDO;
92 import com.ivata.groupware.business.addressbook.person.group.GroupDO;
93 import com.ivata.groupware.web.tree.TreeNode;
94
95
96 /**
97  * <p>Stores one node of a tree which can either contain just groups or groups
98  * and people.</p>
99  *
100  * <p>If this is a node representing a group, the person element will be
101  * <code>null</code>, otherwise the group element will contain the main group
102  * details of the person represented by the node.</p>
103  *
104  * @since 2002-08-26
105  * @author Jan Boros <janboros@sourceforge.net>
106  * @version $Revision: 1.4 $
107  */

108 public class PersonTreeNode implements Serializable JavaDoc, TreeNode {
109
110     /**
111      * <p>Stores the group data for this node as a data object.</p>
112      */

113     private GroupDO group;
114
115     /**
116      * <p>Stores the person data for this node as a data object.</p>
117      */

118     private PersonDO person;
119
120     /**
121      * <p>Default contructor.</p>
122      */

123     public PersonTreeNode() {}
124     /**
125      * Create a person tree node which represents a group of people.
126      *
127      * @param group group of people this tree node represents.
128      */

129     public PersonTreeNode(GroupDO group) {
130         this.group = group;
131     }
132
133     /**
134      * Create a person tree node which represents a person.
135      *
136      * @param person person this tree node represents.
137      */

138     public PersonTreeNode(PersonDO person) {
139         this.person = person;
140     }
141
142     /**
143      * <p>Get the group data for this node as a data object. If this
144      * node represents a group, this gets the values of that group. Otherwise,
145      * this gets the values of the main group associated with the person this
146      * node represents.</p>
147      *
148      * @return the data of the group this node represents.
149      * In the case of the node representing a person, this method gets the
150      * details of that person's main group.
151      */

152     public final GroupDO getGroup() {
153         return group;
154     }
155
156     /**
157      * <p>Get the unique identifier for this tree node.</p>
158      *
159      * @return if the node represents a group, return the unique identifier for
160      * that group. Otherwise the <em>negative</em> value of the person's unique
161      * identifier is returned.
162      */

163     public final Integer JavaDoc getId() {
164         if (person == null) {
165             return group.getId();
166         }
167         return new Integer JavaDoc(0 - person.getId().intValue());
168     }
169     /**
170      * <p>The name of this tree node is either the value of the
171      * <code>fileAs<code> attribute of the person, or the <code>name</code>
172      * of the group depending which this tree node represents.</p>
173      *
174      * @return if this is a person, the <code>fileAs</code> value for that
175      * person, otherwise the <code>name</code> of the group.
176      */

177     public final String JavaDoc getName() {
178         return (person != null) ? person.getFileAs() : group.getName();
179     }
180
181     /**
182      * <p>Get the person data for this node as a data object.</p>
183      *
184      * @return values of the person this node represents, or
185      * <code>null</code> if this node represents a group.
186      */

187     public PersonDO getPerson() {
188         return person;
189     }
190
191     /**
192      * <p>Serialize the object from the input stream provided.</p>
193      *
194      * @param ois the input stream to serialize the object from
195      * @throws IOException thrown by <code>ObjectInputStream.defaultReadObject( )</code>.
196      * @throws ClassNotFoundException thrown by <code>ObjectInputStream.defaultReadObject( )</code>.
197      */

198     private void readObject(final ObjectInputStream JavaDoc ois) throws ClassNotFoundException JavaDoc, IOException JavaDoc {
199         ois.defaultReadObject();
200     }
201
202     /**
203      * <p>Serialize the object to the output stream provided.</p>
204      *
205      * @param oos the output stream to serialize the object to
206      * @throws IOException thrown by <code>ObjectOutputStream.defaultWriteObject( )</code>
207      */

208     private void writeObject(final ObjectOutputStream JavaDoc oos) throws IOException JavaDoc {
209         oos.defaultWriteObject();
210     }
211 }
212
Popular Tags