KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > container > persistence > NamedDO


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: NamedDO.java,v $
31  * Revision 1.3 2005/04/10 20:10:04 colinmacleod
32  * Added new themes.
33  * Changed id type to String.
34  * Changed i tag to em and b tag to strong.
35  * Improved PicoContainerFactory with NanoContainer scripts.
36  *
37  * Revision 1.2 2005/04/09 17:19:58 colinmacleod
38  * Changed copyright text to GPL v2 explicitly.
39  *
40  * Revision 1.1.1.1 2005/03/10 17:51:32 colinmacleod
41  * Restructured ivata op around Hibernate/PicoContainer.
42  * Renamed ivata groupware.
43  *
44  * Revision 1.1 2004/09/30 15:16:00 colinmacleod
45  * Split off addressbook elements into security subproject.
46  *
47  * Revision 1.1 2004/07/13 19:41:15 colinmacleod
48  * Moved project to POJOs from EJBs.
49  * Applied PicoContainer to services layer (replacing session EJBs).
50  * Applied Hibernate to persistence layer (replacing entity EJBs).
51  * -----------------------------------------------------------------------------
52  */

53 package com.ivata.groupware.container.persistence;
54
55 /**
56  * <p>
57  * Any data object which has a unique name for display in lists or choices
58  * should extend this class.
59  * </p>
60  *
61  * @since 2004-06-06
62  * @author Colin MacLeod
63  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
64  * @version $Revision: 1.3 $
65  */

66 public abstract class NamedDO extends TimestampDO implements Comparable JavaDoc {
67
68     /**
69      * <p>Comparison method. See if the object supplied is a person data
70      * object and, if so, whether or not its contents are greater than, the same
71      * or less than this one.</p>
72      *
73      * <p>This method sorts by the name first then the id.</p>
74      *
75      * @param compare the object to compare with this one.
76      * @return a positive number if the object supplied in <code>compare</code>
77      * is greater than this one, <code>0</code> if they are the same,
78      * otherwise a negative number.
79      */

80     public int compareTo(final Object JavaDoc compare) {
81         // first check it is non-null and the class is right
82
if ((compare == null) ||
83             !(this.getClass().isInstance(compare))) {
84             return 1;
85         }
86         NamedDO namedDO = (NamedDO) compare;
87
88         // see if the ids are the same
89
if ((getId() != null)
90                 && (namedDO.getId() != null)) {
91             return getId().compareTo(namedDO.getId());
92         }
93
94         // watch for null names
95
String JavaDoc thisName = getName();
96         String JavaDoc otherName = namedDO.getName();
97         if (thisName == null) {
98             return otherName == null ? 0 : 1;
99         }
100
101         // otherwise, compare the names
102
return thisName.compareTo(otherName);
103     }
104
105     /**
106      * <p>Comparison method. See if the two objects are equivalent.</p>
107      *
108      * @param compare the object to compare with this one.
109      * @return <code>true</code> if the objects are the same.
110      */

111     public boolean equals(final Object JavaDoc compare) {
112         return compareTo(compare) == 0;
113     }
114     /**
115      * Just returns the name.
116      * Refer to {@link #getName}.
117      * @return Refer to {@link #getName}.
118      */

119     public String JavaDoc getDisplayValue() {
120         return getName();
121     }
122
123     /**
124      * <p>
125      * You must override this method to output the usual name for this data
126      * object.
127      * </p>
128      *
129      * @return name of this data object, used to clearly identifiy it if no id
130      * has been set yet.
131      */

132     public abstract String JavaDoc getName();
133
134     /**
135      * <p>
136      * Provide helpful debugging info about this data object.
137      * </p>
138      *
139      * @return clear text describing this object.
140      */

141     public String JavaDoc toString() {
142         return super.toString()
143             + " "
144             + getName();
145     }
146 }
147
Popular Tags