KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > client > net > JmsConnectionStubImpl


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2000-2005 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: JmsConnectionStubImpl.java,v 1.3 2005/05/24 13:36:37 tanderson Exp $
44  */

45 package org.exolab.jms.client.net;
46
47 import java.rmi.RemoteException JavaDoc;
48 import javax.jms.InvalidClientIDException JavaDoc;
49 import javax.jms.JMSException JavaDoc;
50
51 import org.exolab.jms.net.orb.ORB;
52 import org.exolab.jms.server.ServerConnection;
53 import org.exolab.jms.server.ServerSession;
54
55
56 /**
57  * Wraps a {@link ServerConnection}.
58  *
59  * @author <a HREF="mailto:jima@comware.com.au">Jim Alateras</a>
60  * @version $Revision: 1.3 $ $Date: 2005/05/24 13:36:37 $
61  */

62 public class JmsConnectionStubImpl
63         implements ServerConnection {
64
65     /**
66      * The server proxy.
67      */

68     private JmsServerStubImpl _server;
69
70     /**
71      * The connection to delegate calls to.
72      */

73     private ServerConnection _connection;
74
75     /**
76      * The ORB to export objects with.
77      */

78     private final ORB _orb;
79
80     /**
81      * The URI to export objects to.
82      */

83     private final String JavaDoc _uri;
84
85     /**
86      * The security principal. May be <code>null</code>
87      */

88     private final String JavaDoc _principal;
89
90     /**
91      * The security credentials. May be <code>null</code>.
92      */

93     private final String JavaDoc _credentials;
94
95
96     /**
97      * Construct a new <code>JmsConnectionStubImpl</code>.
98      *
99      * @param server the server proxy
100      * @param connection the connection to delegate calls to
101      * @param orb the ORB to export objects with
102      * @param uri the URI to export objects on
103      * @param principal the security principal. May be <code>null</code>
104      * @param credentials the security credentials. May be <code>null</code>
105      */

106     public JmsConnectionStubImpl(JmsServerStubImpl server,
107                                  ServerConnection connection,
108                                  ORB orb, String JavaDoc uri, String JavaDoc principal,
109                                  String JavaDoc credentials) {
110         if (server == null) {
111             throw new IllegalArgumentException JavaDoc("Argument 'server' is null");
112         }
113         if (connection == null) {
114             throw new IllegalArgumentException JavaDoc("Argument 'connection' is null");
115         }
116         _server = server;
117         _connection = connection;
118         _orb = orb;
119         _uri = uri;
120         _principal = principal;
121         _credentials = credentials;
122     }
123
124     /**
125      * Returns the connection identifier
126      *
127      * @return the connection identifier
128      * @throws JMSException for any JMS error
129      */

130     public long getConnectionId() throws JMSException JavaDoc {
131         return _connection.getConnectionId();
132     }
133
134     /**
135      * Returns the client identifier
136      *
137      * @return the client identifier
138      * @throws JMSException for any JMS error
139      */

140     public String JavaDoc getClientID() throws JMSException JavaDoc {
141         return _connection.getClientID();
142     }
143
144     /**
145      * Sets the client identifier for this connection.
146      *
147      * @param clientID the unique client identifier
148      * @throws JMSException if the JMS provider fails to set the
149      * client ID for this connection due to
150      * some internal error.
151      * @throws InvalidClientIDException if the JMS client specifies an invalid
152      * or duplicate client ID.
153      * @throws IllegalStateException if the JMS client attempts to set a
154      * connection's client ID at the wrong time
155      * or when it has been administratively
156      * configured.
157      */

158     public void setClientID(String JavaDoc clientID) throws JMSException JavaDoc {
159         _connection.setClientID(clientID);
160     }
161
162     /**
163      * Create a new session.
164      *
165      * @param transacted indicates whether the session is transacted
166      * @param acknowledgeMode indicates whether the consumer or the client will
167      * acknowledge any messages it receives; ignored if
168      * the session is transacted. Legal values are
169      * <code>Session.AUTO_ACKNOWLEDGE</code>,
170      * <code>Session.CLIENT_ACKNOWLEDGE</code>, and
171      * <code>Session.DUPS_OK_ACKNOWLEDGE</code>.
172      * @return a newly created session
173      * @throws JMSException for any JMS error
174      */

175     public ServerSession createSession(int acknowledgeMode, boolean transacted)
176             throws JMSException JavaDoc {
177         JmsSessionStubImpl result = null;
178         try {
179             ServerSession session = _connection.createSession(acknowledgeMode,
180                                                               transacted);
181             result = new JmsSessionStubImpl(session, _orb, _uri, _principal,
182                                             _credentials);
183         } catch (RemoteException JavaDoc exception) {
184             // rethrow as a JMSException
185
throw new JMSException JavaDoc("Failed to create session: " + exception);
186         }
187
188         return result;
189     }
190
191     /**
192      * Closes the connection.
193      *
194      * @throws JMSException for any JMS error
195      */

196     public void close() throws JMSException JavaDoc {
197         try {
198             _connection.close();
199         } finally {
200             _connection = null;
201         }
202     }
203
204
205 }
206
Popular Tags