KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 1999-2004 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  * This is the cache key for one sitemap component.
21  * It consists of three parts:<br/>
22  * a.) The component type (generator, transformer etc.)<br/>
23  * b.) The component identifier - a unique handle for the sitemap
24  * component<br/>
25  * c.) The cache key - a key, generated by the component, which
26  * is unique inside the components space.
27  *
28  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
29  * @version CVS $Id: ComponentCacheKey.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public final class ComponentCacheKey
32     implements Serializable JavaDoc {
33
34     public static final int ComponentType_Generator = 1;
35     public static final int ComponentType_Transformer = 3;
36     public static final int ComponentType_Serializer = 5;
37     public static final int ComponentType_Reader = 7;
38
39     // Converts Generator / Transformer / Serializer / Reader constants above
40
// into string.
41
private static final String JavaDoc[] COMPONENTS = { "X", "G", "X", "T", "X", "S", "X", "R" };
42
43     /** The component type */
44     private final int type;
45     /** The component identifier */
46     private final String JavaDoc identifier;
47     /** The unique key */
48     private final Serializable JavaDoc key;
49     /** the hash code */
50     private final int hashCode;
51     /** cachePoint */
52     private final boolean cachePoint;
53
54     /**
55      * Constructor
56      */

57     public ComponentCacheKey(int componentType,
58                              String JavaDoc componentIdentifier,
59                              Serializable JavaDoc cacheKey) {
60         this(componentType, componentIdentifier, cacheKey, false);
61     }
62
63     /**
64      * alternate cachepoint Constructor
65      */

66     public ComponentCacheKey(int componentType,
67                              String JavaDoc componentIdentifier,
68                              Serializable JavaDoc cacheKey,
69                  boolean cachePoint) {
70         this.type = componentType;
71         this.identifier = componentIdentifier;
72         this.key = cacheKey;
73         /** cachePoint */
74         this.cachePoint = cachePoint;
75         this.hashCode = this.type +
76                 (this.identifier.length() << 3) +
77                 this.key.hashCode();
78     }
79
80     /**
81      * Compare
82      */

83     public boolean equals(Object JavaDoc object) {
84         if (object instanceof ComponentCacheKey) {
85             ComponentCacheKey ccp = (ComponentCacheKey)object;
86             if (this.type == ccp.type
87                 && this.identifier.equals(ccp.identifier)
88                 && this.key.equals(ccp.key)) {
89                 return true;
90             }
91         }
92         return false;
93     }
94
95     /**
96      * HashCode
97      */

98     public int hashCode() {
99         return this.hashCode;
100     }
101
102     private String JavaDoc toString;
103
104     /**
105      * toString
106      * The FilesystemStore uses toString!
107      */

108     public String JavaDoc toString() {
109         if (this.toString == null) {
110             toString = COMPONENTS[this.type] + '-' + this.identifier + '-' + this.key.toString();
111         }
112         return toString;
113     }
114
115     /**
116      * Check if we are a cachepoint
117      */

118     public boolean isCachePoint() {
119         return cachePoint;
120     }
121 }
122
Popular Tags