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 2003 (C) Exoffice Technologies Inc. All Rights Reserved. 42 */ 43 44 package org.exolab.jms.server.mipc; 45 46 import java.io.Serializable; 47 import java.util.Vector; 48 49 import javax.naming.Binding; 50 import javax.naming.Context; 51 import javax.naming.Name; 52 import javax.naming.NameClassPair; 53 import javax.naming.NameParser; 54 import javax.naming.NamingException; 55 56 import org.apache.avalon.excalibur.naming.NamingProvider; 57 import org.apache.avalon.excalibur.naming.rmi.server.RMINamingProviderImpl; 58 59 import org.exolab.core.ipc.NotifierIfc; 60 61 62 /*** 63 * This class is responsible for interpreting JNDI requests and 64 * delegating them to the server, and passing back any necessary replies. 65 * 66 * @version $Revision: 1.3 $ $Date: 2003/08/17 01:32:26 $ 67 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 68 * @see org.exolab.jms.jndi.mipc.NameServiceProxy 69 * @see org.exolab.jms.jndi.mipc.IpcJndiInitialContextFactory 70 */ 71 public class NameServiceProvider implements NotifierIfc { 72 73 /*** 74 * The root context 75 */ 76 private Context _context; 77 78 /*** 79 * The naming provider to delegate requests to 80 */ 81 private NamingProvider _provider; 82 83 84 /*** 85 * Construct a new <code>NameServiceProvider</code> 86 * 87 * @param context the root context 88 */ 89 public NameServiceProvider(Context context) { 90 _context = context; 91 // use the RMI provider implementation, for convenience... 92 _provider = new RMINamingProviderImpl(context); 93 } 94 95 /*** 96 * A new request has been received. 97 * Carry out the request, and pass back any relevent data. 98 * 99 * @param object The data received, 100 * @param id The id of the calling connection, not used by the client. 101 * @return Object Return any requested result. This must never be null. 102 */ 103 public Serializable notify(Object object, String id) { 104 Vector v = (Vector) object; 105 String func = (String) v.get(1); 106 Serializable result = null; 107 108 try { 109 if (func.equals("getNameParser")) { 110 result = getNameParser(); 111 } else if (func.equals("bind")) { 112 result = bind((Name) v.get(3), (String) v.get(4), v.get(5)); 113 } else if (func.equals("rebind")) { 114 result = rebind((Name) v.get(3), (String) v.get(4), v.get(5)); 115 } else if (func.equals("createSubcontext")) { 116 result = createSubcontext((Name) v.get(3)); 117 } else if (func.equals("destroySubcontext")) { 118 result = destroySubcontext((Name) v.get(3)); 119 } else if (func.equals("list")) { 120 result = list((Name) v.get(3)); 121 } else if (func.equals("listBindings")) { 122 result = listBindings((Name) v.get(3)); 123 } else if (func.equals("lookup")) { 124 result = lookup((Name) v.get(3)); 125 } else if (func.equals("unbind")) { 126 result = unbind((Name) v.get(3)); 127 } else { 128 NamingException error = new NamingException( 129 "Unknown request received: " + func); 130 result = pack(Boolean.FALSE, error); 131 } 132 } catch (NamingException exception) { 133 result = pack(Boolean.FALSE, exception); 134 } catch (Exception exception) { 135 result = pack(Boolean.FALSE, new NamingException( 136 exception.getMessage())); 137 } 138 return result; 139 } 140 141 /*** 142 * The connection has been broken. 143 * 144 * @param The unique identifier of this connection. 145 */ 146 public void disconnection(String id) { 147 } 148 149 protected Vector getNameParser() throws NamingException, Exception { 150 NameParser parser = _provider.getNameParser(); 151 return pack(Boolean.TRUE, parser); 152 } 153 154 protected Vector bind(Name name, String className, Object object) 155 throws NamingException, Exception { 156 _provider.bind(name, className, object); 157 return pack(Boolean.TRUE, null); 158 } 159 160 protected Vector rebind(Name name, String className, Object object) 161 throws NamingException, Exception { 162 _provider.rebind(name, className, object); 163 return pack(Boolean.TRUE, null); 164 } 165 166 protected Vector createSubcontext(Name name) 167 throws NamingException, Exception { 168 Context context = _provider.createSubcontext(name); 169 return pack(Boolean.TRUE, context); 170 } 171 172 protected Vector destroySubcontext(Name name) 173 throws NamingException, Exception { 174 _provider.destroySubcontext(name); 175 return pack(Boolean.TRUE, null); 176 } 177 178 protected Vector list(Name name) throws NamingException, Exception { 179 NameClassPair[] pairs = _provider.list(name); 180 return pack(Boolean.TRUE, pairs); 181 } 182 183 protected Vector listBindings(Name name) 184 throws NamingException, Exception { 185 Binding[] bindings = _provider.listBindings(name); 186 return pack(Boolean.TRUE, bindings); 187 } 188 189 protected Vector lookup(Name name) 190 throws NamingException, Exception { 191 Object object = _provider.lookup(name); 192 return pack(Boolean.TRUE, object); 193 } 194 195 protected Vector unbind(Name name) 196 throws NamingException, Exception { 197 _provider.unbind(name); 198 return pack(Boolean.TRUE, null); 199 } 200 201 /*** 202 * Pack all the data that is required by the server in a vector. 203 * Set the size of the vector to be exactly the right size for efficiency. 204 * 205 * @param success Boolean indicating success or failure of request. 206 * @param ob The Object being returned. 207 * @return Vector The vector containing all the data. 208 * 209 */ 210 protected Vector pack(Boolean success, Object ob) { 211 Vector v = new Vector(2); 212 v.add(success); 213 v.add(ob); 214 return v; 215 } 216 217 } //-- NameServiceProvider

This page was automatically generated by Maven