KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > cache > CachedInfo


1 /* *****************************************************************************
2  * CachedInfo.java
3 * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.cache;
11
12 import org.apache.log4j.*;
13
14 import java.io.Serializable JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.net.MalformedURLException JavaDoc;
17
18 import org.openlaszlo.utils.ChainedException;
19
20 /**
21  * A class for representing the serializable bits of
22  * a cache item.
23  *
24  * @author <a HREF="mailto:bloch@laszlosystems.com">Eric Bloch</a>
25  */

26 public class CachedInfo implements Serializable JavaDoc {
27
28     /** Logger. */
29     private static Logger mLogger = Logger.getLogger(CachedInfo.class);
30
31     /** Size of the cached version of this item */
32     private long mSize = 0;
33
34     /** Name for this item */
35     private long mName = 0;
36
37     /** Key for this item */
38     private Serializable JavaDoc mKey = null;
39
40     /** Meta Data for this item */
41     private Serializable JavaDoc mMetaData = null;
42
43     /** True if item is in mem */
44     private boolean mInMemory = false;
45
46     /** Cached Last modified time of the remote version of this item
47      * (not the last modified time of the file in the cache) */

48     private long mLastModified = -1;
49
50     /** Encoding.
51      * Arguably, this could go in the meta-data. It's broken out here
52      * for historical reasons.
53      */

54     private String JavaDoc mEncoding = null;
55
56     /**
57      * Construct an CachedInfo based on this request
58      */

59     public CachedInfo(Serializable JavaDoc key, String JavaDoc encoding, boolean inMem, long name) {
60
61         mKey = key;
62         if (encoding != null) {
63             mEncoding = new String JavaDoc(encoding);
64         }
65         mName = name;
66         mInMemory = inMem;
67     }
68
69     /**
70      * @return true if the item is in in-mem cache
71      */

72     public boolean isInMemory() {
73         return mInMemory;
74     }
75
76     /**
77      * @return the name of this info
78      */

79     public long getName() {
80         return mName;
81     }
82
83     /**
84      * @return the size of this item in bytes
85      */

86     public long getSize() {
87         return mSize;
88     }
89
90     /**
91      * @return the size of this item's key
92      */

93     public long getKeySize() {
94         if (mKey instanceof String JavaDoc) {
95             return ((String JavaDoc)mKey).length() * 2;
96         } else {
97             return -1;
98         }
99     }
100
101     /**
102      * @return the last modified time of this item
103      */

104     public long getLastModified() {
105         return mLastModified;
106     }
107
108     /**
109      * @return the key for this item
110      */

111     public Serializable JavaDoc getKey() {
112         return mKey;
113     }
114
115     /**
116      * @return the encoding of this info
117      */

118     public String JavaDoc getEncoding() {
119         return mEncoding;
120     }
121
122     /**
123      * @return the meta data for this info
124      */

125     Serializable JavaDoc getMetaData() {
126         return mMetaData;
127     }
128
129
130     /**
131      * Set the in-memory state for this item
132      */

133     public void setInMemory(boolean inMem) {
134         mInMemory = inMem;
135     }
136
137     /**
138      * Set the cached size of this item in bytes
139      */

140     public void setLastModified(long lm) {
141         mLastModified = lm;
142     }
143
144     /**
145      * Set the meta data for this info
146      */

147     public void setMetaData(Serializable JavaDoc md) {
148         mMetaData = md;
149     }
150
151     /**
152      * Return the cached size of this item in bytes
153      */

154     public void setSize(long sz) {
155         mSize = sz;
156     }
157 }
158
Popular Tags