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