Source for org.omg.CosNaming._NamingContextStub

   1: /* _NamingContextStub.java --
   2:    Copyright (C) 2005, 2006 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.MARSHAL;
  42: import org.omg.CORBA.ObjectHelper;
  43: import org.omg.CORBA.portable.ApplicationException;
  44: import org.omg.CORBA.portable.Delegate;
  45: import org.omg.CORBA.portable.InputStream;
  46: import org.omg.CORBA.portable.ObjectImpl;
  47: import org.omg.CORBA.portable.OutputStream;
  48: import org.omg.CORBA.portable.RemarshalException;
  49: import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
  50: import org.omg.CosNaming.NamingContextPackage.AlreadyBoundHelper;
  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.NotEmpty;
  56: import org.omg.CosNaming.NamingContextPackage.NotEmptyHelper;
  57: import org.omg.CosNaming.NamingContextPackage.NotFound;
  58: import org.omg.CosNaming.NamingContextPackage.NotFoundHelper;
  59: 
  60: /**
  61:  * The naming context stub (proxy), used on the client side.
  62:  * The {@link NamingContext} methods contain the code for remote
  63:  * invocaton.
  64:  *
  65:  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  66:  */
  67: public class _NamingContextStub
  68:   extends ObjectImpl
  69:   implements NamingContext
  70: {
  71:   /**
  72:    * Use serialVersionUID (v1.4) for interoperability.
  73:    */
  74:   private static final long serialVersionUID = 6835430958405349379L;
  75: 
  76:   /**
  77:    * Create the naming context stub.
  78:    */
  79:   public _NamingContextStub()
  80:   {
  81:     super();
  82:   }
  83: 
  84:   /**
  85:    * Create the naming context stub with the given delegate.
  86:    */
  87:   _NamingContextStub(Delegate delegate)
  88:   {
  89:     super();
  90:     _set_delegate(delegate);
  91:   }
  92: 
  93:   /**
  94:    * Return the array of repository ids for this object.
  95:    */
  96:   public String[] _ids()
  97:   {
  98:     return new String[] { NamingContextHelper.id() };
  99:   }
 100: 
 101:   /** {@inheritDoc} */
 102:   public void bind(NameComponent[] a_name, org.omg.CORBA.Object an_object)
 103:             throws NotFound, CannotProceed, InvalidName, AlreadyBound
 104:   {
 105:     InputStream in = null;
 106:     try
 107:       {
 108:         OutputStream out = _request("bind", true);
 109:         NameHelper.write(out, a_name);
 110:         ObjectHelper.write(out, an_object);
 111:         in = _invoke(out);
 112:       }
 113:     catch (ApplicationException ex)
 114:       {
 115:         in = ex.getInputStream();
 116: 
 117:         String id = ex.getId();
 118:         throw5(in, id);
 119:       }
 120:     catch (RemarshalException remarsh)
 121:       {
 122:         bind(a_name, an_object);
 123:       }
 124:     finally
 125:       {
 126:         _releaseReply(in);
 127:       }
 128:   }
 129: 
 130:   /** {@inheritDoc} */
 131:   public void bind_context(NameComponent[] a_name, NamingContext a_context)
 132:                     throws NotFound, CannotProceed, InvalidName, AlreadyBound
 133:   {
 134:     InputStream in = null;
 135:     try
 136:       {
 137:         OutputStream out = _request("bind_context", true);
 138:         NameHelper.write(out, a_name);
 139:         NamingContextHelper.write(out, a_context);
 140:         in = _invoke(out);
 141:       }
 142:     catch (ApplicationException ex)
 143:       {
 144:         in = ex.getInputStream();
 145: 
 146:         String id = ex.getId();
 147:         throw5(in, id);
 148:       }
 149:     catch (RemarshalException remarsh)
 150:       {
 151:         bind_context(a_name, a_context);
 152:       }
 153:     finally
 154:       {
 155:         _releaseReply(in);
 156:       }
 157:   }
 158: 
 159:   /** {@inheritDoc} */
 160:   public NamingContext bind_new_context(NameComponent[] a_name)
 161:                                  throws NotFound, AlreadyBound, CannotProceed,
 162:                                         InvalidName
 163:   {
 164:     InputStream in = null;
 165:     try
 166:       {
 167:         OutputStream out = _request("bind_new_context", true);
 168:         NameHelper.write(out, a_name);
 169:         in = _invoke(out);
 170: 
 171:         NamingContext __result = NamingContextHelper.read(in);
 172:         return __result;
 173:       }
 174:     catch (ApplicationException ex)
 175:       {
 176:         in = ex.getInputStream();
 177: 
 178:         String id = ex.getId();
 179:         throw5(in, id);
 180:         throw new InternalError();
 181:       }
 182:     catch (RemarshalException remarsh)
 183:       {
 184:         return bind_new_context(a_name);
 185:       }
 186:     finally
 187:       {
 188:         _releaseReply(in);
 189:       }
 190:   }
 191: 
 192:   /** {@inheritDoc} */
 193:   public void destroy()
 194:                throws NotEmpty
 195:   {
 196:     InputStream in = null;
 197:     try
 198:       {
 199:         OutputStream out = _request("destroy", true);
 200:         in = _invoke(out);
 201:       }
 202:     catch (ApplicationException ex)
 203:       {
 204:         in = ex.getInputStream();
 205: 
 206:         String id = ex.getId();
 207:         if (id.equals(NotEmptyHelper.id()))
 208:           throw NotEmptyHelper.read(in);
 209:         else
 210:           throw new MARSHAL(id);
 211:       }
 212:     catch (RemarshalException remarsh)
 213:       {
 214:         destroy();
 215:       }
 216:     finally
 217:       {
 218:         _releaseReply(in);
 219:       }
 220:   }
 221: 
 222:   /** {@inheritDoc} */
 223:   public void list(int amount, BindingListHolder a_list,
 224:                    BindingIteratorHolder an_iter
 225:                   )
 226:   {
 227:     InputStream in = null;
 228:     try
 229:       {
 230:         OutputStream out = _request("list", true);
 231:         out.write_ulong(amount);
 232:         in = _invoke(out);
 233:         a_list.value = BindingListHelper.read(in);
 234:         an_iter.value = BindingIteratorHelper.read(in);
 235:       }
 236:     catch (ApplicationException ex)
 237:       {
 238:         in = ex.getInputStream();
 239:         throw new MARSHAL(ex.getId());
 240:       }
 241:     catch (RemarshalException remarsh)
 242:       {
 243:         list(amount, a_list, an_iter);
 244:       }
 245:     finally
 246:       {
 247:         _releaseReply(in);
 248:       }
 249:   }
 250: 
 251:   /** {@inheritDoc} */
 252:   public NamingContext new_context()
 253:   {
 254:     InputStream in = null;
 255:     try
 256:       {
 257:         OutputStream out = _request("new_context", true);
 258:         in = _invoke(out);
 259: 
 260:         NamingContext __result = NamingContextHelper.read(in);
 261:         return __result;
 262:       }
 263:     catch (ApplicationException ex)
 264:       {
 265:         in = ex.getInputStream();
 266:         throw new MARSHAL(ex.getId());
 267:       }
 268:     catch (RemarshalException remarsh)
 269:       {
 270:         return new_context();
 271:       }
 272:     finally
 273:       {
 274:         _releaseReply(in);
 275:       }
 276:   }
 277: 
 278:   /** {@inheritDoc} */
 279:   public void rebind(NameComponent[] a_name, org.omg.CORBA.Object an_object)
 280:               throws NotFound, CannotProceed, InvalidName
 281:   {
 282:     InputStream in = null;
 283:     try
 284:       {
 285:         OutputStream out = _request("rebind", true);
 286:         NameHelper.write(out, a_name);
 287:         ObjectHelper.write(out, an_object);
 288:         in = _invoke(out);
 289:       }
 290:     catch (ApplicationException ex)
 291:       {
 292:         in = ex.getInputStream();
 293: 
 294:         String id = ex.getId();
 295:         throw4(in, id);
 296:       }
 297:     catch (RemarshalException remarsh)
 298:       {
 299:         rebind(a_name, an_object);
 300:       }
 301:     finally
 302:       {
 303:         _releaseReply(in);
 304:       }
 305:   }
 306: 
 307:   /** {@inheritDoc} */
 308:   public void rebind_context(NameComponent[] a_name, NamingContext a_context)
 309:                       throws NotFound, CannotProceed, InvalidName
 310:   {
 311:     InputStream in = null;
 312:     try
 313:       {
 314:         OutputStream out = _request("rebind_context", true);
 315:         NameHelper.write(out, a_name);
 316:         NamingContextHelper.write(out, a_context);
 317:         in = _invoke(out);
 318:       }
 319:     catch (ApplicationException ex)
 320:       {
 321:         in = ex.getInputStream();
 322: 
 323:         String id = ex.getId();
 324:         throw4(in, id);
 325:       }
 326:     catch (RemarshalException remarsh)
 327:       {
 328:         rebind_context(a_name, a_context);
 329:       }
 330:     finally
 331:       {
 332:         _releaseReply(in);
 333:       }
 334:   }
 335: 
 336:   /** {@inheritDoc} */
 337:   public org.omg.CORBA.Object resolve(NameComponent[] a_name)
 338:                                throws NotFound, CannotProceed, InvalidName
 339:   {
 340:     InputStream in = null;
 341:     try
 342:       {
 343:         OutputStream out = _request("resolve", true);
 344:         NameHelper.write(out, a_name);
 345:         in = _invoke(out);
 346: 
 347:         org.omg.CORBA.Object __result = ObjectHelper.read(in);
 348:         return __result;
 349:       }
 350:     catch (ApplicationException ex)
 351:       {
 352:         in = ex.getInputStream();
 353: 
 354:         String id = ex.getId();
 355:         throw4(in, id);
 356:         throw new InternalError();
 357:       }
 358:     catch (RemarshalException remarsh)
 359:       {
 360:         return resolve(a_name);
 361:       }
 362:     finally
 363:       {
 364:         _releaseReply(in);
 365:       }
 366:   }
 367: 
 368:   /** {@inheritDoc} */
 369:   public void unbind(NameComponent[] a_name)
 370:               throws NotFound, CannotProceed, InvalidName
 371:   {
 372:     InputStream in = null;
 373:     try
 374:       {
 375:         OutputStream out = _request("unbind", true);
 376:         NameHelper.write(out, a_name);
 377:         in = _invoke(out);
 378:       }
 379:     catch (ApplicationException ex)
 380:       {
 381:         in = ex.getInputStream();
 382: 
 383:         String id = ex.getId();
 384:         if (id.equals(NotFoundHelper.id()))
 385:           throw NotFoundHelper.read(in);
 386:         else if (id.equals(CannotProceedHelper.id()))
 387:           throw CannotProceedHelper.read(in);
 388:         else if (id.equals(InvalidNameHelper.id()))
 389:           throw InvalidNameHelper.read(in);
 390:         else
 391:           throw new MARSHAL(id);
 392:       }
 393:     catch (RemarshalException remarsh)
 394:       {
 395:         unbind(a_name);
 396:       }
 397:     finally
 398:       {
 399:         _releaseReply(in);
 400:       }
 401:   }
 402: 
 403:   /**
 404:    * Throw one of the three possible exceptions, as specified in
 405:    * the passed exception repository id.
 406:    *
 407:    * This method should never return normally.
 408:    *
 409:    * @param in the stream to read the exception from.
 410:    * @param id the exception id.
 411:    *
 412:    * @throws InvalidName if the id matches.
 413:    * @throws CannotProceed if the id matches.
 414:    * @throws NotFound if the id matches.
 415:    * @throws MARSHAL if the id does not match any of the previous 4 exceptions.
 416:    */
 417:   void throw4(InputStream in, String id)
 418:                  throws MARSHAL, InvalidName, CannotProceed, NotFound
 419:   {
 420:     if (id.equals(NotFoundHelper.id()))
 421:       throw NotFoundHelper.read(in);
 422:     else if (id.equals(CannotProceedHelper.id()))
 423:       throw CannotProceedHelper.read(in);
 424:     else if (id.equals(InvalidNameHelper.id()))
 425:       throw InvalidNameHelper.read(in);
 426:     else
 427:       throw new MARSHAL(id);
 428:   }
 429: 
 430:   /**
 431:    * Throw one of the five possible exceptions, as specified in
 432:    * the passed exception repository id.
 433:    *
 434:    * This method should never return normally.
 435:    *
 436:    * @param in the stream to read the exception from.
 437:    * @param id the exception id.
 438:    *
 439:    * @throws AlreadyBound if the id matches.
 440:    * @throws InvalidName if the id matches.
 441:    * @throws CannotProceed if the id matches.
 442:    * @throws NotFound if the id matches.
 443:    * @throws MARSHAL if the id does not match any of the previous 4 exceptions.
 444:    */
 445:   void throw5(InputStream in, String id)
 446:                  throws MARSHAL, AlreadyBound, InvalidName, CannotProceed,
 447:                         NotFound
 448:   {
 449:     if (id.equals(AlreadyBoundHelper.id()))
 450:       throw AlreadyBoundHelper.read(in);
 451:     else
 452:       throw4(in, id);
 453:   }
 454: }