Coverage Report - org.webslinger.commons.vfs.handlers.cow.COWStateXmlStorageHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
COWStateXmlStorageHandler
81%
17/21
100%
4/4
0
COWStateXmlStorageHandler$1
100%
4/4
100%
1/1
0
 
 1  
 package org.webslinger.commons.vfs.handlers.cow;
 2  
 
 3  
 import java.util.Collection;
 4  
 
 5  
 import org.apache.commons.vfs.FileName;
 6  
 import org.apache.commons.vfs.FileObject;
 7  
 import org.apache.commons.vfs.FileSystemException;
 8  
 
 9  
 import org.webslinger.commons.vfs.VFSUtil;
 10  
 import org.webslinger.lang.ConcurrentCache;
 11  
 
 12  
 public abstract class COWStateXmlStorageHandler implements COWStorageHandler {
 13  
     protected final ConcurrentCache<FileName, COWStateXml> states;
 14  
 
 15  53
     public COWStateXmlStorageHandler() {
 16  82892
         states = new ConcurrentCache<FileName, COWStateXml>(COWStateXmlStorageHandler.class, "states", null, ConcurrentCache.SOFT) {
 17  
             protected COWStateXml findIfExists(FileName key) throws Exception {
 18  82820
                 FileObject file = getFile(key);
 19  82820
                 return file.exists() ? new COWStateXml(file) : null;
 20  
             }
 21  
 
 22  
             protected COWStateXml createValue(FileName key) throws Exception {
 23  19
                 return new COWStateXml(getFile(key));
 24  
             }
 25  
         };
 26  53
     }
 27  
 
 28  
     protected abstract FileObject getFile(FileName dir) throws FileSystemException;
 29  
     public abstract void excludeNames(Collection<String> names);
 30  
 
 31  
     protected COWStateXml getCOWStateXml(FileName name, boolean create) throws FileSystemException {
 32  16645
         name = name.getParent();
 33  16645
         if (name == null) return null;
 34  
         try {
 35  16592
             return states.get(name, create);
 36  0
         } catch (Exception e) {
 37  0
             throw VFSUtil.makeFileSystemException(e);
 38  
         }
 39  
     }
 40  
 
 41  
     public void removeDeletedChildren(FileName name, Collection<String> names) throws FileSystemException {
 42  
         try {
 43  67113
             COWStateXml state = states.get(name, false);
 44  67113
             if (state == null) return;
 45  62
             state.removeDeletedChildren(names);
 46  0
         } catch (Exception e) {
 47  0
             throw VFSUtil.makeFileSystemException(e);
 48  62
         }
 49  62
     }
 50  
 
 51  
     public Collection<String> loadData(FileName name, boolean[] isDeleted) throws FileSystemException {
 52  16451
         COWStateXml state = getCOWStateXml(name, false);
 53  16451
         if (state == null) return null;
 54  682
         return state.loadData(name.getBaseName(), isDeleted);
 55  
     }
 56  
 
 57  
     public boolean submitRequests(FileName name, Request... requests) throws FileSystemException {
 58  194
         COWStateXml state = getCOWStateXml(name, true);
 59  194
         if (state == null) return false;
 60  194
         return state.submitRequests(name.getBaseName(), requests);
 61  
     }
 62  
 }