KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > mom > proxies > TopicSubscription


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2003 - 2005 ScalAgent Distributed Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): Frederic Maistre (INRIA)
21  * Contributor(s): ScalAgent Distributed Technologies
22  */

23 package org.objectweb.joram.mom.proxies;
24
25 import fr.dyade.aaa.agent.AgentId;
26
27 import java.util.Enumeration JavaDoc;
28 import java.util.Hashtable JavaDoc;
29
30
31 /**
32  * The <code>TopicSubscription</code> class holds the parameters of a proxy's
33  * subscription to a topic.
34  */

35 class TopicSubscription {
36   /** Table of subscriptions selectors. */
37   private Hashtable JavaDoc subs;
38   /** Last built selector. */
39   private String JavaDoc lastSelector = null;
40
41
42   /**
43    * Creates a <code>TopicSubscription</code> instance.
44    */

45   TopicSubscription() {
46     this.subs = new Hashtable JavaDoc();
47   }
48
49  
50   /**
51    * Adds a new subscription or updates an existing one.
52    *
53    * @param name Subscription name.
54    * @param selector Selector.
55    */

56   void putSubscription(String JavaDoc name, String JavaDoc selector) {
57     if (selector == null)
58       selector = "";
59     subs.put(name, selector);
60   }
61
62   /**
63    * Removes a subscription.
64    *
65    * @param name Subscription name.
66    */

67   void removeSubscription(String JavaDoc name) {
68     subs.remove(name);
69   }
70
71   /** Returns <code>true</code> if the subscriptions table is empty. */
72   boolean isEmpty() {
73     return subs.isEmpty();
74   }
75
76   /** Returns a selector built from the subscriptions' selectors. */
77   String JavaDoc buildSelector() {
78     String JavaDoc currentSel;
79     String JavaDoc builtSelector = null;
80     for (Enumeration JavaDoc names = subs.keys(); names.hasMoreElements();) {
81       currentSel = (String JavaDoc) subs.get(names.nextElement());
82
83       if (currentSel.equals("")) return "";
84       
85       if (builtSelector == null)
86         builtSelector = "(" + currentSel + ")";
87       else
88         builtSelector = builtSelector + " OR (" + currentSel + ")";
89        
90     }
91     return builtSelector;
92   }
93
94   /** Sets the last selector value. */
95   void setLastSelector(String JavaDoc selector) {
96     this.lastSelector = selector;
97   }
98
99   /** Returns the last selector value. */
100   String JavaDoc getLastSelector() {
101     return lastSelector;
102   }
103
104   /** Returns the names of the subscriptions. */
105   Enumeration JavaDoc getNames() {
106     return subs.keys();
107   }
108 }
109
Popular Tags