KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bsf > smartValueObject > Version


1 package org.bsf.smartValueObject;
2
3 /**
4  * Concrete default implementation of <tt>Versionable</tt>.
5  * <p>Versioning is done with timestamping.
6  */

7 public class Version implements Versionable {
8     private long timestamp;
9     private boolean dirty;
10     private boolean created;
11     private boolean deleted;
12     private final boolean debug = false;
13
14     /**
15      * Creates a clean version. Timestamp is set to current time.
16      */

17     public Version() {
18         markClean();
19         create(); // consider new objects as created
20
}
21
22     /**
23      * No specific purpose constructor, needed to satisfy a javassist requirement.
24      * @param o ignored
25      */

26     public Version(Object JavaDoc o) {
27         this();
28     }
29
30     public void touch() {
31         touch("unknown");
32     }
33
34     public void touch(String JavaDoc field) {
35         if (debug)
36         System.out.println("touched (" + field + ") @ " +
37                 this.timestamp);
38         dirty = true;
39     }
40
41     public void delete() {
42         deleted = true;
43         created = false;
44         dirty = true;
45     }
46
47     public void create() {
48         deleted = false;
49         created = true;
50         dirty = true;
51     }
52
53     public boolean isCreated() {
54         return created;
55     }
56
57     public boolean isDeleted() {
58         return deleted;
59     }
60
61     public boolean isDirty() {
62         return dirty;
63     }
64
65     public void markClean() {
66         deleted = dirty = created = false;
67         this.timestamp = System.currentTimeMillis();
68     }
69
70     /**
71      * Gets the version number.
72      */

73     public long getVersionId() {
74         return timestamp;
75     }
76
77     /**
78      * Sets the version number
79      */

80     public void setVersionId(long id) {
81         this.timestamp = id;
82     }
83
84     public String JavaDoc toString() {
85         return "Version [timestamp: " + this.timestamp +
86                 " dirty:" + (dirty ? "yes" : "no") +
87                 " created:" + (created ? "yes" : "no") +
88                 " deleted:" + (deleted ? "yes" : "no") +
89                 "]";
90     }
91 }
92
93
Popular Tags