001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.caching;
018:
019: import java.io.Serializable;
020:
021: /**
022: * This is the cache key for one sitemap component.
023: * It consists of three parts:<br/>
024: * a.) The component type (generator, transformer etc.)<br/>
025: * b.) The component identifier - a unique handle for the sitemap
026: * component<br/>
027: * c.) The cache key - a key, generated by the component, which
028: * is unique inside the components space.
029: *
030: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
031: * @version CVS $Id: ComponentCacheKey.java 433543 2006-08-22 06:22:54Z crossley $
032: */
033: public final class ComponentCacheKey implements Serializable {
034:
035: public static final int ComponentType_Generator = 1;
036: public static final int ComponentType_Transformer = 3;
037: public static final int ComponentType_Serializer = 5;
038: public static final int ComponentType_Reader = 7;
039:
040: // Converts Generator / Transformer / Serializer / Reader constants above
041: // into string.
042: private static final String[] COMPONENTS = { "X", "G", "X", "T",
043: "X", "S", "X", "R" };
044:
045: /** The component type */
046: private final int type;
047: /** The component identifier */
048: private final String identifier;
049: /** The unique key */
050: private final Serializable key;
051: /** the hash code */
052: private final int hashCode;
053: /** cachePoint */
054: private final boolean cachePoint;
055:
056: /**
057: * Constructor
058: */
059: public ComponentCacheKey(int componentType,
060: String componentIdentifier, Serializable cacheKey) {
061: this (componentType, componentIdentifier, cacheKey, false);
062: }
063:
064: /**
065: * alternate cachepoint Constructor
066: */
067: public ComponentCacheKey(int componentType,
068: String componentIdentifier, Serializable cacheKey,
069: boolean cachePoint) {
070: this .type = componentType;
071: this .identifier = componentIdentifier;
072: this .key = cacheKey;
073: /** cachePoint */
074: this .cachePoint = cachePoint;
075: this .hashCode = this .type + (this .identifier.length() << 3)
076: + this .key.hashCode();
077: }
078:
079: /**
080: * Compare
081: */
082: public boolean equals(Object object) {
083: if (object instanceof ComponentCacheKey) {
084: ComponentCacheKey ccp = (ComponentCacheKey) object;
085: if (this .type == ccp.type
086: && this .identifier.equals(ccp.identifier)
087: && this .key.equals(ccp.key)) {
088: return true;
089: }
090: }
091: return false;
092: }
093:
094: /**
095: * HashCode
096: */
097: public int hashCode() {
098: return this .hashCode;
099: }
100:
101: private String toString;
102:
103: /**
104: * toString
105: * The FilesystemStore uses toString!
106: */
107: public String toString() {
108: if (this .toString == null) {
109: toString = COMPONENTS[this .type] + '-' + this .identifier
110: + '-' + 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: }
|