1 25 26 package org.snipsnap.app; 27 28 import java.util.Collection ; 29 import java.util.Map ; 30 import java.util.Iterator ; 31 import java.util.Properties ; 32 33 40 41 public class ApplicationManager { 42 private ApplicationStorage storage; 43 private Map prefixMap; 44 45 public ApplicationManager(ApplicationStorage applicationStorage) { 46 this.storage = applicationStorage; 47 prefixMap = storage.getApplications(); 48 } 49 50 public Properties createApplication(String name, String prefix) { 51 Properties prefixProps = storage.createApplication(name, prefix); 52 prefixMap.put(prefix, prefixProps); 53 return prefixProps; 54 } 55 56 public void removeApplication(String oid) { 57 storage.removeApplication(oid); 58 } 59 60 public String getPrefix(String oid) { 61 String result = null; 62 Iterator iterator = prefixMap.keySet().iterator(); 63 while (iterator.hasNext()) { 64 String prefix = (String ) iterator.next(); 65 String aOid = getApplication(prefix); 66 if (oid.equals(aOid)) { 67 result = prefix; 68 } 69 } 70 return result; 71 } 72 73 public Collection getPrefixes() { 74 return storage.getApplications().keySet(); 75 } 76 77 public Collection getApplications() { 78 return storage.getApplications().values(); 79 } 80 81 public String getApplication(String prefix) { 82 Properties prefixProps = (Properties ) prefixMap.get(prefix); 83 if(null != prefixProps) { 84 return prefixProps.getProperty(ApplicationStorage.OID); 85 } 86 return null; 87 } 88 } 89 | Popular Tags |