KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > transformation > helpers > StoreIncludeCacheStorageProxy


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.transformation.helpers;
17
18 import java.io.IOException JavaDoc;
19 import java.io.Serializable JavaDoc;
20
21 import org.apache.avalon.framework.logger.Logger;
22 import org.apache.excalibur.store.Store;
23
24 /**
25  * This is the interface between the {@link IncludeCacheManager} and the usual
26  * store.
27  *
28  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
29  * @version CVS $Id: StoreIncludeCacheStorageProxy.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  * @since 2.1
31  */

32 public final class StoreIncludeCacheStorageProxy
33     implements IncludeCacheStorageProxy {
34
35     private Store store;
36     
37     private Logger logger;
38     
39     /**
40      * Constructor
41      * @param store The store for the cached content
42      * @param logger A logger for debugging
43      */

44     public StoreIncludeCacheStorageProxy(Store store, Logger logger) {
45         this.store = store;
46         this.logger = logger;
47     }
48     
49     /** A string representation for a key */
50     private String JavaDoc getKey(String JavaDoc uri) {
51         return "DCS:" + uri;
52     }
53     
54     /**
55      * @see IncludeCacheStorageProxy#get(java.lang.String)
56      */

57     public Serializable JavaDoc get(String JavaDoc uri) {
58         if (logger.isDebugEnabled()) {
59             logger.debug("StoreProxy: Getting content for " + uri);
60         }
61
62         Serializable JavaDoc result = (Serializable JavaDoc)this.store.get(this.getKey(uri));
63
64         if (logger.isDebugEnabled()) {
65             logger.debug("StoreProxy: Result for " + uri + " : " + (result == null ? "Not in cache" : "Found"));
66         }
67         return result;
68     }
69
70     /**
71      * @see IncludeCacheStorageProxy#put(java.lang.String, java.io.Serializable)
72      */

73     public void put(String JavaDoc uri, Serializable JavaDoc object)
74     throws IOException JavaDoc {
75         if (logger.isDebugEnabled()) {
76             logger.debug("StoreProxy: Storing content for " + uri);
77         }
78         this.store.store(this.getKey(uri), object);
79     }
80
81     /**
82      * @see IncludeCacheStorageProxy#remove(java.lang.String)
83      */

84     public void remove(String JavaDoc uri) {
85         if (logger.isDebugEnabled()) {
86             logger.debug("StoreProxy: Removing content for " + uri);
87         }
88         this.store.remove(this.getKey(uri));
89     }
90 }
91
Popular Tags