1 6 7 package SOFA.SOFAnet.Repository; 8 9 import java.io.*; 10 import java.util.*; 11 import SOFA.SOFAnode.TR.ComponentInfo; 12 13 19 public class BundleContents extends StorageBase 20 { 21 private CompBundleMap compBundleMap; 22 23 24 public BundleContents(File baseDir) 25 { 26 super(baseDir, "content", true); init(); 28 createCompBundleMap(); 29 } 30 31 protected StorageItem newItem(String name, File file) 32 { 33 String bundleName = BundleInfo.fileNameToBundleName(name); 34 if (bundleName == null) return null; 35 else return new BundleContent(bundleName, file); 36 } 37 38 41 public void createCompBundleMap() 42 { 43 compBundleMap = new CompBundleMap(); 44 Iterator it = map.values().iterator(); 45 while (it.hasNext()) 46 { 47 BundleContent bundleContent = (BundleContent)it.next(); 48 compBundleMap.addBundleContent(bundleContent); 49 bundleContent.setLoaded(false); } 51 } 52 53 58 public CompBundleMap getCompBundleMap() 59 { 60 return compBundleMap; 61 } 62 63 70 public BundleContent getBundleContent(String bundleName) 71 { 72 BundleContent bundleContent = (BundleContent)map.get(bundleName); 73 if (bundleContent != null && !bundleContent.isLoaded()) bundleContent.loadFromStorage(); 74 return bundleContent; 75 } 76 77 83 public boolean deleteBundleContent(String bundleName) 84 { 85 synchronized (map) 86 { 87 BundleContent bundleContent = (BundleContent)map.remove(bundleName); 88 if (bundleContent != null) 89 { 90 bundleContent.deleteFromStorage(); 91 compBundleMap.deleteBundle(bundleName); 92 return true; 93 } 94 else return false; 95 } 96 } 97 98 105 public BundleContent addBundleContent(String bundleName, ComponentInfo[] components) 106 { 107 synchronized (map) 108 { 109 if (map.get(bundleName) != null) return null; 110 111 String fileName = BundleInfo.bundleNameToFileName(bundleName); 112 if (fileName == null) return null; 113 BundleContent bundleContent = new BundleContent(bundleName, new File(baseDir, fileName + ".content")); 114 List compList = bundleContent.getComponents(); 115 for (int i = 0; i < components.length; i++) 116 { 117 compList.add(components[i]); 118 } 119 120 compBundleMap.addBundleContent(bundleContent); 121 bundleContent.saveToStorage(); 122 map.put(bundleName, bundleContent); 123 return bundleContent; 124 } 125 } 126 } 127 | Popular Tags |