1 25 26 package org.snipsnap.interceptor.custom; 27 28 import org.snipsnap.interceptor.InterceptorSupport; 29 import org.snipsnap.interceptor.Invocation; 30 31 import java.util.HashMap ; 32 import java.util.Map ; 33 34 44 45 public class MissingSnipInterceptor extends InterceptorSupport { 46 private Map missing; 47 48 public MissingSnipInterceptor() { 49 super(); 50 missing = new HashMap (); 51 } 52 53 public Object invoke(Invocation invocation) throws Throwable { 54 String methodName = invocation.getMethod().getName(); 55 56 if ("exists".equals(methodName)) { 57 String name = ((String ) invocation.getArgs()[0]).toUpperCase(); 58 if (missing.containsKey(name)) { 60 return new Boolean (false); 61 } 62 Boolean result = (Boolean ) invocation.next(); 63 if (result.equals(Boolean.FALSE)) { 65 missing.put(name, new Integer (0)); 66 } 67 return result; 68 69 } else if ("create".equals(methodName)) { 70 String name = ((String ) invocation.getArgs()[0]).toUpperCase(); 71 72 Object result = invocation.next(); 73 74 if (missing.containsKey(name)) { 75 missing.remove(name); 76 } 77 return result; 78 } else { 79 return invocation.next(); 81 } 82 } 83 } 84 | Popular Tags |