1 21 package net.sf.packtag.cache; 22 23 import java.util.Hashtable ; 24 25 26 27 33 public class ResourceCache { 34 35 private Hashtable resourcesSqp = new Hashtable (); 36 private Hashtable resourcesFqp = new Hashtable (); 37 38 39 public Resource getResourceBySqp(String sqp) { 40 return (Resource)resourcesSqp.get(sqp); 41 } 42 43 44 public Resource getResourceByFqp(String fqp) { 45 return (Resource)resourcesFqp.get(fqp); 46 } 47 48 49 public boolean existResource(String sqp) { 50 return resourcesSqp.containsKey(sqp); 51 } 52 53 54 public void store(Resource resource, boolean clearDependingCombinedResources) { 55 resourcesSqp.put(resource.getShortQualifiedPath(), resource); 56 resourcesFqp.put(resource.getFullQualifiedPath(), resource); 57 58 if (clearDependingCombinedResources) { 59 clearDependingCombinedResources(resource); 60 } 61 } 62 63 64 public void clearCache() { 65 resourcesSqp.clear(); 66 resourcesFqp.clear(); 67 } 68 69 70 private void clearDependingCombinedResources(Resource resource) { 71 String sqp = resource.getShortQualifiedPath(); 72 Object [] keys = resourcesSqp.keySet().toArray(); 73 for (int i = 0; i < keys.length; i++) { 74 Resource currentResource = (Resource)resourcesSqp.get(keys[i]); 75 int idx = currentResource.getShortQualifiedPath().indexOf(sqp); 76 if (idx > 0) { 78 resourcesSqp.remove(keys[i]); 79 } 80 } 81 } 82 } 83 | Popular Tags |