01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.transformation.helpers;
18:
19: import java.io.IOException;
20: import java.io.Serializable;
21:
22: import org.apache.avalon.framework.logger.Logger;
23: import org.apache.excalibur.store.Store;
24:
25: /**
26: * This is the interface between the {@link IncludeCacheManager} and the usual
27: * store.
28: *
29: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
30: * @version CVS $Id: StoreIncludeCacheStorageProxy.java 433543 2006-08-22 06:22:54Z crossley $
31: * @since 2.1
32: */
33: public final class StoreIncludeCacheStorageProxy implements
34: IncludeCacheStorageProxy {
35:
36: private Store store;
37:
38: private Logger logger;
39:
40: /**
41: * Constructor
42: * @param store The store for the cached content
43: * @param logger A logger for debugging
44: */
45: public StoreIncludeCacheStorageProxy(Store store, Logger logger) {
46: this .store = store;
47: this .logger = logger;
48: }
49:
50: /** A string representation for a key */
51: private String getKey(String uri) {
52: return "DCS:" + uri;
53: }
54:
55: /**
56: * @see IncludeCacheStorageProxy#get(java.lang.String)
57: */
58: public Serializable get(String uri) {
59: if (logger.isDebugEnabled()) {
60: logger.debug("StoreProxy: Getting content for " + uri);
61: }
62:
63: Serializable result = (Serializable) this .store.get(this
64: .getKey(uri));
65:
66: if (logger.isDebugEnabled()) {
67: logger.debug("StoreProxy: Result for " + uri + " : "
68: + (result == null ? "Not in cache" : "Found"));
69: }
70: return result;
71: }
72:
73: /**
74: * @see IncludeCacheStorageProxy#put(java.lang.String, java.io.Serializable)
75: */
76: public void put(String uri, Serializable object) throws IOException {
77: if (logger.isDebugEnabled()) {
78: logger.debug("StoreProxy: Storing content for " + uri);
79: }
80: this .store.store(this .getKey(uri), object);
81: }
82:
83: /**
84: * @see IncludeCacheStorageProxy#remove(java.lang.String)
85: */
86: public void remove(String uri) {
87: if (logger.isDebugEnabled()) {
88: logger.debug("StoreProxy: Removing content for " + uri);
89: }
90: this.store.remove(this.getKey(uri));
91: }
92: }
|