1 16 17 package org.springframework.web.context.request; 18 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import org.springframework.core.CollectionFactory; 23 import org.springframework.util.Assert; 24 25 34 public abstract class AbstractRequestAttributes implements RequestAttributes { 35 36 37 protected final Map requestDestructionCallbacks = CollectionFactory.createLinkedMapIfPossible(8); 38 39 40 45 public void requestCompleted() { 46 executeRequestDestructionCallbacks(); 47 updateAccessedSessionAttributes(); 48 } 49 50 55 protected final void registerRequestDestructionCallback(String name, Runnable callback) { 56 Assert.notNull(name, "Name must not be null"); 57 Assert.notNull(callback, "Callback must not be null"); 58 this.requestDestructionCallbacks.put(name, callback); 59 } 60 61 65 protected final void removeRequestDestructionCallback(String name) { 66 Assert.notNull(name, "Name must not be null"); 67 this.requestDestructionCallbacks.remove(name); 68 } 69 70 74 private void executeRequestDestructionCallbacks() { 75 for (Iterator it = this.requestDestructionCallbacks.values().iterator(); it.hasNext();) { 76 ((Runnable ) it.next()).run(); 77 } 78 this.requestDestructionCallbacks.clear(); 79 } 80 81 85 protected abstract void updateAccessedSessionAttributes(); 86 87 } 88 | Popular Tags |