1 6 7 package SOFA.SOFAnet.Repository; 8 9 import java.io.*; 10 import java.util.*; 11 12 18 public class OutputTriggers extends StorageBase 19 { 20 21 22 public OutputTriggers(File baseDir) 23 { 24 super(baseDir, "ot", true); 25 init(); 26 } 27 28 protected StorageItem newItem(String name, File file) 29 { 30 return new OutputTrigger(name, file); 31 } 32 33 40 public OutputTrigger getOutputTrigger(String name) 41 { 42 OutputTrigger outputTrigger = (OutputTrigger)map.get(name); 43 if (outputTrigger != null && !outputTrigger.isLoaded()) outputTrigger.loadFromStorage(); 44 return outputTrigger; 45 } 46 47 53 public boolean deleteOutputTrigger(String name) 54 { 55 synchronized (map) 56 { 57 OutputTrigger outputTrigger = (OutputTrigger)map.remove(name); 58 if (outputTrigger != null) 59 { 60 outputTrigger.deleteFromStorage(); 61 return true; 62 } 63 else return false; 64 } 65 } 66 67 93 public OutputTrigger addOutputTrigger(String name, 94 boolean customizableName, 95 String description, 96 boolean autoDelete, 97 BundleNameFilter bundleFilter, 98 NodeNameFilter nodeFilter, 99 Date validFrom, 100 Date validTo, 101 String contractID, 102 String contractRule) 103 { 104 synchronized (map) 105 { 106 if (customizableName || name == null) 107 { 108 if (name == null || name.length() == 0) 109 { 110 name = "auto"; 111 Random random = new Random(); 112 for (int i = 0; i < 10; i++) name += Integer.toString(random.nextInt(16), 16); 113 } 114 115 String postfix = ""; 116 for (int i = 0; ; i++) 117 { 118 if (map.get(name + postfix) == null) 119 { 120 name += postfix; 121 break; 122 } 123 postfix = Integer.toString(i + 1); 124 } 125 } 126 else 127 { 128 if (map.get(name) != null) return null; 129 } 130 131 OutputTrigger outputTrigger = new OutputTrigger(name, new File(baseDir, name + ".ot")); 132 outputTrigger.setDescription(description); 133 outputTrigger.setAutoDelete(autoDelete); 134 outputTrigger.setBundleFilter(bundleFilter); 135 outputTrigger.setNodeFilter(nodeFilter); 136 outputTrigger.setValidFrom(validFrom); 137 outputTrigger.setValidTo(validTo); 138 outputTrigger.setContract(contractID, contractRule); 139 140 outputTrigger.saveToStorage(); 141 map.put(name, outputTrigger); 142 return outputTrigger; 143 } 144 } 145 } | Popular Tags |