Source for org.omg.CosNaming._NamingContextImplBase

   1: /* _NamingContextImplBase.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.BAD_OPERATION;
  42: import org.omg.CORBA.CompletionStatus;
  43: import org.omg.CORBA.DynamicImplementation;
  44: import org.omg.CORBA.ObjectHelper;
  45: import org.omg.CORBA.ObjectHolder;
  46: import org.omg.CORBA.ServerRequest;
  47: import org.omg.CORBA.portable.InputStream;
  48: import org.omg.CORBA.portable.InvokeHandler;
  49: import org.omg.CORBA.portable.OutputStream;
  50: import org.omg.CORBA.portable.ResponseHandler;
  51: import org.omg.CORBA.portable.Streamable;
  52: import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
  53: import org.omg.CosNaming.NamingContextPackage.AlreadyBoundHelper;
  54: import org.omg.CosNaming.NamingContextPackage.CannotProceed;
  55: import org.omg.CosNaming.NamingContextPackage.CannotProceedHelper;
  56: import org.omg.CosNaming.NamingContextPackage.InvalidName;
  57: import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper;
  58: import org.omg.CosNaming.NamingContextPackage.NotEmpty;
  59: import org.omg.CosNaming.NamingContextPackage.NotEmptyHelper;
  60: import org.omg.CosNaming.NamingContextPackage.NotFound;
  61: import org.omg.CosNaming.NamingContextPackage.NotFoundHelper;
  62: 
  63: import java.util.Hashtable;
  64: 
  65: /**
  66:  * The naming context implementation base.
  67:  *
  68:  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  69:  */
  70: public abstract class _NamingContextImplBase
  71:   extends DynamicImplementation
  72:   implements NamingContext, InvokeHandler
  73: {
  74:   /**
  75:    * Use serialVersionUID (v1.4) for interoperability.
  76:    */
  77:   private static final long serialVersionUID = -114280294134561035L;
  78: 
  79:   /**
  80:    * As there are quite many methods, it may be sensible to use the hashtable.
  81:    */
  82:   private static Hashtable methods = new Hashtable();
  83: 
  84:   /**
  85:    * Put all methods into the table.
  86:    */
  87:   static
  88:   {
  89:     methods.put("bind", new Integer(0));
  90:     methods.put("rebind", new Integer(1));
  91:     methods.put("bind_context", new Integer(2));
  92:     methods.put("rebind_context", new Integer(3));
  93:     methods.put("resolve", new Integer(4));
  94:     methods.put("unbind", new Integer(5));
  95:     methods.put("new_context", new Integer(6));
  96:     methods.put("bind_new_context", new Integer(7));
  97:     methods.put("destroy", new Integer(8));
  98:     methods.put("list", new Integer(9));
  99:   }
 100: 
 101:   /**
 102:    * Return the array of repository ids.
 103:    */
 104:   public String[] _ids()
 105:   {
 106:     return new String[] { NamingContextHelper.id() };
 107:   }
 108: 
 109:   /**
 110:    * The server calls this method after receiving the request message
 111:    * from client. The implementation base calls one of its abstract
 112:    * methods to perform the requested operation.
 113:    *
 114:    * @param method the method being invoked.
 115:    * @param in the stream to read parameters from.
 116:    * @param rh the handler to get a stream for writing a response.
 117:    *
 118:    * @return the stream, returned by the handler.
 119:    */
 120:   public OutputStream _invoke(String method, InputStream in, ResponseHandler rh)
 121:   {
 122:     OutputStream out = null;
 123:     Integer call_method = (Integer) methods.get(method);
 124:     if (call_method == null)
 125:       throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
 126: 
 127:     switch (call_method.intValue())
 128:       {
 129:         case 0 : // bind
 130:         {
 131:           try
 132:             {
 133:               NameComponent[] a_name = NameHelper.read(in);
 134:               org.omg.CORBA.Object an_object = ObjectHelper.read(in);
 135:               bind(a_name, an_object);
 136:               out = rh.createReply();
 137:             }
 138:           catch (NotFound ex)
 139:             {
 140:               out = rh.createExceptionReply();
 141:               NotFoundHelper.write(out, ex);
 142:             }
 143:           catch (CannotProceed ex)
 144:             {
 145:               out = rh.createExceptionReply();
 146:               CannotProceedHelper.write(out, ex);
 147:             }
 148:           catch (InvalidName ex)
 149:             {
 150:               out = rh.createExceptionReply();
 151:               InvalidNameHelper.write(out, ex);
 152:             }
 153:           catch (AlreadyBound ex)
 154:             {
 155:               out = rh.createExceptionReply();
 156:               AlreadyBoundHelper.write(out, ex);
 157:             }
 158:           break;
 159:         }
 160: 
 161:         case 1 : // rebind
 162:         {
 163:           try
 164:             {
 165:               NameComponent[] a_name = NameHelper.read(in);
 166:               org.omg.CORBA.Object an_object = ObjectHelper.read(in);
 167:               rebind(a_name, an_object);
 168:               out = rh.createReply();
 169:             }
 170:           catch (NotFound ex)
 171:             {
 172:               out = rh.createExceptionReply();
 173:               NotFoundHelper.write(out, ex);
 174:             }
 175:           catch (CannotProceed ex)
 176:             {
 177:               out = rh.createExceptionReply();
 178:               CannotProceedHelper.write(out, ex);
 179:             }
 180:           catch (InvalidName ex)
 181:             {
 182:               out = rh.createExceptionReply();
 183:               InvalidNameHelper.write(out, ex);
 184:             }
 185:           break;
 186:         }
 187: 
 188:         case 2 : // bind_context
 189:         {
 190:           try
 191:             {
 192:               NameComponent[] a_name = NameHelper.read(in);
 193:               NamingContext a_context = NamingContextHelper.read(in);
 194:               bind_context(a_name, a_context);
 195:               out = rh.createReply();
 196:             }
 197:           catch (NotFound ex)
 198:             {
 199:               out = rh.createExceptionReply();
 200:               NotFoundHelper.write(out, ex);
 201:             }
 202:           catch (CannotProceed ex)
 203:             {
 204:               out = rh.createExceptionReply();
 205:               CannotProceedHelper.write(out, ex);
 206:             }
 207:           catch (InvalidName ex)
 208:             {
 209:               out = rh.createExceptionReply();
 210:               InvalidNameHelper.write(out, ex);
 211:             }
 212:           catch (AlreadyBound ex)
 213:             {
 214:               out = rh.createExceptionReply();
 215:               AlreadyBoundHelper.write(out, ex);
 216:             }
 217:           break;
 218:         }
 219: 
 220:         case 3 : // rebind_context
 221:         {
 222:           try
 223:             {
 224:               NameComponent[] a_name = NameHelper.read(in);
 225:               NamingContext a_context = NamingContextHelper.read(in);
 226:               rebind_context(a_name, a_context);
 227:               out = rh.createReply();
 228:             }
 229:           catch (NotFound ex)
 230:             {
 231:               out = rh.createExceptionReply();
 232:               NotFoundHelper.write(out, ex);
 233:             }
 234:           catch (CannotProceed ex)
 235:             {
 236:               out = rh.createExceptionReply();
 237:               CannotProceedHelper.write(out, ex);
 238:             }
 239:           catch (InvalidName ex)
 240:             {
 241:               out = rh.createExceptionReply();
 242:               InvalidNameHelper.write(out, ex);
 243:             }
 244:           break;
 245:         }
 246: 
 247:         case 4 : // resolve
 248:         {
 249:           try
 250:             {
 251:               NameComponent[] a_name = NameHelper.read(in);
 252:               org.omg.CORBA.Object __result = null;
 253:               __result = resolve(a_name);
 254:               out = rh.createReply();
 255:               ObjectHelper.write(out, __result);
 256:             }
 257:           catch (NotFound ex)
 258:             {
 259:               out = rh.createExceptionReply();
 260:               NotFoundHelper.write(out, ex);
 261:             }
 262:           catch (CannotProceed ex)
 263:             {
 264:               out = rh.createExceptionReply();
 265:               CannotProceedHelper.write(out, ex);
 266:             }
 267:           catch (InvalidName ex)
 268:             {
 269:               out = rh.createExceptionReply();
 270:               InvalidNameHelper.write(out, ex);
 271:             }
 272:           break;
 273:         }
 274: 
 275:         case 5 : // unbind
 276:         {
 277:           try
 278:             {
 279:               NameComponent[] a_name = NameHelper.read(in);
 280:               unbind(a_name);
 281:               out = rh.createReply();
 282:             }
 283:           catch (NotFound ex)
 284:             {
 285:               out = rh.createExceptionReply();
 286:               NotFoundHelper.write(out, ex);
 287:             }
 288:           catch (CannotProceed ex)
 289:             {
 290:               out = rh.createExceptionReply();
 291:               CannotProceedHelper.write(out, ex);
 292:             }
 293:           catch (InvalidName ex)
 294:             {
 295:               out = rh.createExceptionReply();
 296:               InvalidNameHelper.write(out, ex);
 297:             }
 298:           break;
 299:         }
 300: 
 301:         case 6 : // new_context
 302:         {
 303:           NamingContext __result = null;
 304:           __result = new_context();
 305:           out = rh.createReply();
 306:           NamingContextHelper.write(out, __result);
 307:           break;
 308:         }
 309: 
 310:         case 7 : // bind_new_context
 311:         {
 312:           try
 313:             {
 314:               NameComponent[] a_name = NameHelper.read(in);
 315:               NamingContext __result = null;
 316:               __result = bind_new_context(a_name);
 317:               out = rh.createReply();
 318:               NamingContextHelper.write(out, __result);
 319:             }
 320:           catch (NotFound ex)
 321:             {
 322:               out = rh.createExceptionReply();
 323:               NotFoundHelper.write(out, ex);
 324:             }
 325:           catch (AlreadyBound ex)
 326:             {
 327:               out = rh.createExceptionReply();
 328:               AlreadyBoundHelper.write(out, ex);
 329:             }
 330:           catch (CannotProceed ex)
 331:             {
 332:               out = rh.createExceptionReply();
 333:               CannotProceedHelper.write(out, ex);
 334:             }
 335:           catch (InvalidName ex)
 336:             {
 337:               out = rh.createExceptionReply();
 338:               InvalidNameHelper.write(out, ex);
 339:             }
 340:           break;
 341:         }
 342: 
 343:         case 8 : // destroy
 344:         {
 345:           try
 346:             {
 347:               destroy();
 348:               out = rh.createReply();
 349:             }
 350:           catch (NotEmpty ex)
 351:             {
 352:               out = rh.createExceptionReply();
 353:               NotEmptyHelper.write(out, ex);
 354:             }
 355:           break;
 356:         }
 357: 
 358:         case 9 : // list
 359:         {
 360:           int amount = in.read_ulong();
 361:           BindingListHolder a_list = new BindingListHolder();
 362:           BindingIteratorHolder an_iter = new BindingIteratorHolder();
 363:           list(amount, a_list, an_iter);
 364:           out = rh.createReply();
 365:           BindingListHelper.write(out, a_list.value);
 366:           BindingIteratorHelper.write(out, an_iter.value);
 367:           break;
 368:         }
 369: 
 370:         default :
 371:           throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
 372:       }
 373: 
 374:     return out;
 375:   }
 376: 
 377:   /**
 378:    * The obsolete invocation using server request. Implemented for
 379:    * compatibility reasons, but is it more effectinve to use
 380:    * {@link #_invoke}.
 381:    *
 382:    * @param request a server request.
 383:    */
 384:   public void invoke(ServerRequest request)
 385:   {
 386:     Streamable result = null;
 387: 
 388:     // The server request contains no required result type.
 389:     Integer call_method = (Integer) methods.get(request.operation());
 390:     if (call_method == null)
 391:       throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
 392: 
 393:     switch (call_method.intValue())
 394:       {
 395:         case 4 : // resolve, object
 396:           result = new ObjectHolder();
 397:           break;
 398: 
 399:         case 6 : // new_context, NamingContext
 400:         case 7 : // bind_new_context, NamingContext
 401:         {
 402:           result = new NamingContextHolder();
 403:           break;
 404:         }
 405: 
 406:         default : // void for others.
 407:           result = null;
 408:       }
 409: 
 410:     gnu.CORBA.ServiceRequestAdapter.invoke(request, this, result);
 411:   }