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