KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > caching > IdentifierCacheKey


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.caching;
17
18 import java.io.Serializable JavaDoc;
19
20 /**
21  * This is a "simple" cache key that does not consider the components used in the
22  * pipeline. It simply consists of a key (unique identifier for the request) and
23  * a boolean value that defines if the key is for a complete pipeline call or
24  * for an internal pipeline call.
25  *
26  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
27  * @version CVS $Id: IdentifierCacheKey.java 189614 2005-06-08 18:07:32Z cziegeler $
28  * @since 2.1.1
29  */

30 public class IdentifierCacheKey
31     implements Serializable JavaDoc {
32
33     /** The key */
34     final protected String JavaDoc key;
35
36     /** Is this an external pipeline call? */
37     final protected boolean external;
38
39     /** cache key */
40     final protected String JavaDoc cacheKey;
41     
42     /** cache toString() */
43     protected String JavaDoc toString;
44     
45     /**
46      * Constructor
47      */

48     public IdentifierCacheKey(String JavaDoc key, boolean external) {
49         this.key = key;
50         this.external = external;
51         final StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
52         buf.append(this.external).append(':').append(this.key);
53         this.cacheKey = buf.toString();
54     }
55
56     /**
57      * Compare
58      */

59     public boolean equals(Object JavaDoc object) {
60         if (object instanceof IdentifierCacheKey) {
61             IdentifierCacheKey pck = (IdentifierCacheKey)object;
62             return this.cacheKey.equals( pck.cacheKey );
63         }
64         return false;
65     }
66
67     /**
68      * Generate a hash code
69      */

70     public int hashCode() {
71         return this.cacheKey.hashCode();
72     }
73
74     /**
75      * toString
76      * The FilesystemStore uses toString!
77      */

78     public String JavaDoc toString() {
79         if (this.toString == null) {
80             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
81             buffer.append("IK:");
82             buffer.append(this.cacheKey);
83             this.toString = buffer.toString();
84         }
85         return toString;
86     }
87     
88     /**
89      * The cache key
90      */

91     public String JavaDoc getKey() {
92         return this.key;
93     }
94 }
95
Popular Tags