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.HashSet ; 32 import java.util.Set ; 33 34 43 public class MissingInterceptor extends InterceptorSupport { 44 private Set missing; 47 48 public MissingInterceptor() { 49 super(); 50 missing = new HashSet (); 51 } 52 53 public Set getMissing() { 54 return missing; 55 } 56 57 public Object invoke(Invocation invocation) throws Throwable { 58 String method = invocation.getMethod().getName(); 59 60 if ("exists".equals(method)) { 62 String name = ((String ) invocation.getArgs()[0]).toUpperCase(); 63 if (missing.contains(name)) { 64 return Boolean.FALSE; 65 } 66 Object result = invocation.next(); 67 if (Boolean.FALSE.equals(result)) { 68 missing.add(name); 69 } 70 return result; 71 } else if ("create".equals(method)) { 73 String name = ((String ) invocation.getArgs()[0]).toUpperCase(); 74 if (missing.contains(name.toUpperCase())) { 75 missing.remove(name); 76 } 77 } 78 Object result = invocation.next(); 79 return result; 80 } 81 } 82 | Popular Tags |