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.5 2005/11/18 03:29:41 tanderson Exp $
44 */
45 package org.exolab.jms.client.net;
46
47 import java.rmi.RemoteException;
48 import javax.jms.InvalidClientIDException;
49 import javax.jms.JMSException;
50
51 import org.exolab.jms.net.orb.ORB;
52 import org.exolab.jms.net.proxy.Proxy;
53 import org.exolab.jms.server.ServerConnection;
54 import org.exolab.jms.server.ServerSession;
55
56
57 /***
58 * Wraps a {@link ServerConnection}.
59 *
60 * @author <a href="mailto:jima@comware.com.au">Jim Alateras</a>
61 * @version $Revision: 1.5 $ $Date: 2005/11/18 03:29:41 $
62 */
63 public class JmsConnectionStubImpl
64 implements ServerConnection {
65
66 /***
67 * The connection to delegate calls to.
68 */
69 private ServerConnection _connection;
70
71 /***
72 * The ORB to export objects with.
73 */
74 private final ORB _orb;
75
76 /***
77 * The URI to export objects to.
78 */
79 private final String _uri;
80
81 /***
82 * The security principal. May be <code>null</code>
83 */
84 private final String _principal;
85
86 /***
87 * The security credentials. May be <code>null</code>.
88 */
89 private final String _credentials;
90
91
92 /***
93 * Construct a new <code>JmsConnectionStubImpl</code>.
94 *
95 * @param connection the connection to delegate calls to
96 * @param orb the ORB to export objects with
97 * @param uri the URI to export objects on
98 * @param principal the security principal. May be <code>null</code>
99 * @param credentials the security credentials. May be <code>null</code>
100 */
101 public JmsConnectionStubImpl(ServerConnection connection,
102 ORB orb, String uri, String principal,
103 String credentials) {
104 if (connection == null) {
105 throw new IllegalArgumentException("Argument 'connection' is null");
106 }
107 _connection = connection;
108 _orb = orb;
109 _uri = uri;
110 _principal = principal;
111 _credentials = credentials;
112 }
113
114 /***
115 * Returns the connection identifier
116 *
117 * @return the connection identifier
118 * @throws JMSException for any JMS error
119 */
120 public long getConnectionId() throws JMSException {
121 return _connection.getConnectionId();
122 }
123
124 /***
125 * Returns the client identifier
126 *
127 * @return the client identifier
128 * @throws JMSException for any JMS error
129 */
130 public String getClientID() throws JMSException {
131 return _connection.getClientID();
132 }
133
134 /***
135 * Sets the client identifier for this connection.
136 *
137 * @param clientID the unique client identifier
138 * @throws JMSException if the JMS provider fails to set the
139 * client ID for this connection due to
140 * some internal error.
141 * @throws InvalidClientIDException if the JMS client specifies an invalid
142 * or duplicate client ID.
143 * @throws IllegalStateException if the JMS client attempts to set a
144 * connection's client ID at the wrong time
145 * or when it has been administratively
146 * configured.
147 */
148 public void setClientID(String clientID) throws JMSException {
149 _connection.setClientID(clientID);
150 }
151
152 /***
153 * Create a new session.
154 *
155 * @param acknowledgeMode indicates whether the consumer or the client will
156 * acknowledge any messages it receives; ignored if
157 * the session is transacted. Legal values are
158 * <code>Session.AUTO_ACKNOWLEDGE</code>,
159 * <code>Session.CLIENT_ACKNOWLEDGE</code>, and
160 * <code>Session.DUPS_OK_ACKNOWLEDGE</code>.
161 * @param transacted indicates whether the session is transacted
162 * @return a newly created session
163 * @throws JMSException for any JMS error
164 */
165 public ServerSession createSession(int acknowledgeMode, boolean transacted)
166 throws JMSException {
167 JmsSessionStubImpl result = null;
168 try {
169 ServerSession session = _connection.createSession(acknowledgeMode,
170 transacted);
171 result = new JmsSessionStubImpl(session, _orb, _uri, _principal,
172 _credentials);
173 } catch (RemoteException exception) {
174
175 throw new JMSException("Failed to create session: " + exception);
176 }
177
178 return result;
179 }
180
181 /***
182 * Closes the connection.
183 *
184 * @throws JMSException for any JMS error
185 */
186 public void close() throws JMSException {
187 try {
188 _connection.close();
189 } finally {
190 if (_connection instanceof Proxy) {
191 ((Proxy) _connection).disposeProxy();
192 }
193 _connection = null;
194 }
195 }
196
197
198 }