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.search;
021:
022: import java.util.logging.*;
023: import java.util.logging.Level;
024:
025: import org.openharmonise.commons.cache.*;
026: import org.openharmonise.commons.dsi.*;
027:
028: /**
029: * This class provides caching functionality for <code>CachedResultSet</code>.
030: *
031: * @author Michael Bell
032: * @version $Revision: 1.2 $
033: *
034: */
035: public final class SearchResultsCache extends AbstractCache {
036: private static SearchResultsCache m_instance = null;
037: private static String CACHE_NAME = "SearchResults";
038:
039: /**
040: * Logger for this class.
041: */
042: private static final Logger m_logger = Logger
043: .getLogger(SearchResultsCache.class.getName());
044:
045: /**
046: * Basic constructor.
047: *
048: * @throws CacheException
049: */
050: private SearchResultsCache() throws CacheException {
051: super (CACHE_NAME);
052: }
053:
054: /**
055: * Returns the singleton instance of this cache.
056: *
057: * @return
058: * @throws CacheException
059: */
060: public synchronized static SearchResultsCache getInstance()
061: throws CacheException {
062: if (m_instance == null) {
063: m_instance = new SearchResultsCache();
064: }
065:
066: return m_instance;
067: }
068:
069: /**
070: * Returns the <code>CachedResultSet</code> associated with the given <code>query</code>.
071: *
072: * @param query
073: * @return
074: */
075: public CachedResultSet getResults(String query) {
076: CachedResultSet returnResultSet = null;
077: final CachedResultSet cached_results;
078: try {
079: cached_results = (CachedResultSet) this .getObject(query);
080: if (cached_results != null) {
081: returnResultSet = (CachedResultSet) cached_results
082: .clone();
083: }
084: } catch (CacheException e) {
085: m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
086: }
087:
088: return returnResultSet;
089: }
090:
091: /**
092: * Adds the given <code>CachedResultSet</code> to the cache associated to the given
093: * <code>query</code>.
094: *
095: * @param query
096: * @param results
097: */
098: public void addToCache(String query, CachedResultSet results) {
099: super .addToCache(query, results);
100: }
101:
102: /* (non-Javadoc)
103: * @see org.openharmonise.commons.cache.AbstractCache#getCacheableObject(java.lang.Object)
104: */
105: protected Object getCacheableObject(Object query) throws Exception {
106: //return null as results are added from external source
107: return null;
108: }
109: }
|