1 package org.codehaus.xfire.handler; 2 3 import java.util.ArrayList; 4 import java.util.Iterator; 5 import java.util.List; 6 7 import org.codehaus.xfire.MessageContext; 8 import org.codehaus.xfire.fault.XFireFault; 9 10 /*** 11 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a> 12 */ 13 public class HandlerPipeline 14 extends AbstractHandler 15 implements Handler 16 { 17 private List handlers; 18 19 public HandlerPipeline() 20 { 21 handlers = new ArrayList(); 22 } 23 24 public Handler getHandler(int i) 25 { 26 return (Handler) handlers.get(i); 27 } 28 29 public int size() 30 { 31 return handlers.size(); 32 } 33 34 public void invoke(MessageContext context) 35 throws Exception 36 { 37 for (int i = 0; i < size(); i++ ) 38 { 39 Handler h = getHandler(i); 40 try 41 { 42 h.invoke(context); 43 } 44 catch (Exception e) 45 { 46 context.setProperty(this, new Integer(i)); 47 48 throw e; 49 } 50 } 51 } 52 53 public void handleFault(XFireFault e, MessageContext context) 54 { 55 int total = size(); 56 57 Integer exceptionPoint = (Integer) context.getProperty(this); 58 if (exceptionPoint != null) 59 total = exceptionPoint.intValue(); 60 61 for (int i = total; i >= 0; i-- ) 62 { 63 Handler h = getHandler(i); 64 h.handleFault(e, context); 65 } 66 } 67 68 public void addHandler(Handler handler) 69 { 70 handlers.add(handler); 71 } 72 73 public void remove(Handler handler) 74 { 75 handlers.remove(handler); 76 } 77 78 public Iterator iterator() 79 { 80 return handlers.iterator(); 81 } 82 }