01: package tools.sniffer;
02:
03: import java.util.*;
04:
05: /**
06: * A list of Sniff Sessions.
07: * Acknowledgement:
08: * This code was contributed by Tim Bardzil <bardzil@colorado.edu>.
09: * This code was completed as part of a class project in TLEN 5843
10: * Singaling Protocols, taught by Professor Douglas C. Sicker, Ph.D. at
11: * the University of Colorado, Boulder.
12: * Minor modifications to the code were made by M. Ranganathan .
13: *
14: *@author Tim Bardzil <bardzil@colorado.edu>
15: *
16: */
17:
18: public class SniffSessionList extends ArrayList {
19:
20: /**
21: * Add a new SniffMessage to the SniffSessionList.
22: * Create a new Sniff Session if this is a new call id.
23: */
24: public void add(SniffMessage sniffMessage) {
25: boolean newSession = true;
26: ListIterator i = super .listIterator();
27: while (i.hasNext()) {
28: SniffMessageList temp = (SniffMessageList) i.next();
29: if (temp.getCallID().equals(sniffMessage.getCallID())) {
30: temp.add(sniffMessage);
31: newSession = false;
32: }
33: }
34: if (newSession == true) {
35: SniffMessageList newMessageList = new SniffMessageList();
36: newMessageList.add(sniffMessage);
37: super .add(newMessageList);
38: }
39: }
40:
41: /**
42: * Return a string consisting of formatted messages that can be fed
43: * to the trace viewer.
44: */
45: public String toXML() {
46: ListIterator li = super .listIterator();
47: String xmlMessages = "<description\n " + "logDescription = "
48: + "\" sniffer capture " + "\"\n name = "
49: + "\" snifferTrace \" /> \n";
50: int i = 0;
51: while (li.hasNext()) {
52: SniffMessageList sml = (SniffMessageList) li.next();
53: xmlMessages += sml.toXML();
54: }
55: return xmlMessages;
56: }
57:
58: /**
59: * Return an array of call identifiers for the traces.
60: */
61: public String[] getCallIds() {
62: ListIterator li = super .listIterator();
63: String[] retval = new String[this .size()];
64: int i = 0;
65: while (li.hasNext()) {
66: SniffMessageList temp = (SniffMessageList) li.next();
67: retval[i++] = temp.getCallID();
68: }
69: return retval;
70: }
71: }
|