View Javadoc

1   package com.melloware.jukes.db.orm;
2   
3   import java.io.Serializable;
4   import java.util.Date;
5   
6   import com.jgoodies.binding.beans.Model;
7   import com.melloware.jukes.util.TimeSpan;
8   
9   /**
10   * Base class for all domain ORM objects.
11   * <p>
12   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
13   * @author Emil A. Lefkof III <info@melloware.com>
14   * @version 4.0
15   *
16   * @see com.jgoodies.binding.beans.Model
17   */
18  abstract public class AbstractJukesObject
19      extends Model
20      implements Serializable {
21  
22      private static final Date TODAY = new Date();
23  
24      /*
25       * These are used for lazy loading of tree nodes.
26       */
27      public static final int NO_CHILDREN = 0;
28      protected boolean newFile = false;
29      protected boolean valid = true;
30      protected int childCount = -1;
31      
32      /**
33       * All objects must implement a name function to describe this object.
34       * <p>
35       * @return the name of the object
36       */
37      abstract public String getName();
38      
39      /**
40       * All objects must implement a unique identifier.
41       * <p>
42       * @return the id of the object
43       */
44      abstract public Long getId();
45  
46      /**
47       * Method implemented in each ORM class. If it has some sort of child return
48       * the count else return 0. This is used for lazy loading the tree nodes.
49       * <p>
50       * @return the count of the children or 0 if no children
51       */
52      abstract public int getChildCount();
53      
54      /**
55       * Date will be used to determine new-ness.  
56       * <p>
57       * @return the audit date to determine new-ness
58       */
59      abstract public Date getAuditDate();
60  
61      /**
62       * Method implemented in each ORM class. This returns the audit modified 
63       * date.
64       * <p>
65       * @return the modification date
66       */
67      abstract public Date getModifiedDate();
68      
69      /**
70       * Method implemented in each ORM class. This returns the audit created 
71       * date.
72       * <p>
73       * @return the created date
74       */
75      abstract public Date getCreatedDate();
76  
77      /**
78       * Gets the valid flag.
79       * <p>
80       * @return Returns the valid flag.
81       */
82      abstract public boolean isValid();
83      
84      /**
85       * Gets the valid flag.
86       * <p>
87       * @return Returns the valid flag.
88       */
89      public boolean isNotValid() {
90          return !isValid();
91      }
92  
93      /**
94       * Sets the Child count.
95       * <p>
96       * @param count the count to set it to.
97       */
98      public void setChildCount(final int count) {
99          this.childCount = count;
100     }
101 
102     /**
103      * Sets the newFile.
104      * <p>
105      * @param aNewFile The newFile to set.
106      */
107     public void setNewFile(final boolean aNewFile) {
108         this.newFile = aNewFile;
109     }
110 
111     /**
112      * Sets the valid.
113      * <p>
114      * @param aValid The valid to set.
115      */
116     public void setValid(final boolean aValid) {
117         this.valid = aValid;
118     }
119 
120     /**
121      * Gets whether this file is considered new by checking the number of days
122      * against aDays.
123      * <p>
124      * @param aDays the number of days past a file is considered new
125      * @return Returns the newFile.
126      */
127     public boolean isNewFile(final int aDays) {
128         // subtract today from the modified date and check against the pref
129         final TimeSpan timespan = TimeSpan.subtract(TODAY, this.getAuditDate());
130         this.newFile = (timespan.getDays() < aDays);
131         return this.newFile;
132     }
133 
134 }