View Javadoc

1   /***
2    * @(#)SwarmCacheServiceImpl.java
3    *  
4    * JFoxSOAF, Service-Oriented Application Framework
5    * 
6    * Copyright(c) JFoxSOAF Team
7    * 
8    * Licensed under the GNU LGPL, Version 2.1 (the "License"); 
9    * you may not use this file except in compliance with the License. 
10   * You may obtain a copy of the License at  
11   * 
12   * http://www.gnu.org/copyleft/lesser.html
13   * 
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, 
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17   * See the License for the specific language governing permissions and 
18   * limitations under the License. 
19   * 
20   * For more information, please visit:
21   * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
22   * http://www.huihoo.org/jfox/jfoxsoaf
23   */
24  
25  package org.huihoo.jfox.soaf.services.cache;
26  
27  import java.io.Serializable;
28  
29  import net.sf.swarmcache.ObjectCache;
30  
31  import org.huihoo.jfox.soaf.exception.CacheServiceException;
32  
33  /***
34   * <p>
35   * Support for SwarmCache.
36   * </p>
37   * 
38   * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
39   * @author <a href="mailto:m.bogaert@intrasoft.be">Mathias Bogaert </a>
40   * @version $Revision: 1.1 $ $Date: 2005/05/22 06:48:52 $
41   * @version Revision: 1.0
42   */
43  
44  public class SwarmCacheServiceImpl implements CacheService {
45  
46      private ObjectCache cache;
47  
48      public SwarmCacheServiceImpl(ObjectCache cache) {
49          this.cache = cache;
50      }
51  
52      /***
53       * @see org.huihoo.jfox.soaf.services.cache.CacheService#get(java.lang.Object)
54       */
55      public Object get(Object key) throws CacheServiceException {
56          if (key instanceof Serializable) {
57              return cache.get((Serializable) key);
58          } else {
59              throw new CacheServiceException("Keys must implement Serializable");
60          }
61      }
62  
63      /***
64       * @see org.huihoo.jfox.soaf.services.cache.CacheService#put(java.lang.Object,
65       *      java.lang.Object)
66       */
67      public void put(Object key, Object value) throws CacheServiceException {
68          if (key instanceof Serializable) {
69              cache.put((Serializable) key, value);
70          } else {
71              throw new CacheServiceException("Keys must implement Serializable");
72          }
73      }
74  
75      /***
76       * @see org.huihoo.jfox.soaf.services.cache.CacheService#remove(java.lang.Object)
77       */
78      public void remove(Object key) throws CacheServiceException {
79          if (key instanceof Serializable) {
80              cache.clear((Serializable) key);
81          } else {
82              throw new CacheServiceException("Keys must implement Serializable");
83          }
84      }
85  
86      /***
87       * @see org.huihoo.jfox.soaf.services.cache.CacheService#clear()
88       */
89      public void clear() throws CacheServiceException {
90          cache.clearAll();
91      }
92  
93  }