001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019:
020: package org.openharmonise.rm.publishing;
021:
022: import org.openharmonise.commons.cache.*;
023: import org.openharmonise.commons.dsi.*;
024: import org.openharmonise.rm.sessions.*;
025:
026: /**
027: * Cache class for <code>WebPageEngine</code> objects.
028: *
029: * @author Michael Bell
030: * @version $Revision: 1.2 $
031: *
032: */
033: public final class WebPageEngineCache extends AbstractCache {
034: private static WebPageEngineCache m_instance = null;
035: private static final String m_sClassname = "WebPageEngine";
036:
037: protected AbstractDataStoreInterface m_dbintrf = null;
038:
039: /**
040: * Constructs cache with an interface to the DB.
041: *
042: * @param dbinterf
043: * @throws CacheException
044: */
045: private WebPageEngineCache(AbstractDataStoreInterface dbinterf)
046: throws CacheException {
047: super (m_sClassname);
048:
049: m_dbintrf = dbinterf;
050: }
051:
052: /**
053: * Returns the singleton instance of this cache.
054: *
055: * @param dbinterf
056: * @return
057: * @throws CacheException
058: */
059: public synchronized static WebPageEngineCache getInstance(
060: AbstractDataStoreInterface dbinterf) throws CacheException {
061: if (m_instance == null) {
062: m_instance = new WebPageEngineCache(dbinterf);
063: }
064:
065: return m_instance;
066: }
067:
068: /**
069: * Return <code>WebPageEngine</code> associated with <code>object_id</code>.
070: *
071: * @param object_id
072: * @return
073: * @throws Exception
074: */
075: public WebPageEngine getWebPageEngine(String object_id)
076: throws CacheException {
077: final WebPageEngine cached_object = (WebPageEngine) this
078: .getObject(object_id);
079:
080: if (cached_object == null) {
081: throw new RuntimeException(
082: "Cached WebPageEngine was returned as null.");
083: }
084:
085: return cached_object;
086: }
087:
088: /* (non-Javadoc)
089: * @see org.openharmonise.commons.cache.AbstractCache#getCacheableObject(java.lang.Object)
090: */
091: protected Object getCacheableObject(Object object_id)
092: throws Exception {
093: if (object_id == null) {
094: throw new IllegalArgumentException(m_sClassname
095: + " id must be passed "
096: + " to GetCacheableObject object_id:" + object_id);
097: }
098:
099: Object object = new WebPageEngine(this .m_dbintrf,
100: (String) object_id);
101:
102: if (object == null) {
103: throw new RuntimeException(
104: "Could not get WebPageEngine for WebPageEngine:"
105: + object_id);
106: }
107:
108: return object;
109: }
110:
111: /* (non-Javadoc)
112: * @see org.openharmonise.commons.cache.AbstractCache#addToCache(java.lang.Object, java.lang.Object)
113: */
114: public void addToCache(Object key, Object cacheable_object) {
115: String sKey = Session.removeSessionIdPrefix((String) key);
116: super.addToCache(sKey, cacheable_object);
117: }
118: }
|