1 package org.apache.jcs.engine;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Serializable;
23
24 import org.apache.jcs.engine.behavior.ICacheElementSerialized;
25 import org.apache.jcs.engine.behavior.IElementAttributes;
26
27 /*** Either serialized value or the value should be null; */
28 public class CacheElementSerialized
29 implements ICacheElementSerialized
30 {
31 /*** Don't change. */
32 private static final long serialVersionUID = -7265084818647601874L;
33
34 /*** The name of the cache region. This is a namespace. */
35 private final String cacheName;
36
37 /*** This is the cache key by which the value can be referenced. */
38 private final Serializable key;
39
40 /*** The serialized value. */
41 private final byte[] serializedValue;
42
43 /***
44 * These attributes hold information about the element and what it is allowed to do.
45 */
46 private IElementAttributes elementAttributes;
47
48 /***
49 * Constructs a usable wrapper.
50 * <p>
51 * @param cacheNameArg
52 * @param keyArg
53 * @param serializedValueArg
54 * @param elementAttributesArg
55 */
56 public CacheElementSerialized( String cacheNameArg, Serializable keyArg, byte[] serializedValueArg,
57 IElementAttributes elementAttributesArg )
58 {
59 this.cacheName = cacheNameArg;
60 this.key = keyArg;
61 this.serializedValue = serializedValueArg;
62 this.elementAttributes = elementAttributesArg;
63 }
64
65 /***
66 * Returns the name of the cache. This is the name of the region.
67 * <p>
68 * @return this.cacheName;
69 */
70 public String getCacheName()
71 {
72 return this.cacheName;
73 }
74
75 /*** @return Serializable */
76 public Serializable getKey()
77 {
78 return this.key;
79 }
80
81 /*** @return byte[] */
82 public byte[] getSerializedValue()
83 {
84 return this.serializedValue;
85 }
86
87 /*** @return IElementAttributes */
88 public IElementAttributes getElementAttributes()
89 {
90 return this.elementAttributes;
91 }
92
93 /***
94 * @param attr
95 */
96 public void setElementAttributes( IElementAttributes attr )
97 {
98 this.elementAttributes = attr;
99 }
100
101 /***
102 * Backward compatibility.
103 * <p>
104 * @return Serializable
105 */
106 public Serializable getVal()
107 {
108 return null;
109 }
110
111 /***
112 * For debugging only.
113 * <p>
114 * @return debugging string.
115 */
116 public String toString()
117 {
118 StringBuffer buf = new StringBuffer();
119 buf.append( "\n CacheElementSerialized: " );
120 buf.append( "\n CacheName = [" + getCacheName() + "]" );
121 buf.append( "\n Key = [" + getKey() + "]" );
122 buf.append( "\n SerializedValue = " + getSerializedValue() );
123 buf.append( "\n ElementAttributes = " + getElementAttributes() );
124 return buf.toString();
125 }
126
127 }