1 6 7 package SOFA.SOFAnet.Repository; 8 9 import java.io.*; 10 import java.util.*; 11 12 18 public class Licences extends StorageBase 19 { 20 21 22 public Licences(File baseDir) 23 { 24 super(baseDir, "licence", false); 25 init(); 26 } 27 28 protected StorageItem newItem(String name, File file) 29 { 30 String bundleName = BundleInfo.fileNameToBundleName(name); 31 if (bundleName == null) return null; 32 else return new Licence(bundleName, file); 33 } 34 35 42 public Licence getLicence(String bundleName) 43 { 44 Licence licence = (Licence)map.get(bundleName); 45 if (licence != null && !licence.isLoaded()) licence.loadFromStorage(); 46 return licence; 47 } 48 49 55 public boolean deleteLicence(String bundleName) 56 { 57 synchronized (map) 58 { 59 Licence licence = (Licence)map.remove(bundleName); 60 if (licence != null) 61 { 62 licence.deleteFromStorage(); 63 return true; 64 } 65 else return false; 66 } 67 } 68 69 81 public Licence addLicence(String bundleName, 82 int type, 83 int numberOfCopies, 84 Date validFrom, 85 Date validTo, 86 String text) 87 { 88 synchronized (map) 89 { 90 if (map.get(bundleName) != null) return null; 91 String fileName = BundleInfo.bundleNameToFileName(bundleName); 92 if (fileName == null) return null; 93 Licence lic = new Licence(bundleName, new File(baseDir, fileName + ".licence")); 94 lic.setType(type); 95 lic.setNumberOfCopies(numberOfCopies); 96 lic.setValidFrom(validFrom); 97 lic.setValidTo(validTo); 98 lic.setText(text); 99 100 lic.saveToStorage(); 101 map.put(bundleName, lic); 102 return lic; 103 } 104 } 105 } 106 | Popular Tags |