1 /* _NamingContextExtImplBase.java -- 2 Copyright (C) 2005 Free Software Foundation, Inc. 3 4 This file is part of GNU Classpath. 5 6 GNU Classpath is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Classpath is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Classpath; see the file COPYING. If not, write to the 18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301 USA. 20 21 Linking this library statically or dynamically with other modules is 22 making a combined work based on this library. Thus, the terms and 23 conditions of the GNU General Public License cover the whole 24 combination. 25 26 As a special exception, the copyright holders of this library give you 27 permission to link this library with independent modules to produce an 28 executable, regardless of the license terms of these independent 29 modules, and to copy and distribute the resulting executable under 30 terms of your choice, provided that you also meet, for each linked 31 independent module, the terms and conditions of the license of that 32 module. An independent module is a module which is not derived from 33 or based on this library. If you modify this library, you may extend 34 this exception to your version of the library, but you are not 35 obligated to do so. If you do not wish to do so, delete this 36 exception statement from your version. */ 37 38 39 package org.omg.CosNaming; 40 41 import org.omg.CORBA.ObjectHolder; 42 import org.omg.CORBA.ServerRequest; 43 import org.omg.CORBA.StringHolder; 44 import org.omg.CORBA.portable.InputStream; 45 import org.omg.CORBA.portable.InvokeHandler; 46 import org.omg.CORBA.portable.OutputStream; 47 import org.omg.CORBA.portable.ResponseHandler; 48 import org.omg.CORBA.portable.Streamable; 49 import org.omg.CosNaming.NamingContextExtPackage.InvalidAddress; 50 import org.omg.CosNaming.NamingContextExtPackage.InvalidAddressHelper; 51 import org.omg.CosNaming.NamingContextPackage.CannotProceed; 52 import org.omg.CosNaming.NamingContextPackage.CannotProceedHelper; 53 import org.omg.CosNaming.NamingContextPackage.InvalidName; 54 import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper; 55 import org.omg.CosNaming.NamingContextPackage.NotFound; 56 import org.omg.CosNaming.NamingContextPackage.NotFoundHelper; 57 58 import java.util.Hashtable; 59 60 /** 61 * The extended naming context implementation base. 62 * 63 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) 64 */ 65 public abstract class _NamingContextExtImplBase 66 extends _NamingContextImplBase 67 implements NamingContextExt, InvokeHandler 68 { 69 static Hashtable<String,Integer> _methods = new Hashtable<String,Integer>(); 70 71 static 72 { 73 _methods.put("to_string", new java.lang.Integer(0)); 74 _methods.put("to_name", new java.lang.Integer(1)); 75 _methods.put("to_url", new java.lang.Integer(2)); 76 _methods.put("resolve_str", new java.lang.Integer(3)); 77 } 78 79 /** 80 * This stub can be the base of the two CORBA objects, so it 81 * has two repository ids. 82 */ 83 private static String[] __ids = 84 { NamingContextExtHelper.id(), NamingContextHelper.id() }; 85 86 /** 87 * Return the array of repository ids for this object. 88 * This stub can be the base of the two CORBA objects, so it 89 * has two repository ids, for {@link NamingContext} and 90 * for {@link NamingContextExt}. 91 */ _ids()92 public String[] _ids() 93 { 94 return __ids; 95 } 96 _invoke(String method, InputStream in, ResponseHandler rh)97 public OutputStream _invoke(String method, InputStream in, ResponseHandler rh) 98 { 99 Integer call_method = _methods.get(method); 100 101 if (call_method == null) 102 103 // The older methods are handled by the parent class. 104 return super._invoke(method, in, rh); 105 106 OutputStream out = null; 107 108 switch (call_method.intValue()) 109 { 110 case 0 : // to_string 111 { 112 try 113 { 114 NameComponent[] a_name = NameHelper.read(in); 115 String result = null; 116 result = this.to_string(a_name); 117 out = rh.createReply(); 118 out.write_string(result); 119 } 120 catch (InvalidName ex) 121 { 122 out = rh.createExceptionReply(); 123 InvalidNameHelper.write(out, ex); 124 } 125 break; 126 } 127 128 case 1 : // to_name 129 { 130 try 131 { 132 String a_name_string = in.read_string(); 133 NameComponent[] result = to_name(a_name_string); 134 out = rh.createReply(); 135 NameHelper.write(out, result); 136 } 137 catch (InvalidName ex) 138 { 139 out = rh.createExceptionReply(); 140 InvalidNameHelper.write(out, ex); 141 } 142 break; 143 } 144 145 case 2 : // to_url 146 { 147 try 148 { 149 String an_address = in.read_string(); 150 String a_name_string = in.read_string(); 151 String result = to_url(an_address, a_name_string); 152 out = rh.createReply(); 153 out.write_string(result); 154 } 155 catch (InvalidAddress ex) 156 { 157 out = rh.createExceptionReply(); 158 InvalidAddressHelper.write(out, ex); 159 } 160 catch (InvalidName ex) 161 { 162 out = rh.createExceptionReply(); 163 InvalidNameHelper.write(out, ex); 164 } 165 break; 166 } 167 168 case 3 : // resolve_str 169 { 170 try 171 { 172 String a_name_string = in.read_string(); 173 org.omg.CORBA.Object result = resolve_str(a_name_string); 174 out = rh.createReply(); 175 org.omg.CORBA.ObjectHelper.write(out, result); 176 } 177 catch (NotFound ex) 178 { 179 out = rh.createExceptionReply(); 180 NotFoundHelper.write(out, ex); 181 } 182 catch (CannotProceed ex) 183 { 184 out = rh.createExceptionReply(); 185 CannotProceedHelper.write(out, ex); 186 } 187 catch (InvalidName ex) 188 { 189 out = rh.createExceptionReply(); 190 InvalidNameHelper.write(out, ex); 191 } 192 break; 193 } 194 } 195 return out; 196 } 197 198 /** 199 * The obsolete invocation using server request. Implemented for 200 * compatibility reasons, but is it more effectinve to use 201 * {@link #_invoke}. 202 * 203 * @param request a server request. 204 */ invoke(ServerRequest request)205 public void invoke(ServerRequest request) 206 { 207 Streamable result = null; 208 209 Integer call_method = _methods.get(request.operation()); 210 211 if (call_method == null) 212 { 213 super.invoke(request); 214 return; 215 } 216 217 switch (call_method.intValue()) 218 { 219 case 0 : // to_string, String 220 result = new StringHolder(); 221 break; 222 223 case 1 : // to_name, Name 224 result = new NameHolder(); 225 break; 226 227 case 2 : // to_url, String 228 result = new StringHolder(); 229 break; 230 231 case 3 : // resolve_str, Object 232 result = new ObjectHolder(); 233 break; 234 } 235 gnu.CORBA.ServiceRequestAdapter.invoke(request, this, result); 236 } 237 } 238