1 19 20 package org.openharmonise.rm.commands; 21 22 import java.lang.reflect.*; 23 import java.util.logging.*; 24 25 import org.openharmonise.commons.cache.*; 26 import org.openharmonise.rm.factory.*; 27 import org.openharmonise.rm.search.*; 28 29 30 37 public class CmdClearCache extends AbstractCmd { 38 private static String PARAM_CACHE = "cache"; 39 40 43 private static final Logger m_logger = Logger.getLogger(CmdClearCache.class.getName()); 44 45 49 public CmdClearCache() { 50 super(); 51 } 52 53 56 public Object execute(Context context) throws CommandException { 57 String cache_name = this.getParameter(PARAM_CACHE); 58 59 if(m_logger.isLoggable(Level.FINE)) { 60 m_logger.logp(Level.FINE, this.getClass().getName(), "execute", "Clearing cache:" + cache_name); 61 } 62 63 if (cache_name.equalsIgnoreCase("resultset")) { 64 try { 65 SearchResultsCache.getInstance().clearCache(); 66 } catch (CacheException e) { 67 throw new CommandExecutionException("Cache exception",e); 68 } 69 } else if (cache_name.indexOf(".") > 0) { 70 Class obj_class; 71 try { 72 obj_class = Class.forName(cache_name); 73 } catch (ClassNotFoundException e) { 74 throw new CommandException("Class not found - " + cache_name,e); 75 } 76 77 if (isCache(obj_class) == true) { 78 try { 79 Method getInstanceMethod = obj_class.getMethod("getInstance", 80 null); 81 82 AbstractCache cache = (AbstractCache) getInstanceMethod.invoke( 83 null, null); 84 85 86 cache.clearCache(); 87 88 } catch (NoSuchMethodException e) { 89 throw new CommandExecutionException("Didn't find 'getInstance' for " + cache_name); 90 } catch (SecurityException e) { 91 throw new CommandExecutionException("Not allowed to access 'getInstance' for " + cache_name); 92 } catch (IllegalArgumentException e) { 93 throw new CommandExecutionException("InvocationTargetException: Not allowed to access 'getInstance' for " + cache_name); 94 } catch (IllegalAccessException e) { 95 throw new CommandExecutionException("InvocationTargetException: Not allowed to access 'getInstance' for " + cache_name); 96 } catch (InvocationTargetException e) { 97 throw new CommandExecutionException("InvocationTargetException: Not allowed to access 'getInstance' for " + cache_name); 98 } 99 } else { 100 101 String sClassname = cache_name; 102 CacheHandler chandler = CacheHandler.getInstance(getDataStoreInteface()); 103 104 if (sClassname != null) { 105 try { 106 AbstractCache cache = chandler.getCache(sClassname); 107 cache.clearCache(); 108 } catch (Exception e) { 109 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 110 } 111 } 112 113 } 114 } else { 115 throw new CommandExecutionException("Didn't clear cache for " + cache_name); 116 } 117 118 return null; 119 } 120 121 124 public String getName() { 125 return "ClearCache"; 126 } 127 128 131 public boolean isValidCommandObject(Object obj) { 132 return true; 134 } 135 136 144 private boolean isCache(Class clss) { 145 return AbstractCache.class.isAssignableFrom(clss); 146 } 147 148 } | Popular Tags |