Source for org.omg.CosNaming.NamingContextPOA

   1: /* NamingContextPOA.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.NamingContextPackage.AlreadyBound;
  49: import org.omg.CosNaming.NamingContextPackage.AlreadyBoundHelper;
  50: import org.omg.CosNaming.NamingContextPackage.CannotProceed;
  51: import org.omg.CosNaming.NamingContextPackage.CannotProceedHelper;
  52: import org.omg.CosNaming.NamingContextPackage.InvalidName;
  53: import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper;
  54: import org.omg.CosNaming.NamingContextPackage.NotEmpty;
  55: import org.omg.CosNaming.NamingContextPackage.NotEmptyHelper;
  56: import org.omg.CosNaming.NamingContextPackage.NotFound;
  57: import org.omg.CosNaming.NamingContextPackage.NotFoundHelper;
  58: import org.omg.PortableServer.POA;
  59: import org.omg.PortableServer.Servant;
  60: 
  61: /**
  62:  * The naming service servant. After implementing the abstract methods the
  63:  * instance of this class can be connected to an ORB using POA.
  64:  * 
  65:  * @since 1.4 
  66:  *
  67:  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  68:  */
  69: public abstract class NamingContextPOA
  70:   extends Servant
  71:   implements NamingContextOperations, InvokeHandler
  72: {
  73:   /** @inheritDoc */
  74:   public String[] _all_interfaces(POA poa, byte[] object_ID)
  75:   {
  76:     return new String[] { NamingContextHelper.id() };
  77:   }
  78: 
  79:   /**
  80:    * The server calls this method after receiving the request message from
  81:    * client. The implementation base calls one of its abstract methods to
  82:    * perform the requested operation.
  83:    *
  84:    * @param method the method being invoked.
  85:    * @param in the stream to read parameters from.
  86:    * @param rh the handler to get a stream for writing a response.
  87:    *
  88:    * @return the stream, returned by the handler.
  89:    */
  90:   public OutputStream _invoke(String method, InputStream in, ResponseHandler rh)
  91:   {
  92:     OutputStream out = null;
  93:     Integer call_method = (Integer) _NamingContextImplBase.methods.get(method);
  94:     if (call_method == null)
  95:       throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
  96: 
  97:     switch (call_method.intValue())
  98:       {
  99:         case 0: // bind
 100:         {
 101:           try
 102:             {
 103:               NameComponent[] a_name = NameHelper.read(in);
 104:               org.omg.CORBA.Object an_object = ObjectHelper.read(in);
 105:               bind(a_name, an_object);
 106:               out = rh.createReply();
 107:             }
 108:           catch (NotFound ex)
 109:             {
 110:               out = rh.createExceptionReply();
 111:               NotFoundHelper.write(out, ex);
 112:             }
 113:           catch (CannotProceed ex)
 114:             {
 115:               out = rh.createExceptionReply();
 116:               CannotProceedHelper.write(out, ex);
 117:             }
 118:           catch (InvalidName ex)
 119:             {
 120:               out = rh.createExceptionReply();
 121:               InvalidNameHelper.write(out, ex);
 122:             }
 123:           catch (AlreadyBound ex)
 124:             {
 125:               out = rh.createExceptionReply();
 126:               AlreadyBoundHelper.write(out, ex);
 127:             }
 128:           break;
 129:         }
 130: 
 131:         case 1: // rebind
 132:         {
 133:           try
 134:             {
 135:               NameComponent[] a_name = NameHelper.read(in);
 136:               org.omg.CORBA.Object an_object = ObjectHelper.read(in);
 137:               rebind(a_name, an_object);
 138:               out = rh.createReply();
 139:             }
 140:           catch (NotFound ex)
 141:             {
 142:               out = rh.createExceptionReply();
 143:               NotFoundHelper.write(out, ex);
 144:             }
 145:           catch (CannotProceed ex)
 146:             {
 147:               out = rh.createExceptionReply();
 148:               CannotProceedHelper.write(out, ex);
 149:             }
 150:           catch (InvalidName ex)
 151:             {
 152:               out = rh.createExceptionReply();
 153:               InvalidNameHelper.write(out, ex);
 154:             }
 155:           break;
 156:         }
 157: 
 158:         case 2: // bind_context
 159:         {
 160:           try
 161:             {
 162:               NameComponent[] a_name = NameHelper.read(in);
 163:               NamingContext a_context = NamingContextHelper.read(in);
 164:               bind_context(a_name, a_context);
 165:               out = rh.createReply();
 166:             }
 167:           catch (NotFound ex)
 168:             {
 169:               out = rh.createExceptionReply();
 170:               NotFoundHelper.write(out, ex);
 171:             }
 172:           catch (CannotProceed ex)
 173:             {
 174:               out = rh.createExceptionReply();
 175:               CannotProceedHelper.write(out, ex);
 176:             }
 177:           catch (InvalidName ex)
 178:             {
 179:               out = rh.createExceptionReply();
 180:               InvalidNameHelper.write(out, ex);
 181:             }
 182:           catch (AlreadyBound ex)
 183:             {
 184:               out = rh.createExceptionReply();
 185:               AlreadyBoundHelper.write(out, ex);
 186:             }
 187:           break;
 188:         }
 189: 
 190:         case 3: // rebind_context
 191:         {
 192:           try
 193:             {
 194:               NameComponent[] a_name = NameHelper.read(in);
 195:               NamingContext a_context = NamingContextHelper.read(in);
 196:               rebind_context(a_name, a_context);
 197:               out = rh.createReply();
 198:             }
 199:           catch (NotFound ex)
 200:             {
 201:               out = rh.createExceptionReply();
 202:               NotFoundHelper.write(out, ex);
 203:             }
 204:           catch (CannotProceed ex)
 205:             {
 206:               out = rh.createExceptionReply();
 207:               CannotProceedHelper.write(out, ex);
 208:             }
 209:           catch (InvalidName ex)
 210:             {
 211:               out = rh.createExceptionReply();
 212:               InvalidNameHelper.write(out, ex);
 213:             }
 214:           break;
 215:         }
 216: 
 217:         case 4: // resolve
 218:         {
 219:           try
 220:             {
 221:               NameComponent[] a_name = NameHelper.read(in);
 222:               org.omg.CORBA.Object __result = null;
 223:               __result = resolve(a_name);
 224:               out = rh.createReply();
 225:               ObjectHelper.write(out, __result);
 226:             }
 227:           catch (NotFound ex)
 228:             {
 229:               out = rh.createExceptionReply();
 230:               NotFoundHelper.write(out, ex);
 231:             }
 232:           catch (CannotProceed ex)
 233:             {
 234:               out = rh.createExceptionReply();
 235:               CannotProceedHelper.write(out, ex);
 236:             }
 237:           catch (InvalidName ex)
 238:             {
 239:               out = rh.createExceptionReply();
 240:               InvalidNameHelper.write(out, ex);
 241:             }
 242:           break;
 243:         }
 244: 
 245:         case 5: // unbind
 246:         {
 247:           try
 248:             {
 249:               NameComponent[] a_name = NameHelper.read(in);
 250:               unbind(a_name);
 251:               out = rh.createReply();
 252:             }
 253:           catch (NotFound ex)
 254:             {
 255:               out = rh.createExceptionReply();
 256:               NotFoundHelper.write(out, ex);
 257:             }
 258:           catch (CannotProceed ex)
 259:             {
 260:               out = rh.createExceptionReply();
 261:               CannotProceedHelper.write(out, ex);
 262:             }
 263:           catch (InvalidName ex)
 264:             {
 265:               out = rh.createExceptionReply();
 266:               InvalidNameHelper.write(out, ex);
 267:             }
 268:           break;
 269:         }
 270: 
 271:         case 6: // new_context
 272:         {
 273:           NamingContext __result = null;
 274:           __result = new_context();
 275:           out = rh.createReply();
 276:           NamingContextHelper.write(out, __result);
 277:           break;
 278:         }
 279: 
 280:         case 7: // bind_new_context
 281:         {
 282:           try
 283:             {
 284:               NameComponent[] a_name = NameHelper.read(in);
 285:               NamingContext __result = null;
 286:               __result = bind_new_context(a_name);
 287:               out = rh.createReply();
 288:               NamingContextHelper.write(out, __result);
 289:             }
 290:           catch (NotFound ex)
 291:             {
 292:               out = rh.createExceptionReply();
 293:               NotFoundHelper.write(out, ex);
 294:             }
 295:           catch (AlreadyBound ex)
 296:             {
 297:               out = rh.createExceptionReply();
 298:               AlreadyBoundHelper.write(out, ex);
 299:             }
 300:           catch (CannotProceed ex)
 301:             {
 302:               out = rh.createExceptionReply();
 303:               CannotProceedHelper.write(out, ex);
 304:             }
 305:           catch (InvalidName ex)
 306:             {
 307:               out = rh.createExceptionReply();
 308:               InvalidNameHelper.write(out, ex);
 309:             }
 310:           break;
 311:         }
 312: 
 313:         case 8: // destroy
 314:         {
 315:           try
 316:             {
 317:               destroy();
 318:               out = rh.createReply();
 319:             }
 320:           catch (NotEmpty ex)
 321:             {
 322:               out = rh.createExceptionReply();
 323:               NotEmptyHelper.write(out, ex);
 324:             }
 325:           break;
 326:         }
 327: 
 328:         case 9: // list
 329:         {
 330:           int amount = in.read_ulong();
 331:           BindingListHolder a_list = new BindingListHolder();
 332:           BindingIteratorHolder an_iter = new BindingIteratorHolder();
 333:           list(amount, a_list, an_iter);
 334:           out = rh.createReply();
 335:           BindingListHelper.write(out, a_list.value);
 336:           BindingIteratorHelper.write(out, an_iter.value);
 337:           break;
 338:         }
 339: 
 340:         default:
 341:           throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
 342:       }
 343: 
 344:     return out;
 345:   }
 346: 
 347:   /**
 348:    * Get the CORBA object that delegates calls to this servant. The servant must
 349:    * be already connected to an ORB.
 350:    */
 351:   public NamingContext _this()
 352:   {
 353:     return NamingContextHelper.narrow(super._this_object());
 354:   }
 355: 
 356:   /**
 357:    * Get the CORBA object that delegates calls to this servant. Connect to the
 358:    * given ORB, if needed.
 359:    */
 360:   public NamingContext _this(org.omg.CORBA.ORB orb)
 361:   {
 362:     return NamingContextHelper.narrow(super._this_object(orb));
 363:   }
 364: 
 365: }