01: /*
02: * CoadunationLib: The coaduntion implementation library.
03: * Copyright (C) 2006 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: *
19: * ProxyCacheEntry.java
20: */
21:
22: // package path
23: package com.rift.coad.lib.bean;
24:
25: // java imports
26: import java.util.Date;
27:
28: // coadunation imports
29: import com.rift.coad.lib.cache.Cache;
30: import com.rift.coad.lib.cache.CacheEntry;
31:
32: /**
33: * This object is responsible for implementing the cache entry.
34: *
35: * @author Brett Chaldecott
36: */
37: public class ProxyCacheEntry implements CacheEntry {
38: // private member variables
39: private long timeout = -1;
40: private Object proxy = null;
41: private CacheEntry cacheEntry = null;
42:
43: /**
44: * The constructor of the proxy cache object.
45: *
46: * @param timeout The timeout for this proxy object.
47: * @param proxy The proxy interface for the object.
48: * @param cacheEntry The cache entry being handled.
49: */
50: public ProxyCacheEntry(long timeout, Object proxy,
51: CacheEntry cacheEntry) {
52: this .timeout = timeout;
53: this .proxy = proxy;
54: this .cacheEntry = cacheEntry;
55: }
56:
57: /**
58: * The touch method
59: */
60: public void touch() {
61: // do nothing
62: }
63:
64: /**
65: * This method will return true if the date is older than the given expiry
66: * date.
67: *
68: * @return TRUE if expired FALSE if not.
69: * @param expiryDate The expiry date to perform the check with.
70: */
71: public boolean isExpired(Date expiryDate) {
72: // check if this object should never be expired
73: if (timeout <= 0) {
74: return false;
75: }
76: Date calculatedExpiry = new Date(expiryDate.getTime() - timeout);
77: return cacheEntry.isExpired(calculatedExpiry);
78: }
79:
80: /**
81: * This method is called by the cache when an object is removed.
82: */
83: public void cacheRelease() {
84: cacheEntry.cacheRelease();
85: }
86:
87: /**
88: * This method returns the handler stored with
89: */
90: public CacheEntry getCacheEntry() {
91: return cacheEntry;
92: }
93: }
|