KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > search > SearchResultsCache


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.search;
21
22 import java.util.logging.*;
23 import java.util.logging.Level JavaDoc;
24
25 import org.openharmonise.commons.cache.*;
26 import org.openharmonise.commons.dsi.*;
27
28
29 /**
30  * This class provides caching functionality for <code>CachedResultSet</code>.
31  *
32  * @author Michael Bell
33  * @version $Revision: 1.2 $
34  *
35  */

36 public final class SearchResultsCache extends AbstractCache {
37     private static SearchResultsCache m_instance = null;
38     private static String JavaDoc CACHE_NAME = "SearchResults";
39     
40     /**
41      * Logger for this class.
42      */

43     private static final Logger m_logger = Logger.getLogger(SearchResultsCache.class.getName());
44
45     /**
46      * Basic constructor.
47      *
48      * @throws CacheException
49      */

50     private SearchResultsCache() throws CacheException {
51         super(CACHE_NAME);
52     }
53
54     /**
55      * Returns the singleton instance of this cache.
56      *
57      * @return
58      * @throws CacheException
59      */

60     public synchronized static SearchResultsCache getInstance() throws CacheException {
61         if (m_instance == null) {
62             m_instance = new SearchResultsCache();
63         }
64
65         return m_instance;
66     }
67
68     /**
69      * Returns the <code>CachedResultSet</code> associated with the given <code>query</code>.
70      *
71      * @param query
72      * @return
73      */

74     public CachedResultSet getResults(String JavaDoc query) {
75         CachedResultSet returnResultSet = null;
76         final CachedResultSet cached_results;
77         try {
78             cached_results = (CachedResultSet) this.getObject(query);
79             if(cached_results != null){
80                   returnResultSet = (CachedResultSet)cached_results.clone();
81             }
82         } catch (CacheException e) {
83             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
84         }
85         
86         return returnResultSet;
87     }
88
89     /**
90      * Adds the given <code>CachedResultSet</code> to the cache associated to the given
91      * <code>query</code>.
92      *
93      * @param query
94      * @param results
95      */

96     public void addToCache(String JavaDoc query, CachedResultSet results) {
97         super.addToCache(query, results);
98     }
99     
100
101     /* (non-Javadoc)
102      * @see org.openharmonise.commons.cache.AbstractCache#getCacheableObject(java.lang.Object)
103      */

104     protected Object JavaDoc getCacheableObject(Object JavaDoc query) throws Exception JavaDoc {
105         //return null as results are added from external source
106
return null;
107     }
108 }
Popular Tags