001 /* _NamingContextExtImplBase.java -- 002 Copyright (C) 2005 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package org.omg.CosNaming; 040 041 import org.omg.CORBA.ObjectHolder; 042 import org.omg.CORBA.ServerRequest; 043 import org.omg.CORBA.StringHolder; 044 import org.omg.CORBA.portable.InputStream; 045 import org.omg.CORBA.portable.InvokeHandler; 046 import org.omg.CORBA.portable.OutputStream; 047 import org.omg.CORBA.portable.ResponseHandler; 048 import org.omg.CORBA.portable.Streamable; 049 import org.omg.CosNaming.NamingContextExtPackage.InvalidAddress; 050 import org.omg.CosNaming.NamingContextExtPackage.InvalidAddressHelper; 051 import org.omg.CosNaming.NamingContextPackage.CannotProceed; 052 import org.omg.CosNaming.NamingContextPackage.CannotProceedHelper; 053 import org.omg.CosNaming.NamingContextPackage.InvalidName; 054 import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper; 055 import org.omg.CosNaming.NamingContextPackage.NotFound; 056 import org.omg.CosNaming.NamingContextPackage.NotFoundHelper; 057 058 import java.util.Hashtable; 059 060 /** 061 * The extended naming context implementation base. 062 * 063 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) 064 */ 065 public abstract class _NamingContextExtImplBase 066 extends _NamingContextImplBase 067 implements NamingContextExt, InvokeHandler 068 { 069 static Hashtable<String,Integer> _methods = new Hashtable<String,Integer>(); 070 071 static 072 { 073 _methods.put("to_string", new java.lang.Integer(0)); 074 _methods.put("to_name", new java.lang.Integer(1)); 075 _methods.put("to_url", new java.lang.Integer(2)); 076 _methods.put("resolve_str", new java.lang.Integer(3)); 077 } 078 079 /** 080 * This stub can be the base of the two CORBA objects, so it 081 * has two repository ids. 082 */ 083 private static String[] __ids = 084 { NamingContextExtHelper.id(), NamingContextHelper.id() }; 085 086 /** 087 * Return the array of repository ids for this object. 088 * This stub can be the base of the two CORBA objects, so it 089 * has two repository ids, for {@link NamingContext} and 090 * for {@link NamingContextExt}. 091 */ 092 public String[] _ids() 093 { 094 return __ids; 095 } 096 097 public OutputStream _invoke(String method, InputStream in, ResponseHandler rh) 098 { 099 Integer call_method = (Integer) _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 */ 205 public void invoke(ServerRequest request) 206 { 207 Streamable result = null; 208 209 Integer call_method = (Integer) _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 }