KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > pojos > PersistentObject


1
2 package org.roller.pojos;
3
4 import java.io.Serializable JavaDoc;
5
6 import org.apache.commons.lang.builder.EqualsBuilder;
7 import org.apache.commons.lang.builder.HashCodeBuilder;
8 import org.apache.commons.lang.builder.ToStringBuilder;
9 import org.apache.commons.lang.builder.ToStringStyle;
10 import org.roller.RollerException;
11 import org.roller.business.PersistenceStrategy;
12 import org.roller.model.RollerFactory;
13
14 /**
15  * Base class for all of Roller's persistent objects.
16  */

17 public abstract class PersistentObject implements Serializable JavaDoc
18 {
19     private long mTimeStamp = 0L; // this was only for Castor, right? -Lance
20

21     public PersistentObject()
22     {
23     }
24
25     /** Setter needed by RollerImpl.storePersistentObject() */
26     public abstract void setData( PersistentObject vo );
27
28     /** Get ID */
29     public abstract String JavaDoc getId();
30
31     /** Set ID */
32     public abstract void setId( String JavaDoc id );
33
34     //---------------------------------------------------------- TimeStampable
35

36
37     public void save() throws RollerException
38     {
39         PersistenceStrategy pstrategy =
40             RollerFactory.getRoller().getPersistenceStrategy();
41         pstrategy.store(this);
42     }
43     
44     public void remove() throws RollerException
45     {
46         PersistenceStrategy pstrategy =
47             RollerFactory.getRoller().getPersistenceStrategy();
48         pstrategy.remove(this);
49     }
50     
51     
52     public String JavaDoc toString()
53     {
54         try
55         {
56             // this may throw an exception if called by a thread that
57
return ToStringBuilder.reflectionToString(
58                 this, ToStringStyle.MULTI_LINE_STYLE);
59         }
60         catch (Throwable JavaDoc e)
61         {
62             // alternative toString() implementation used in case of exception
63
return getClass().getName() + ":" + getId();
64         }
65     }
66
67     public boolean equals(Object JavaDoc o) {
68         return EqualsBuilder.reflectionEquals(this, o);
69     }
70     
71     /** Can user associated with persistence session save this object? */
72     public boolean canSave() throws RollerException
73     {
74         return true;
75     }
76 }
77
78
Popular Tags