Source for org.omg.CosNaming.NamingContextExtPOA

   1: /* NamingContextExtPOA.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 gnu.CORBA.Minor;
  42: 
  43: import org.omg.CORBA.BAD_OPERATION;
  44: import org.omg.CORBA.CompletionStatus;
  45: import org.omg.CORBA.ObjectHelper;
  46: import org.omg.CORBA.portable.InputStream;
  47: import org.omg.CORBA.portable.InvokeHandler;
  48: import org.omg.CORBA.portable.OutputStream;
  49: import org.omg.CORBA.portable.ResponseHandler;
  50: import org.omg.CosNaming.NamingContextExtPackage.InvalidAddress;
  51: import org.omg.CosNaming.NamingContextExtPackage.InvalidAddressHelper;
  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: import org.omg.PortableServer.POA;
  63: import org.omg.PortableServer.Servant;
  64: 
  65: /**
  66:  * The extended naming service servant. After implementing the abstract methods the
  67:  * instance of this class can be connected to an ORB using POA.
  68:  *
  69:  * @since 1.4
  70:  *
  71:  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  72:  */
  73: public abstract class NamingContextExtPOA
  74:   extends Servant
  75:   implements NamingContextExtOperations, InvokeHandler
  76: 
  77: {
  78:   /** @inheritDoc */
  79:   public String[] _all_interfaces(POA poa, byte[] object_ID)
  80:   {
  81:     return new String[] { NamingContextExtHelper.id(), NamingContextHelper.id() };
  82:   }
  83: 
  84:   /** @inheritDoc */
  85:   public OutputStream _invoke(String method, InputStream in, ResponseHandler rh)
  86:   {
  87:     Integer call_method = _NamingContextExtImplBase._methods.get(method);
  88: 
  89:     if (call_method == null)
  90:       // The older methods are handled separately.
  91:       return super_invoke(method, in, rh);
  92: 
  93:     OutputStream out = null;
  94: 
  95:     switch (call_method.intValue())
  96:       {
  97:         case 0: // to_string
  98:         {
  99:           try
 100:             {
 101:               NameComponent[] a_name = NameHelper.read(in);
 102:               String result = null;
 103:               result = this.to_string(a_name);
 104:               out = rh.createReply();
 105:               out.write_string(result);
 106:             }
 107:           catch (InvalidName ex)
 108:             {
 109:               out = rh.createExceptionReply();
 110:               InvalidNameHelper.write(out, ex);
 111:             }
 112:           break;
 113:         }
 114: 
 115:         case 1: // to_name
 116:         {
 117:           try
 118:             {
 119:               String a_name_string = in.read_string();
 120:               NameComponent[] result = to_name(a_name_string);
 121:               out = rh.createReply();
 122:               NameHelper.write(out, result);
 123:             }
 124:           catch (InvalidName ex)
 125:             {
 126:               out = rh.createExceptionReply();
 127:               InvalidNameHelper.write(out, ex);
 128:             }
 129:           break;
 130:         }
 131: 
 132:         case 2: // to_url
 133:         {
 134:           try
 135:             {
 136:               String an_address = in.read_string();
 137:               String a_name_string = in.read_string();
 138:               String result = to_url(an_address, a_name_string);
 139:               out = rh.createReply();
 140:               out.write_string(result);
 141:             }
 142:           catch (InvalidAddress ex)
 143:             {
 144:               out = rh.createExceptionReply();
 145:               InvalidAddressHelper.write(out, ex);
 146:             }
 147:           catch (InvalidName ex)
 148:             {
 149:               out = rh.createExceptionReply();
 150:               InvalidNameHelper.write(out, ex);
 151:             }
 152:           break;
 153:         }
 154: 
 155:         case 3: // resolve_str
 156:         {
 157:           try
 158:             {
 159:               String a_name_string = in.read_string();
 160:               org.omg.CORBA.Object result = resolve_str(a_name_string);
 161:               out = rh.createReply();
 162:               org.omg.CORBA.ObjectHelper.write(out, result);
 163:             }
 164:           catch (NotFound ex)
 165:             {
 166:               out = rh.createExceptionReply();
 167:               NotFoundHelper.write(out, ex);
 168:             }
 169:           catch (CannotProceed ex)
 170:             {
 171:               out = rh.createExceptionReply();
 172:               CannotProceedHelper.write(out, ex);
 173:             }
 174:           catch (InvalidName ex)
 175:             {
 176:               out = rh.createExceptionReply();
 177:               InvalidNameHelper.write(out, ex);
 178:             }
 179:           break;
 180:         }
 181:       }
 182:     return out;
 183:   }
 184: 
 185:   /**
 186:    * Handles calls to the methods from the NamingContext. The classes cannot be
 187:    * directly derived from each other; new public methods would appear.
 188:    */
 189:   OutputStream super_invoke(String method, InputStream in, ResponseHandler rh)
 190:   {
 191:     OutputStream out = null;
 192:     Integer call_method = _NamingContextImplBase.methods.get(method);
 193:     if (call_method == null)
 194:       throw new BAD_OPERATION(Minor.Method, CompletionStatus.COMPLETED_MAYBE);
 195: 
 196:     switch (call_method.intValue())
 197:       {
 198:         case 0: // bind
 199:         {
 200:           try
 201:             {
 202:               NameComponent[] a_name = NameHelper.read(in);
 203:               org.omg.CORBA.Object an_object = ObjectHelper.read(in);
 204:               bind(a_name, an_object);
 205:               out = rh.createReply();
 206:             }
 207:           catch (NotFound ex)
 208:             {
 209:               out = rh.createExceptionReply();
 210:               NotFoundHelper.write(out, ex);
 211:             }
 212:           catch (CannotProceed ex)
 213:             {
 214:               out = rh.createExceptionReply();
 215:               CannotProceedHelper.write(out, ex);
 216:             }
 217:           catch (InvalidName ex)
 218:             {
 219:               out = rh.createExceptionReply();
 220:               InvalidNameHelper.write(out, ex);
 221:             }
 222:           catch (AlreadyBound ex)
 223:             {
 224:               out = rh.createExceptionReply();
 225:               AlreadyBoundHelper.write(out, ex);
 226:             }
 227:           break;
 228:         }
 229: 
 230:         case 1: // rebind
 231:         {
 232:           try
 233:             {
 234:               NameComponent[] a_name = NameHelper.read(in);
 235:               org.omg.CORBA.Object an_object = ObjectHelper.read(in);
 236:               rebind(a_name, an_object);
 237:               out = rh.createReply();
 238:             }
 239:           catch (NotFound ex)
 240:             {
 241:               out = rh.createExceptionReply();
 242:               NotFoundHelper.write(out, ex);
 243:             }
 244:           catch (CannotProceed ex)
 245:             {
 246:               out = rh.createExceptionReply();
 247:               CannotProceedHelper.write(out, ex);
 248:             }
 249:           catch (InvalidName ex)
 250:             {
 251:               out = rh.createExceptionReply();
 252:               InvalidNameHelper.write(out, ex);
 253:             }
 254:           break;
 255:         }
 256: 
 257:         case 2: // bind_context
 258:         {
 259:           try
 260:             {
 261:               NameComponent[] a_name = NameHelper.read(in);
 262:               NamingContext a_context = NamingContextHelper.read(in);
 263:               bind_context(a_name, a_context);
 264:               out = rh.createReply();
 265:             }
 266:           catch (NotFound ex)
 267:             {
 268:               out = rh.createExceptionReply();
 269:               NotFoundHelper.write(out, ex);
 270:             }
 271:           catch (CannotProceed ex)
 272:             {
 273:               out = rh.createExceptionReply();
 274:               CannotProceedHelper.write(out, ex);
 275:             }
 276:           catch (InvalidName ex)
 277:             {
 278:               out = rh.createExceptionReply();
 279:               InvalidNameHelper.write(out, ex);
 280:             }
 281:           catch (AlreadyBound ex)
 282:             {
 283:               out = rh.createExceptionReply();
 284:               AlreadyBoundHelper.write(out, ex);
 285:             }
 286:           break;
 287:         }
 288: 
 289:         case 3: // rebind_context
 290:         {
 291:           try
 292:             {
 293:               NameComponent[] a_name = NameHelper.read(in);
 294:               NamingContext a_context = NamingContextHelper.read(in);
 295:               rebind_context(a_name, a_context);
 296:               out = rh.createReply();
 297:             }
 298:           catch (NotFound ex)
 299:             {
 300:               out = rh.createExceptionReply();
 301:               NotFoundHelper.write(out, ex);
 302:             }
 303:           catch (CannotProceed ex)
 304:             {
 305:               out = rh.createExceptionReply();
 306:               CannotProceedHelper.write(out, ex);
 307:             }
 308:           catch (InvalidName ex)
 309:             {
 310:               out = rh.createExceptionReply();
 311:               InvalidNameHelper.write(out, ex);
 312:             }
 313:           break;
 314:         }
 315: 
 316:         case 4: // resolve
 317:         {
 318:           try
 319:             {
 320:               NameComponent[] a_name = NameHelper.read(in);
 321:               org.omg.CORBA.Object __result = null;
 322:               __result = resolve(a_name);
 323:               out = rh.createReply();
 324:               ObjectHelper.write(out, __result);
 325:             }
 326:           catch (NotFound ex)
 327:             {
 328:               out = rh.createExceptionReply();
 329:               NotFoundHelper.write(out, ex);
 330:             }
 331:           catch (CannotProceed ex)
 332:             {
 333:               out = rh.createExceptionReply();
 334:               CannotProceedHelper.write(out, ex);
 335:             }
 336:           catch (InvalidName ex)
 337:             {
 338:               out = rh.createExceptionReply();
 339:               InvalidNameHelper.write(out, ex);
 340:             }
 341:           break;
 342:         }
 343: 
 344:         case 5: // unbind
 345:         {
 346:           try
 347:             {
 348:               NameComponent[] a_name = NameHelper.read(in);
 349:               unbind(a_name);
 350:               out = rh.createReply();
 351:             }
 352:           catch (NotFound ex)
 353:             {
 354:               out = rh.createExceptionReply();
 355:               NotFoundHelper.write(out, ex);
 356:             }
 357:           catch (CannotProceed ex)
 358:             {
 359:               out = rh.createExceptionReply();
 360:               CannotProceedHelper.write(out, ex);
 361:             }
 362:           catch (InvalidName ex)
 363:             {
 364:               out = rh.createExceptionReply();
 365:               InvalidNameHelper.write(out, ex);
 366:             }
 367:           break;
 368:         }
 369: 
 370:         case 6: // new_context
 371:         {
 372:           NamingContext __result = null;
 373:           __result = new_context();
 374:           out = rh.createReply();
 375:           NamingContextHelper.write(out, __result);
 376:           break;
 377:         }
 378: 
 379:         case 7: // bind_new_context
 380:         {
 381:           try
 382:             {
 383:               NameComponent[] a_name = NameHelper.read(in);
 384:               NamingContext __result = null;
 385:               __result = bind_new_context(a_name);
 386:               out = rh.createReply();
 387:               NamingContextHelper.write(out, __result);
 388:             }
 389:           catch (NotFound ex)
 390:             {
 391:               out = rh.createExceptionReply();
 392:               NotFoundHelper.write(out, ex);
 393:             }
 394:           catch (AlreadyBound ex)
 395:             {
 396:               out = rh.createExceptionReply();
 397:               AlreadyBoundHelper.write(out, ex);
 398:             }
 399:           catch (CannotProceed ex)
 400:             {
 401:               out = rh.createExceptionReply();
 402:               CannotProceedHelper.write(out, ex);
 403:             }
 404:           catch (InvalidName ex)
 405:             {
 406:               out = rh.createExceptionReply();
 407:               InvalidNameHelper.write(out, ex);
 408:             }
 409:           break;
 410:         }
 411: 
 412:         case 8: // destroy
 413:         {
 414:           try
 415:             {
 416:               destroy();
 417:               out = rh.createReply();
 418:             }
 419:           catch (NotEmpty ex)
 420:             {
 421:               out = rh.createExceptionReply();
 422:               NotEmptyHelper.write(out, ex);
 423:             }
 424:           break;
 425:         }
 426: 
 427:         case 9: // list
 428:         {
 429:           int amount = in.read_ulong();
 430:           BindingListHolder a_list = new BindingListHolder();
 431:           BindingIteratorHolder an_iter = new BindingIteratorHolder();
 432:           list(amount, a_list, an_iter);
 433:           out = rh.createReply();
 434:           BindingListHelper.write(out, a_list.value);
 435:           BindingIteratorHelper.write(out, an_iter.value);
 436:           break;
 437:         }
 438: 
 439:         default:
 440:           throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
 441:       }
 442: 
 443:     return out;
 444:   }
 445: 
 446:   /**
 447:    * Get the CORBA object that delegates calls to this servant. The servant must
 448:    * be already connected to an ORB.
 449:    */
 450:   public NamingContextExt _this()
 451:   {
 452:     return NamingContextExtHelper.narrow(super._this_object());
 453:   }
 454: 
 455:   /**
 456:    * Get the CORBA object that delegates calls to this servant. Connect to the
 457:    * given ORB, if needed.
 458:    */
 459:   public NamingContextExt _this(org.omg.CORBA.ORB orb)
 460:   {
 461:     return NamingContextExtHelper.narrow(super._this_object(orb));
 462:   }
 463: }