KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > jms > TemporaryTopic


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

24 package org.objectweb.joram.client.jms;
25
26 import java.util.Vector JavaDoc;
27 import java.util.Hashtable JavaDoc;
28
29 import javax.jms.JMSException JavaDoc;
30 import javax.jms.JMSSecurityException JavaDoc;
31 import javax.naming.NamingException JavaDoc;
32
33 import org.objectweb.joram.shared.client.TempDestDeleteRequest;
34
35 import org.objectweb.util.monolog.api.BasicLevel;
36 import org.objectweb.joram.shared.JoramTracing;
37
38 /**
39  * Implements the <code>javax.jms.TemporaryTopic</code> interface.
40  */

41 public class TemporaryTopic extends Topic implements javax.jms.TemporaryTopic JavaDoc
42 {
43   private final static String JavaDoc TMP_TOPIC_TYPE = "topic.tmp";
44
45   public static boolean isTemporaryTopic(String JavaDoc type) {
46     return Destination.isAssignableTo(type, TMP_TOPIC_TYPE);
47   }
48
49   /** The connection the topic belongs to, <code>null</code> if not known. */
50   private Connection cnx;
51
52   // Used by jndi2 SoapObjectHelper
53
public TemporaryTopic() {}
54
55   /**
56    * Constructs a temporary topic.
57    *
58    * @param agentId Identifier of the topic agent.
59    * @param cnx The connection the queue belongs to, <code>null</code> if
60    * not known.
61    */

62   public TemporaryTopic(String JavaDoc agentId, Connection cnx) {
63     super(agentId, TMP_TOPIC_TYPE);
64     this.cnx = cnx;
65   }
66
67   /** Returns a String image of the topic. */
68   public String JavaDoc toString()
69   {
70     return "TempTopic:" + agentId;
71   }
72
73   /**
74    * API method.
75    *
76    * @exception IllegalStateException If the connection is closed or broken.
77    * @exception JMSException If the request fails for any other reason.
78    */

79   public void delete() throws JMSException JavaDoc
80   {
81     if (cnx == null)
82       throw new JMSSecurityException JavaDoc("Forbidden call as this TemporaryQueue"
83                                      + " does not belong to this connection.");
84
85     if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
86       JoramTracing.dbgClient.log(BasicLevel.DEBUG, "--- " + this
87                                  + ": deleting...");
88
89     // Checking the connection's subscribers:
90
cnx.checkConsumers(agentId);
91
92     // Sending the request to the server:
93
cnx.syncRequest(new TempDestDeleteRequest(agentId));
94
95     if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
96       JoramTracing.dbgClient.log(BasicLevel.DEBUG, this + ": deleted.");
97   }
98
99   /**
100    * Returns the connection this temporary topic belongs to,
101    * <code>null</code> if not known.
102    */

103   Connection getCnx()
104   {
105     return cnx;
106   }
107 }
108
Popular Tags