001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.jetspeed.cache.file;
019:
020: import java.io.File;
021: import java.util.Date;
022:
023: /**
024: * FileCache entry keeps the cached content along with last access information.
025: *
026: * @author David S. Taylor <a href="mailto:taylor@apache.org">David Sean Taylor</a>
027: * @version $Id: FileCacheEntryImpl.java 516448 2007-03-09 16:25:47Z ate $
028: */
029:
030: public class FileCacheEntryImpl implements FileCacheEntry {
031: protected File file;
032: protected Object document;
033:
034: protected long lastAccessed;
035: protected Date lastModified;
036:
037: private FileCacheEntryImpl() {
038: }
039:
040: /**
041: * Constructs a FileCacheEntry object
042: *
043: * @param document The user specific content being cached
044: * @param lastModified The document's last modified stamp
045: */
046: public FileCacheEntryImpl(File file, Object document) {
047: this .file = file;
048: this .document = document;
049: this .lastModified = new Date(file.lastModified());
050: this .lastAccessed = new Date().getTime();
051: }
052:
053: /**
054: * Get the file descriptor
055: *
056: * @return the file descriptor
057: */
058: public File getFile() {
059: return new File(this .file.getAbsolutePath());
060: }
061:
062: /**
063: * Set the file descriptor
064: *
065: * @param file the new file descriptor
066: */
067: public void setFile(File file) {
068: this .file = file;
069: }
070:
071: /**
072: * Set the cache's last accessed stamp
073: *
074: * @param lastAccessed the cache's last access stamp
075: */
076: public void setLastAccessed(long lastAccessed) {
077: this .lastAccessed = lastAccessed;
078: }
079:
080: /**
081: * Get the cache's lastAccessed stamp
082: *
083: * @return the cache's last accessed stamp
084: */
085: public long getLastAccessed() {
086: return this .lastAccessed;
087: }
088:
089: /**
090: * Set the cache's last modified stamp
091: *
092: * @param lastModified the cache's last modified stamp
093: */
094: public void setLastModified(Date lastModified) {
095: this .lastModified = lastModified;
096: }
097:
098: /**
099: * Get the entry's lastModified stamp (which may be stale compared to file's stamp)
100: *
101: * @return the last modified stamp
102: */
103: public Date getLastModified() {
104: return this .lastModified;
105: }
106:
107: /**
108: * Set the Document in the cache
109: *
110: * @param document the document being cached
111: */
112: public void setDocument(Object document) {
113: this .document = document;
114: }
115:
116: /**
117: * Get the Document
118: *
119: * @return the document being cached
120: */
121: public Object getDocument() {
122: return this.document;
123: }
124:
125: }
|