1 package com.calipso.reportgenerator.reportmanager; 2 3 import com.calipso.reportgenerator.common.InfoException; 4 5 import java.util.HashMap ; 6 7 import com.calipso.reportgenerator.common.LanguageTraslator; 8 9 12 public class CacheRepository { 13 private HashMap cache; 14 private String repositoryName; 15 16 20 public CacheRepository(String name) { 21 this.repositoryName = name; 22 } 23 24 28 public HashMap getCache() { 29 if (cache == null) { 30 cache = new HashMap (); 31 } 32 return cache; 33 } 34 35 40 public boolean containsObject(String name) { 41 return getCache().containsKey(name.toUpperCase()); 42 } 43 44 49 public boolean containsObject(Object object) { 50 return getCache().containsValue(object); 51 } 52 53 58 public void addObject(String name, Object object) { 59 if (!containsObject(name)) { 60 System.out.println(repositoryName + LanguageTraslator.traslate("494") + name); 61 getCache().put(name, object); 62 } 63 } 64 65 70 public void removeObject(String name) throws InfoException { 71 if (name.equalsIgnoreCase("")) { 72 throw new InfoException(LanguageTraslator.traslate("72")); 73 } 74 else { 75 if (getCache().remove(name) == null) { 76 throw new InfoException(LanguageTraslator.traslate("73") + name); 77 } 78 } 79 } 80 81 87 public Object getObject(String name) throws InfoException { 88 Object returnObject = null; 89 if (name.equalsIgnoreCase("")) { 90 throw new InfoException(LanguageTraslator.traslate("74")); 91 } 92 else { 93 returnObject = getCache().get(name); 94 System.out.println(repositoryName + LanguageTraslator.traslate("495") + name); 95 if (returnObject == null) { 96 throw new InfoException(LanguageTraslator.traslate("75") + name); 97 } 98 else { 99 return returnObject; 100 } 101 } 102 } 103 104 107 public void deleteAll(){ 108 getCache().clear(); 109 } 110 111 115 public void delete(String name){ 116 getCache().remove(name); 117 } 118 119 } 120 | Popular Tags |