1 6 7 package SOFA.SOFAnet.Repository; 8 9 import java.io.*; 10 import java.util.*; 11 import SOFA.SOFAnode.TR.Impl.ComponentInfoImpl; 12 13 19 public class BundleOffers extends StorageBase 20 { 21 private CompBundleMap compBundleMap; 22 23 24 public BundleOffers(File baseDir) 25 { 26 super(baseDir, "offer", 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 BundleOffer(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 BundleOffer bundleOffer = (BundleOffer)it.next(); 48 compBundleMap.addBundleOffer(bundleOffer); 49 bundleOffer.setLoaded(false); } 51 } 52 53 58 public CompBundleMap getCompBundleMap() 59 { 60 return compBundleMap; 61 } 62 63 70 public BundleOffer getBundleOffer(String bundleName) 71 { 72 BundleOffer bundleOffer = (BundleOffer)map.get(bundleName); 73 if (bundleOffer != null && !bundleOffer.isLoaded()) bundleOffer.loadFromStorage(); 74 return bundleOffer; 75 } 76 77 83 public boolean deleteBundleOffer(String bundleName) 84 { 85 synchronized (map) 86 { 87 BundleOffer bundleOffer = (BundleOffer)map.remove(bundleName); 88 if (bundleOffer != null) 89 { 90 bundleOffer.deleteFromStorage(); 91 compBundleMap.deleteBundle(bundleName); 92 return true; 93 } 94 else return false; 95 } 96 } 97 98 106 public BundleOffer addBundleOffer(String bundleName, String nodeName, ComponentInfoImpl[] components) 107 { 108 synchronized (map) 109 { 110 if (map.get(bundleName) != null) return null; 111 112 String fileName = BundleInfo.bundleNameToFileName(bundleName); 113 if (fileName == null) return null; 114 BundleOffer bundleOffer = new BundleOffer(bundleName, new File(baseDir, fileName + ".offer")); 115 bundleOffer.setNodeName(nodeName); 116 List compList = bundleOffer.getComponents(); 117 for (int i = 0; i < components.length; i++) 118 { 119 compList.add(components[i]); 120 } 121 122 compBundleMap.addBundleOffer(bundleOffer); 123 bundleOffer.saveToStorage(); 124 map.put(bundleName, bundleOffer); 125 return bundleOffer; 126 } 127 } 128 } 129 | Popular Tags |