1 48 49 50 package org.exolab.jms.tools.admin; 51 52 import java.awt.Component ; 53 import java.util.Enumeration ; 54 import java.util.Vector ; 55 56 import javax.swing.JOptionPane ; 57 58 import org.exolab.jms.administration.AdminConnectionFactory; 59 import org.exolab.jms.administration.JmsAdminServerIfc; 60 import org.exolab.jms.config.ConfigHelper; 61 import org.exolab.jms.config.ConfigurationManager; 62 import org.exolab.jms.config.Connector; 63 import org.exolab.jms.config.SecurityConfiguration; 64 import org.exolab.jms.config.types.SchemeType; 65 66 67 76 public class OnlineConnection extends AbstractAdminConnection { 77 78 private JmsAdminServerIfc _admin = null; 80 81 private Component _parent; 83 84 private String _connectionType; 86 87 88 94 public OnlineConnection(Component parent) throws OnlineConnectionException { 95 String username = "anonymous"; 96 String password = "anonymous"; 97 98 try { 99 if (_instance == null) { 100 Connector connector = ConfigurationManager.getConnector(); 101 SchemeType scheme = connector.getScheme(); 102 String url = ConfigHelper.getAdminURL( 103 scheme, ConfigurationManager.getConfig()); 104 105 SecurityConfiguration config = 106 ConfigurationManager.getConfig().getSecurityConfiguration(); 107 if (config.getSecurityEnabled()) { 108 CreateLogonDialog.instance().displayCreateLogon(); 109 110 if (CreateLogonDialog.instance().isConfirmed()) { 111 username = CreateLogonDialog.instance().getName(); 112 password = CreateLogonDialog.instance().getPassword(); 113 } 114 } 115 116 _admin = AdminConnectionFactory.create(url, username, password); 118 119 _parent = parent; 120 _instance = this; 121 } else { 122 throw new org.exolab.jms.tools.admin.OnlineConnectionException("Already connected"); 123 } 124 } catch (Exception err) { 125 throw new org.exolab.jms.tools.admin.OnlineConnectionException("Failed to connect: " + err.toString()); 126 } 127 } 128 129 135 public OnlineConnection(String username, String password) throws OnlineConnectionException { 136 try { 137 if (_instance == null) { 138 Connector connector = ConfigurationManager.getConnector(); 139 SchemeType scheme = connector.getScheme(); 140 String url = ConfigHelper.getAdminURL( 141 scheme, ConfigurationManager.getConfig()); 142 143 _admin = AdminConnectionFactory.create(url, username, password); 145 146 _instance = this; 147 } else { 148 throw new org.exolab.jms.tools.admin.OnlineConnectionException("Already connected"); 149 } 150 } catch (Exception err) { 151 throw new org.exolab.jms.tools.admin.OnlineConnectionException("Failed to connect: " + err.toString()); 152 } 153 } 154 155 162 private void displayError(Exception err, String st) { 163 JOptionPane.showMessageDialog 164 (_parent, st + "\n" + err, st, JOptionPane.ERROR_MESSAGE); 165 } 166 167 public void close() { 169 _admin.close(); 170 _instance = null; 171 _admin = null; 172 } 173 174 public boolean addDurableConsumer(String topic, String name) { 176 try { 177 return _admin.addDurableConsumer(topic, name); 178 } catch (javax.jms.JMSException error) { 179 if (error.getLinkedException() != null) { 180 error.getLinkedException().printStackTrace(); 181 } 182 displayError(error, "Failed to add consumer"); 183 return false; 184 } catch (Exception err) { 185 displayError(err, "Failed to add consumer " + name); 186 return false; 187 } 188 } 189 190 public boolean removeDurableConsumer(String name) { 192 try { 193 return _admin.removeDurableConsumer(name); 194 } catch (Exception err) { 195 displayError(err, "Failed to remove consumer " + name); 196 return false; 197 } 198 } 199 200 public boolean unregisterConsumer(String name) { 202 try { 203 return _admin.unregisterConsumer(name); 204 } catch (Exception err) { 205 displayError(err, "Failed to De-Activate consumer " + name); 206 return false; 207 } 208 } 209 210 public boolean isConnected(String name) { 212 try { 213 return _admin.isConnected(name); 214 } catch (Exception err) { 215 return false; 216 } 217 } 218 219 public Enumeration getAllDestinations() { 221 try { 222 Vector v = _admin.getAllDestinations(); 223 Enumeration e = null; 224 if (v != null) { 225 e = v.elements(); 226 } 227 return e; 228 } catch (Exception err) { 229 displayError(err, "Failed to getAllQueueTopics"); 230 return null; 231 } 232 } 233 234 public boolean addDestination(String destination, boolean isQueue) { 236 try { 237 return _admin.addDestination(destination, new Boolean (isQueue)); 238 } catch (Exception err) { 239 displayError(err, "Failed to add destination"); 240 return false; 241 } 242 } 243 244 public int getDurableConsumerMessageCount(String topic, String name) { 246 try { 247 return _admin.getDurableConsumerMessageCount(topic, name); 248 } catch (Exception err) { 249 displayError(err, "Failed in getDurableConsumerMessageCount"); 250 return -1; 251 } 252 } 253 254 public int getQueueMessageCount(String queue) { 256 try { 257 return _admin.getQueueMessageCount(queue); 258 } catch (Exception err) { 259 displayError(err, "Failed in getQueueMessageCount"); 260 return -1; 261 } 262 } 263 264 public boolean durableConsumerExists(String name) { 266 try { 267 return _admin.durableConsumerExists(name); 268 } catch (Exception err) { 269 displayError(err, "Failed in durableConsumerExists"); 270 } 271 272 return false; 273 } 274 275 public Enumeration getDurableConsumers(String topic) { 277 try { 278 Vector v = _admin.getDurableConsumers(topic); 279 Enumeration e = null; 280 if (v != null) { 281 e = v.elements(); 282 } 283 return e; 284 } catch (Exception err) { 285 displayError(err, "Failed in getDurableConsumers"); 286 return null; 287 } 288 } 289 290 public boolean removeDestination(String destination) { 292 try { 293 return _admin.removeDestination(destination); 294 } catch (Exception err) { 295 displayError(err, "Failed to destroy destination"); 296 return false; 297 } 298 } 299 300 public int purgeMessages() { 302 int result = -1; 303 try { 304 result = _admin.purgeMessages(); 305 } catch (Exception err) { 306 displayError(err, "Failed to purge messages from database"); 307 } 308 309 return result; 310 } 311 312 public void stopServer() { 314 try { 315 if (_admin == null) { 316 JOptionPane.showMessageDialog 317 (_parent, "Must connect with online mode \nto " 318 + "shutdown server", "Shutdown Error", 319 JOptionPane.ERROR_MESSAGE); 320 } else { 321 _admin.stopServer(); 322 _instance = null; 323 _admin = null; 324 } 325 } catch (Exception err) { 326 displayError(err, "Failed to Stop server"); 327 } 328 } 329 330 public boolean addUser(String username, String password) { 332 try { 333 return _admin.addUser(username, password); 334 } catch (javax.jms.JMSException error) { 335 if (error.getLinkedException() != null) { 336 error.getLinkedException().printStackTrace(); 337 } 338 displayError(error, "Failed to add user"); 339 return false; 340 } catch (Exception err) { 341 displayError(err, "Failed to add user " + username); 342 return false; 343 } 344 } 345 346 public boolean changePassword(String username, String password) { 348 try { 349 return _admin.changePassword(username, password); 350 } catch (javax.jms.JMSException error) { 351 if (error.getLinkedException() != null) { 352 error.getLinkedException().printStackTrace(); 353 } 354 displayError(error, "Failed to change password"); 355 return false; 356 } catch (Exception err) { 357 displayError(err, "Failed to change password for user " + username); 358 return false; 359 } 360 } 361 362 public boolean removeUser(String username) { 364 try { 365 return _admin.removeUser(username); 366 } catch (javax.jms.JMSException error) { 367 if (error.getLinkedException() != null) { 368 error.getLinkedException().printStackTrace(); 369 } 370 displayError(error, "Failed to remove user"); 371 return false; 372 } catch (Exception err) { 373 displayError(err, "Failed to remove user " + username); 374 return false; 375 } 376 } 377 378 public Enumeration getAllUsers() { 380 try { 381 Vector v = _admin.getAllUsers(); 382 Enumeration e = null; 383 if (v != null) { 384 e = v.elements(); 385 } 386 return e; 387 } catch (Exception err) { 388 displayError(err, "Failed to getAllUsers"); 389 return null; 390 } 391 } 392 393 } | Popular Tags |