1 13 14 package org.ejbca.core.model.ca.caadmin; 15 16 import java.util.Date ; 17 import java.util.Hashtable ; 18 19 import org.apache.log4j.Logger; 20 import org.ejbca.core.ejb.ca.caadmin.CADataBean; 21 22 23 29 public class CACacheManager { 30 31 32 private static transient Logger log = Logger.getLogger(CACacheManager.class); 33 34 35 private Hashtable caRegistry = new Hashtable (); 36 37 38 private static CACacheManager instance = null; 39 40 42 private CACacheManager() {} 43 44 47 public synchronized static CACacheManager instance() { 48 if (instance == null) { 49 instance = new CACacheManager(); 50 } 51 return instance; 52 } 53 54 59 public CA getCA(int caid, CADataBean caData) { 60 CA ret = (CA)caRegistry.get(new Integer (caid)); 61 if (ret != null) { 62 ret.setStatus(caData.getStatus()); 64 ret.setExpireTime(new Date (caData.getExpireTime())); 65 ret.setName(caData.getName()); 66 ret.setSubjectDN(caData.getSubjectDN()); 67 ret.setCAId(caid); 68 } 69 return ret; 70 } 71 72 78 public synchronized void addCA(int caid, CA ca) { 79 removeCA(caid); 80 if (ca != null) { 81 caRegistry.put(new Integer (caid), ca); 82 log.debug("Added CA to registry: "+caid); 83 } 84 } 85 86 89 public synchronized void removeCA(int caid) { 90 if (caRegistry.containsKey(new Integer (caid))) { 91 caRegistry.remove(new Integer (caid)); 92 log.debug("Removed old CA from registry: "+caid); 93 } 94 } 95 } 96 | Popular Tags |