KickJava   Java API By Example, From Geeks To Geeks.

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


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: BaseDO.java,v $
31  * Revision 1.4 2005/04/29 02:48:15 colinmacleod
32  * Data bugfixes.
33  * Changed primary key back to Integer.
34  *
35  * Revision 1.3 2005/04/10 20:09:42 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:37 colinmacleod
42  * Changed copyright text to GPL v2 explicitly.
43  *
44  * Revision 1.1 2005/03/10 19:23:03 colinmacleod
45  * Moved to ivata groupware.
46  *
47  * Revision 1.2 2004/11/12 15:57:10 colinmacleod
48  * Removed dependencies on SSLEXT.
49  * Moved Persistence classes to ivata masks.
50  *
51  * Revision 1.1 2004/07/13 19:42:44 colinmacleod
52  * Moved project to POJOs from EJBs.
53  * Applied PicoContainer to services layer (replacing session EJBs).
54  * Applied Hibernate to persistence layer (replacing entity EJBs).
55  * -----------------------------------------------------------------------------
56  */

57 package com.ivata.groupware.container.persistence;
58
59 import java.io.IOException JavaDoc;
60 import java.io.ObjectInputStream JavaDoc;
61 import java.io.ObjectOutputStream JavaDoc;
62 import java.io.Serializable JavaDoc;
63
64 import com.ivata.mask.util.StringHandling;
65 import com.ivata.mask.valueobject.ValueObject;
66
67 /**
68  * <p>
69  * This data object class is inherited by all others.
70  * </p>
71  *
72  * @author Colin MacLeod
73  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
74  * @since Mar 27, 2004
75  * @version $Revision: 1.4 $
76  */

77 public abstract class BaseDO implements Serializable JavaDoc, ValueObject {
78     /**
79      * <p>
80      * Unique identifier of this data object.
81      * </p>
82      */

83     private Integer JavaDoc id;
84
85     /**
86      * @see Object
87      */

88     public boolean equals(final Object JavaDoc compare) {
89         return hashCode() == compare.hashCode();
90     }
91
92     /**
93      * <p>
94      * This default implementation simply throws an exception.
95      * </p>
96      *
97      * @see com.ivata.mask.valueobject.ValueObject#getDisplayValue()
98      * @throws UnsupportedOperationException always, with a description of the
99      * subclass for which <code>getDisplayValue</code> was not overridden.
100      */

101     public String JavaDoc getDisplayValue() {
102         throw new UnsupportedOperationException JavaDoc(
103                 "ERROR: getDisplayValue not implemented for "
104                 + this.getClass());
105     }
106
107     /**
108      * <p>
109      * Override this method to return <code>getIdImpl</code> and set the
110      * sequence name for hibernate.
111      * </p>
112      *
113      * @hibernate.id
114      * generator-class = "native"
115      * @return current value of the unique identifier of this dependent value
116      * object.
117      */

118     public Integer JavaDoc getId() {
119         return id;
120     }
121
122     /**
123      * <p>
124      * Implementation for ivata masks interface <code>ValueObject</code>.
125      * </p>
126      *
127      * <p>
128      * Identifies this value object uniquely. This value may only be
129      * <code>null</code> for a new value object.
130      * </p>
131      *
132      * @return unique identifier for this value object.
133      */

134     public final String JavaDoc getIdString() {
135         return id == null ? null : id.toString();
136     }
137
138     /**
139      * @see Object
140      */

141     public int hashCode() {
142         String JavaDoc modifier = getClass().getName();
143         int result = 17;
144         if (getId() == null) {
145             result = 37 * result;
146         } else {
147             result = 37 * result + (int) getId().hashCode();
148         }
149         result = 37 * result + (int) modifier.hashCode();
150         return result;
151     }
152
153     /**
154      * <p>Serialize the object from the input stream provided.</p>
155      *
156      * @param ois the input stream to serialize the object from
157      * @throws IOException thrown by
158      * <code>ObjectInputStream.defaultReadObject()</code>.
159      * @throws ClassNotFoundException thrown by
160      * <code>ObjectInputStream.defaultReadObject()</code>.
161      */

162     private void readObject(final ObjectInputStream JavaDoc ois)
163             throws ClassNotFoundException JavaDoc, IOException JavaDoc {
164         ois.defaultReadObject();
165     }
166
167     /**
168      * <p>
169      * Unique identifier of this data object.
170      * </p>
171      * @param id current value of the unique identifier of this dependent value
172      * object.
173      */

174     public final void setId(final Integer JavaDoc id) {
175         this.id = id;
176     }
177     /**
178      * Set the value as a string. The string must represent a number or a
179      * <code>RuntimeException</code> will be thrown.
180      *
181      * @param idString string representing the id of this object.
182      */

183     public final void setIdString(final String JavaDoc idString) {
184         id = StringHandling.integerValue(idString);
185     }
186
187
188     /**
189      * <p>
190      * Provide helpful debugging info about this data object.
191      * </p>
192      *
193      * @return clear text describing this object.
194      */

195     public String JavaDoc toString() {
196         String JavaDoc className = getClass().getName();
197         // don't output package - just the class name
198
if (className.lastIndexOf('.') >= 0) {
199             className = className.substring(className.lastIndexOf('.') + 1);
200         }
201         return className
202             + "(id "
203             + getId()
204             + ")";
205     }
206
207     /**
208      * <p>Serialize the object to the output stream provided.</p>
209      *
210      * @param oos the output stream to serialize the object to
211      * @throws IOException thrown by <code>ObjectOutputStream.defaultWriteObject( )</code>
212      */

213     private void writeObject(final ObjectOutputStream JavaDoc oos) throws IOException JavaDoc {
214         oos.defaultWriteObject();
215     }
216 }
217
Popular Tags