Clover coverage report - Acegi Security System for Spring - 1.0.0-RC1
Coverage timestamp: Mon Dec 5 2005 09:05:15 EST
file stats: LOC: 107   Methods: 5
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
EhCacheBasedAclEntryCache.java 62.5% 80% 100% 78.8%
coverage coverage
 1    /* Copyright 2004 Acegi Technology Pty Limited
 2    *
 3    * Licensed under the Apache License, Version 2.0 (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
 6    *
 7    * http://www.apache.org/licenses/LICENSE-2.0
 8    *
 9    * Unless required by applicable law or agreed to in writing, software
 10    * distributed under the License is distributed on an "AS IS" BASIS,
 11    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    * See the License for the specific language governing permissions and
 13    * limitations under the License.
 14    */
 15   
 16    package org.acegisecurity.acl.basic.cache;
 17   
 18    import org.acegisecurity.acl.basic.AclObjectIdentity;
 19    import org.acegisecurity.acl.basic.BasicAclEntry;
 20    import org.acegisecurity.acl.basic.BasicAclEntryCache;
 21   
 22    import net.sf.ehcache.Cache;
 23    import net.sf.ehcache.CacheException;
 24    import net.sf.ehcache.Element;
 25   
 26    import org.apache.commons.logging.Log;
 27    import org.apache.commons.logging.LogFactory;
 28   
 29    import org.springframework.beans.factory.InitializingBean;
 30   
 31    import org.springframework.dao.DataRetrievalFailureException;
 32    import org.springframework.util.Assert;
 33   
 34   
 35    /**
 36    * Caches <code>BasicAclEntry</code>s using a Spring IoC defined <A
 37    * HREF="http://ehcache.sourceforge.net">EHCACHE</a>.
 38    *
 39    * @author Ben Alex
 40    * @version $Id: EhCacheBasedAclEntryCache.java,v 1.5 2005/11/17 00:56:47 benalex Exp $
 41    */
 42    public class EhCacheBasedAclEntryCache implements BasicAclEntryCache,
 43    InitializingBean {
 44    //~ Static fields/initializers =============================================
 45   
 46    private static final Log logger = LogFactory.getLog(EhCacheBasedAclEntryCache.class);
 47   
 48    //~ Instance fields ========================================================
 49   
 50    private Cache cache;
 51   
 52    //~ Methods ================================================================
 53   
 54  2 public void setCache(Cache cache) {
 55  2 this.cache = cache;
 56    }
 57   
 58  1 public Cache getCache() {
 59  1 return cache;
 60    }
 61   
 62  4 public BasicAclEntry[] getEntriesFromCache(
 63    AclObjectIdentity aclObjectIdentity) {
 64  4 Element element = null;
 65   
 66  4 try {
 67  4 element = cache.get(aclObjectIdentity);
 68    } catch (CacheException cacheException) {
 69  0 throw new DataRetrievalFailureException("Cache failure: "
 70    + cacheException.getMessage());
 71    }
 72   
 73    // Return null if cache element has expired or not found
 74  4 if (element == null) {
 75  1 if (logger.isDebugEnabled()) {
 76  0 logger.debug("Cache miss: " + aclObjectIdentity);
 77    }
 78   
 79  1 return null;
 80    }
 81   
 82  3 if (logger.isDebugEnabled()) {
 83  0 logger.debug("Cache hit: " + (element != null) + "; object: "
 84    + aclObjectIdentity);
 85    }
 86   
 87  3 BasicAclEntryHolder holder = (BasicAclEntryHolder) element.getValue();
 88   
 89  3 return holder.getBasicAclEntries();
 90    }
 91   
 92  2 public void afterPropertiesSet() throws Exception {
 93  2 Assert.notNull(cache, "cache mandatory");
 94    }
 95   
 96  2 public void putEntriesInCache(BasicAclEntry[] basicAclEntry) {
 97  2 BasicAclEntryHolder holder = new BasicAclEntryHolder(basicAclEntry);
 98  2 Element element = new Element(basicAclEntry[0].getAclObjectIdentity(),
 99    holder);
 100   
 101  2 if (logger.isDebugEnabled()) {
 102  0 logger.debug("Cache put: " + element.getKey());
 103    }
 104   
 105  2 cache.put(element);
 106    }
 107    }