KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > publishing > WebPageEngineCache


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19
20 package org.openharmonise.rm.publishing;
21
22 import org.openharmonise.commons.cache.*;
23 import org.openharmonise.commons.dsi.*;
24 import org.openharmonise.rm.sessions.*;
25
26
27 /**
28  * Cache class for <code>WebPageEngine</code> objects.
29  *
30  * @author Michael Bell
31  * @version $Revision: 1.2 $
32  *
33  */

34 public final class WebPageEngineCache extends AbstractCache {
35     private static WebPageEngineCache m_instance = null;
36     private static final String JavaDoc m_sClassname = "WebPageEngine";
37
38     protected AbstractDataStoreInterface m_dbintrf = null;
39
40     /**
41      * Constructs cache with an interface to the DB.
42      *
43      * @param dbinterf
44      * @throws CacheException
45      */

46     private WebPageEngineCache(AbstractDataStoreInterface dbinterf) throws CacheException {
47         super(m_sClassname);
48
49         m_dbintrf = dbinterf;
50     }
51
52     /**
53      * Returns the singleton instance of this cache.
54      *
55      * @param dbinterf
56      * @return
57      * @throws CacheException
58      */

59     public synchronized static WebPageEngineCache getInstance(AbstractDataStoreInterface dbinterf) throws CacheException {
60         if (m_instance == null) {
61             m_instance = new WebPageEngineCache(dbinterf);
62         }
63
64         return m_instance;
65     }
66
67     /**
68      * Return <code>WebPageEngine</code> associated with <code>object_id</code>.
69      *
70      * @param object_id
71      * @return
72      * @throws Exception
73      */

74     public WebPageEngine getWebPageEngine(String JavaDoc object_id) throws CacheException {
75         final WebPageEngine cached_object = (WebPageEngine) this.getObject(
76                                                     object_id);
77
78         if (cached_object == null) {
79             throw new RuntimeException JavaDoc(
80                     "Cached WebPageEngine was returned as null.");
81         }
82
83         return cached_object;
84     }
85
86   
87     /* (non-Javadoc)
88      * @see org.openharmonise.commons.cache.AbstractCache#getCacheableObject(java.lang.Object)
89      */

90     protected Object JavaDoc getCacheableObject(Object JavaDoc object_id)
91                                  throws Exception JavaDoc {
92         if (object_id == null) {
93             throw new IllegalArgumentException JavaDoc(m_sClassname +
94                                                " id must be passed " +
95                                                " to GetCacheableObject object_id:" +
96                                                object_id);
97         }
98
99         Object JavaDoc object = new WebPageEngine(this.m_dbintrf, (String JavaDoc) object_id);
100
101         if (object == null) {
102             throw new RuntimeException JavaDoc(
103                     "Could not get WebPageEngine for WebPageEngine:" +
104                     object_id);
105         }
106
107         return object;
108     }
109
110     /* (non-Javadoc)
111      * @see org.openharmonise.commons.cache.AbstractCache#addToCache(java.lang.Object, java.lang.Object)
112      */

113     public void addToCache(Object JavaDoc key, Object JavaDoc cacheable_object) {
114         String JavaDoc sKey = Session.removeSessionIdPrefix((String JavaDoc) key);
115         super.addToCache(sKey, cacheable_object);
116     }
117 }
Popular Tags