1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.dynamic;
3
4 import org.jmock.expectation.Verifiable;
5
6 import java.util.ArrayList;
7 import java.util.Iterator;
8 import java.util.ListIterator;
9
10 public class LIFOInvocationDispatcher implements InvocationDispatcher {
11
12 private ArrayList invokables = new ArrayList();
13
14 public Object dispatch(Invocation invocation) throws Throwable {
15 ListIterator i = invokables.listIterator(invokables.size());
16 while (i.hasPrevious()) {
17 Invokable invokable = (Invokable) i.previous();
18 if (invokable.matches(invocation)) {
19 return invokable.invoke(invocation);
20 }
21 }
22 throw new DynamicMockError(invocation, "No match found");
23 }
24
25 public void add(Invokable invokable) {
26 invokables.add(invokable);
27 }
28
29 public void verify() {
30 Iterator i = invokables.iterator();
31 while (i.hasNext()) {
32 ((Verifiable) i.next()).verify();
33 }
34 }
35
36 public void clear() {
37 invokables.clear();
38 }
39
40 }
This page was automatically generated by Maven