01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26: package gov.nist.siplite.stack;
27:
28: import java.util.*;
29: import gov.nist.core.*;
30: import gov.nist.siplite.header.*;
31: import gov.nist.siplite.message.*;
32:
33: /**
34: * Class representing a list of subscription.
35: */
36: public class SubscriptionList {
37: /** Vector of the active subscriptions */
38: private Vector subscriptionVector;
39:
40: /**
41: * Default constructor.
42: */
43: public SubscriptionList() {
44: subscriptionVector = new Vector();
45: }
46:
47: /**
48: * Checks if the subscription list is empty.
49: * @return true if the subscription list is empty, false otherwise
50: */
51: public boolean isEmpty() {
52: return subscriptionVector.isEmpty();
53: }
54:
55: /**
56: * Removes the given subscription from the list.
57: * @param s a subscription to remove
58: */
59: public void removeSubscription(Subscription s) {
60: if (s != null) {
61: // System.out.println("*** Removing SUBSCRIPTION");
62: subscriptionVector.removeElement(s);
63: }
64: }
65:
66: /**
67: * Adds a new subscription to the list.
68: * @param s a subscription to add
69: */
70: public void addSubscription(Subscription s) {
71: if (s != null) {
72: // System.out.println("*** Adding a new SUBSCRIPTION");
73: subscriptionVector.addElement(s);
74: }
75: }
76:
77: /**
78: * Finds a subscription matching the given response or NOTIFY.
79: * @param message response or NOTIFY message
80: * @return a subscription matching to the given response or NOTIFY
81: * or null if the subscription was not found
82: */
83: public Subscription getMatchingSubscription(Message message) {
84: Enumeration en = subscriptionVector.elements();
85:
86: while (en.hasMoreElements()) {
87: Subscription s = (Subscription) en.nextElement();
88: if (s.containsSubscription(message)) {
89: // System.out.println("*** Matching SUBSCRIPTION found!");
90: return s;
91: }
92: }
93:
94: // System.out.println("*** Matching SUBSCRIPTION NOT found!");
95: return null;
96: }
97: }
|