View Javadoc

1   package org.apache.jcs.engine;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 }