001: /* *****************************************************************************
002: * CachedInfo.java
003: * ****************************************************************************/
004:
005: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006: * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
007: * Use is subject to license terms. *
008: * J_LZ_COPYRIGHT_END *********************************************************/
009:
010: package org.openlaszlo.cache;
011:
012: import org.apache.log4j.*;
013:
014: import java.io.Serializable;
015: import java.net.URL;
016: import java.net.MalformedURLException;
017:
018: import org.openlaszlo.utils.ChainedException;
019:
020: /**
021: * A class for representing the serializable bits of
022: * a cache item.
023: *
024: * @author <a href="mailto:bloch@laszlosystems.com">Eric Bloch</a>
025: */
026: public class CachedInfo implements Serializable {
027:
028: /** Logger. */
029: private static Logger mLogger = Logger.getLogger(CachedInfo.class);
030:
031: /** Size of the cached version of this item */
032: private long mSize = 0;
033:
034: /** Name for this item */
035: private long mName = 0;
036:
037: /** Key for this item */
038: private Serializable mKey = null;
039:
040: /** Meta Data for this item */
041: private Serializable mMetaData = null;
042:
043: /** True if item is in mem */
044: private boolean mInMemory = false;
045:
046: /** Cached Last modified time of the remote version of this item
047: * (not the last modified time of the file in the cache) */
048: private long mLastModified = -1;
049:
050: /** Encoding.
051: * Arguably, this could go in the meta-data. It's broken out here
052: * for historical reasons.
053: */
054: private String mEncoding = null;
055:
056: /**
057: * Construct an CachedInfo based on this request
058: */
059: public CachedInfo(Serializable key, String encoding, boolean inMem,
060: long name) {
061:
062: mKey = key;
063: if (encoding != null) {
064: mEncoding = new String(encoding);
065: }
066: mName = name;
067: mInMemory = inMem;
068: }
069:
070: /**
071: * @return true if the item is in in-mem cache
072: */
073: public boolean isInMemory() {
074: return mInMemory;
075: }
076:
077: /**
078: * @return the name of this info
079: */
080: public long getName() {
081: return mName;
082: }
083:
084: /**
085: * @return the size of this item in bytes
086: */
087: public long getSize() {
088: return mSize;
089: }
090:
091: /**
092: * @return the size of this item's key
093: */
094: public long getKeySize() {
095: if (mKey instanceof String) {
096: return ((String) mKey).length() * 2;
097: } else {
098: return -1;
099: }
100: }
101:
102: /**
103: * @return the last modified time of this item
104: */
105: public long getLastModified() {
106: return mLastModified;
107: }
108:
109: /**
110: * @return the key for this item
111: */
112: public Serializable getKey() {
113: return mKey;
114: }
115:
116: /**
117: * @return the encoding of this info
118: */
119: public String getEncoding() {
120: return mEncoding;
121: }
122:
123: /**
124: * @return the meta data for this info
125: */
126: Serializable getMetaData() {
127: return mMetaData;
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 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: }
|