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