View Javadoc
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 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: OnlineConnection.java,v 1.6 2003/08/17 01:32:23 tanderson Exp $ 44 * 45 * Date Author Changes 46 * $Date jimm Created 47 */ 48 49 50 package org.exolab.jms.jndiadministration; 51 52 import java.awt.Component; 53 import java.util.Enumeration; 54 import java.util.Hashtable; 55 56 import javax.naming.Context; 57 import javax.naming.InitialContext; 58 import javax.swing.JOptionPane; 59 60 import org.exolab.jms.config.AdminConfiguration; 61 import org.exolab.jms.config.Configuration; 62 63 64 /*** 65 * Connects to the OpenJMSServer for all updates and requests. 66 * 67 * <P>Note: The OpenJMSServer must be active and in a running state for this 68 * type of connection to succeed. 69 * 70 * @version $Revision: 1.6 $ $Date: 2003/08/17 01:32:23 $ 71 * @author <a href="mailto:mourikis@exolab.org">Jim Mourikis</a> 72 * @see AdminConnection 73 * @see AdminMgr 74 */ 75 public class OnlineConnection extends AdminConnection { 76 77 // The deafult JNDI context. 78 private Context context_ = null; 79 80 // The parent Gui 81 private Component parent_; 82 83 /*** 84 * Connect to the Admin Server 85 * 86 * @exception OnlineConnectionException When online connection fails. 87 * 88 */ 89 public OnlineConnection(Component parent) throws OnlineConnectionException { 90 try { 91 if (instance_ == null) { 92 93 parent_ = parent; 94 instance_ = this; 95 if (context_ == null) { 96 // connect to the JNDI server and get a 97 // reference to root context 98 Hashtable props = new Hashtable(); 99 props.put(Context.INITIAL_CONTEXT_FACTORY, 100 "org.exolab.jms.jndi.rmi.RmiJndiInitialContextFactory"); 101 context_ = new InitialContext(props); 102 } 103 } else { 104 throw new OnlineConnectionException("Already connected"); 105 } 106 } catch (Exception err) { 107 throw new OnlineConnectionException("Failed to connect: " + err); 108 } 109 } 110 111 112 /*** 113 * Display the error in a JOptionPane. 114 * 115 * @param err The Error to display. 116 * @param st The string to use as a title on the JOptionPane. 117 * 118 */ 119 private void displayError(Exception err, String st) { 120 JOptionPane.showMessageDialog 121 (parent_, st + "\n" + err, st, JOptionPane.ERROR_MESSAGE); 122 } 123 124 125 /*** 126 * Close the connection. 127 * 128 */ 129 public void close() { 130 try { 131 context_.close(); 132 instance_ = null; 133 context_ = null; 134 } catch (javax.naming.NamingException err) { 135 displayError(err, "Failed to close context"); 136 } 137 } 138 139 /*** 140 * Get an enumerated list of all the Contexts 141 * 142 * @return Enumeration The list of contexts 143 * 144 */ 145 public Enumeration getAllContexts(String name) { 146 try { 147 if (name == null) { 148 name = ""; 149 } 150 151 return context_.list(name); 152 } catch (Exception err) { 153 System.err.println("Err in getAllContexts\n" + err); 154 return null; 155 } 156 } 157 158 /*** 159 * Return the object associated with this context. 160 * if none exists return null. 161 * 162 * @param context The context name 163 * @return Object The object for this context. 164 * 165 */ 166 public Object lookup(String context) { 167 try { 168 return context_.lookup(context); 169 } catch (Exception err) { 170 System.err.println("Failed to get Context " + context + "\n" + 171 err); 172 return null; 173 } 174 } 175 176 177 /*** 178 * Create a new context with the given name. 179 * 180 * @param name The new context name. 181 * @exception NamingException If the context cannot be created. 182 * 183 */ 184 public void createContext(String name) throws javax.naming.NamingException { 185 context_.createSubcontext(name); 186 } 187 188 189 /*** 190 * Destroy context with the given name. 191 * 192 * @param name The new context name. 193 * @exception NamingException If the context cannot be created. 194 * 195 */ 196 public void destroyContext(String name) throws javax.naming.NamingException { 197 context_.destroySubcontext(name); 198 } 199 200 201 /*** 202 * Rename context with the given name. 203 * 204 * @param oldName The old context name 205 * @param newName The new context name 206 * @exception NamingException If the context cannot be created. 207 * 208 */ 209 public void renameContext(String oldName, String newName) 210 throws javax.naming.NamingException { 211 context_.rename(oldName, newName); 212 } 213 214 215 /*** 216 * Rebind the context with the given object. 217 * 218 * @param name The context name 219 * @param ob The object to bind in this context 220 * @exception NamingException If the context cannot be created. 221 * 222 */ 223 public void rebind(String name, Object ob) 224 throws javax.naming.NamingException { 225 context_.rebind(name, ob); 226 } 227 228 } // End OnlineConnection

This page was automatically generated by Maven