View Javadoc

1   /*
2    * Copyright 2000-2001,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.jetspeed.cache;
18  
19  import java.util.Date;
20  import java.io.File;
21  
22  /***
23   * FileCache entry keeps the cached content along with last access information.
24   *
25   *  @author David S. Taylor <a href="mailto:taylor@apache.org">David Sean Taylor</a>
26   *  @version $Id: FileCacheEntry.java,v 1.3 2004/02/23 02:46:05 jford Exp $
27   */
28  
29  public class FileCacheEntry
30  {
31      protected File file;
32      protected Object document;
33  
34      protected long lastAccessed;
35      protected Date lastModified;
36  
37      private FileCacheEntry()
38      {
39      }
40  
41      /***
42       * Constructs a FileCacheEntry object
43       *
44       * @param document The user specific content being cached
45       * @param lastModified The document's last modified stamp
46       */
47      public FileCacheEntry(File file, Object document)
48      {
49          this.file = file;
50          this.document = document;
51          this.lastModified = new Date(file.lastModified());
52          this.lastAccessed = new Date().getTime();
53      }
54  
55      /***
56       * Get the file descriptor
57       *
58       * @return the file descriptor
59       */
60      public File getFile()
61      {
62          return this.file;
63      }
64  
65      /***
66       * Set the file descriptor
67       *
68       * @param file the new file descriptor
69       */
70      public void setFile(File file)
71      {
72          this.file = file;
73      }
74  
75      /***
76       * Set the cache's last accessed stamp
77       *
78       * @param lastAccessed the cache's last access stamp
79       */
80      public void setLastAccessed(long lastAccessed)
81      {
82          this.lastAccessed = lastAccessed;
83      }
84  
85      /***
86       * Get the cache's lastAccessed stamp
87       *
88       * @return the cache's last accessed stamp
89       */
90      public long getLastAccessed()
91      {
92          return this.lastAccessed;
93      }
94  
95      /***
96       * Set the cache's last modified stamp
97       *
98       * @param lastModified the cache's last modified stamp
99       */
100     public void setLastModified(Date lastModified)
101     {
102         this.lastModified = lastModified;
103     }
104 
105     /***
106      * Get the entry's lastModified stamp (which may be stale compared to file's stamp)
107      *
108      * @return the last modified stamp
109      */
110     public Date getLastModified()
111     {
112         return this.lastModified;
113     }
114 
115     /***
116      * Set the Document in the cache
117      *
118      * @param document the document being cached
119      */
120     public void setDocument(Object document)
121     {
122         this.document = document;
123     }
124 
125     /***
126      * Get the Document
127      *
128      * @return the document being cached
129      */
130     public Object getDocument()
131     {
132         return this.document;
133     }
134 
135 }
136 
137