1 /** 2 * 3 */ 4 package net.sf.crispy.impl; 5 6 import java.util.ArrayList; 7 import java.util.List; 8 9 import net.sf.crispy.InterceptorContext; 10 import net.sf.crispy.Modifier; 11 12 /** 13 * You can link together several Modifier in a chain. 14 * 15 * @author Linke 16 * 17 */ 18 public class ModifierChain implements Modifier { 19 20 private List modifiers = new ArrayList(); 21 22 public void addModifier(Modifier pvModifier) { modifiers.add(pvModifier); } 23 public void removeModifier(int pvPos) { modifiers.remove(pvPos); } 24 public int size () { return modifiers.size(); } 25 26 public InterceptorContext modifyBeforeInvocation(InterceptorContext pvInterceptorContext) { 27 InterceptorContext lvContext = pvInterceptorContext; 28 for (int i = 0; i < modifiers.size(); i++) { 29 Modifier lvModifier = (Modifier) modifiers.get(i); 30 lvContext = lvModifier.modifyBeforeInvocation(lvContext); 31 } 32 return lvContext; 33 } 34 35 public InterceptorContext modifyAfterInvocation(InterceptorContext pvInterceptorContext) { 36 InterceptorContext lvContext = pvInterceptorContext; 37 for (int i = 0; i < modifiers.size(); i++) { 38 Modifier lvModifier = (Modifier) modifiers.get(i); 39 lvContext = lvModifier.modifyAfterInvocation(lvContext); 40 } 41 return lvContext; 42 } 43 44 }