Source for org.omg.CosNaming._NamingContextImplBase

   1: /* _NamingContextImplBase.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.DynamicImplementation;
  44: import org.omg.CORBA.ObjectHelper;
  45: import org.omg.CORBA.ObjectHolder;
  46: import org.omg.CORBA.ServerRequest;
  47: import org.omg.CORBA.portable.InputStream;
  48: import org.omg.CORBA.portable.InvokeHandler;
  49: import org.omg.CORBA.portable.OutputStream;
  50: import org.omg.CORBA.portable.ResponseHandler;
  51: import org.omg.CORBA.portable.Streamable;
  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: 
  63: import java.util.Hashtable;
  64: 
  65: /**
  66:  * The naming context implementation base.
  67:  *
  68:  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  69:  */
  70: public abstract class _NamingContextImplBase
  71:   extends DynamicImplementation
  72:   implements NamingContext, InvokeHandler
  73: {
  74:   /**
  75:    * Use serialVersionUID (v1.4) for interoperability.
  76:    */
  77:   private static final long serialVersionUID = -114280294134561035L;
  78: 
  79:   /**
  80:    * As there are quite many methods, it may be sensible to use the hashtable.
  81:    * This field is also reused in NamingContextPOA.
  82:    */
  83:   static Hashtable methods = new Hashtable();
  84: 
  85:   /**
  86:    * Put all methods into the table.
  87:    */
  88:   static
  89:   {
  90:     methods.put("bind", new Integer(0));
  91:     methods.put("rebind", new Integer(1));
  92:     methods.put("bind_context", new Integer(2));
  93:     methods.put("rebind_context", new Integer(3));
  94:     methods.put("resolve", new Integer(4));
  95:     methods.put("unbind", new Integer(5));
  96:     methods.put("new_context", new Integer(6));
  97:     methods.put("bind_new_context", new Integer(7));
  98:     methods.put("destroy", new Integer(8));
  99:     methods.put("list", new Integer(9));
 100:   }
 101: 
 102:   /**
 103:    * Return the array of repository ids.
 104:    */
 105:   public String[] _ids()
 106:   {
 107:     return new String[] { NamingContextHelper.id() };
 108:   }
 109: 
 110:   /**
 111:    * The server calls this method after receiving the request message
 112:    * from client. The implementation base calls one of its abstract
 113:    * methods to perform the requested operation.
 114:    *
 115:    * @param method the method being invoked.
 116:    * @param in the stream to read parameters from.
 117:    * @param rh the handler to get a stream for writing a response.
 118:    *
 119:    * @return the stream, returned by the handler.
 120:    */
 121:   public OutputStream _invoke(String method, InputStream in, ResponseHandler rh)
 122:   {
 123:     OutputStream out = null;
 124:     Integer call_method = (Integer) methods.get(method);
 125:     if (call_method == null)
 126:       throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
 127: 
 128:     switch (call_method.intValue())
 129:       {
 130:         case 0 : // bind
 131:         {
 132:           try
 133:             {
 134:               NameComponent[] a_name = NameHelper.read(in);
 135:               org.omg.CORBA.Object an_object = ObjectHelper.read(in);
 136:               bind(a_name, an_object);
 137:               out = rh.createReply();
 138:             }
 139:           catch (NotFound ex)
 140:             {
 141:               out = rh.createExceptionReply();
 142:               NotFoundHelper.write(out, ex);
 143:             }
 144:           catch (CannotProceed ex)
 145:             {
 146:               out = rh.createExceptionReply();
 147:               CannotProceedHelper.write(out, ex);
 148:             }
 149:           catch (InvalidName ex)
 150:             {
 151:               out = rh.createExceptionReply();
 152:               InvalidNameHelper.write(out, ex);
 153:             }
 154:           catch (AlreadyBound ex)
 155:             {
 156:               out = rh.createExceptionReply();
 157:               AlreadyBoundHelper.write(out, ex);
 158:             }
 159:           break;
 160:         }
 161: 
 162:         case 1 : // rebind
 163:         {
 164:           try
 165:             {
 166:               NameComponent[] a_name = NameHelper.read(in);
 167:               org.omg.CORBA.Object an_object = ObjectHelper.read(in);
 168:               rebind(a_name, an_object);
 169:               out = rh.createReply();
 170:             }
 171:           catch (NotFound ex)
 172:             {
 173:               out = rh.createExceptionReply();
 174:               NotFoundHelper.write(out, ex);
 175:             }
 176:           catch (CannotProceed ex)
 177:             {
 178:               out = rh.createExceptionReply();
 179:               CannotProceedHelper.write(out, ex);
 180:             }
 181:           catch (InvalidName ex)
 182:             {
 183:               out = rh.createExceptionReply();
 184:               InvalidNameHelper.write(out, ex);
 185:             }
 186:           break;
 187:         }
 188: 
 189:         case 2 : // bind_context
 190:         {
 191:           try
 192:             {
 193:               NameComponent[] a_name = NameHelper.read(in);
 194:               NamingContext a_context = NamingContextHelper.read(in);
 195:               bind_context(a_name, a_context);
 196:               out = rh.createReply();
 197:             }
 198:           catch (NotFound ex)
 199:             {
 200:               out = rh.createExceptionReply();
 201:               NotFoundHelper.write(out, ex);
 202:             }
 203:           catch (CannotProceed ex)
 204:             {
 205:               out = rh.createExceptionReply();
 206:               CannotProceedHelper.write(out, ex);
 207:             }
 208:           catch (InvalidName ex)
 209:             {
 210:               out = rh.createExceptionReply();
 211:               InvalidNameHelper.write(out, ex);
 212:             }
 213:           catch (AlreadyBound ex)
 214:             {
 215:               out = rh.createExceptionReply();
 216:               AlreadyBoundHelper.write(out, ex);
 217:             }
 218:           break;
 219:         }
 220: 
 221:         case 3 : // rebind_context
 222:         {
 223:           try
 224:             {
 225:               NameComponent[] a_name = NameHelper.read(in);
 226:               NamingContext a_context = NamingContextHelper.read(in);
 227:               rebind_context(a_name, a_context);
 228:               out = rh.createReply();
 229:             }
 230:           catch (NotFound ex)
 231:             {
 232:               out = rh.createExceptionReply();
 233:               NotFoundHelper.write(out, ex);
 234:             }
 235:           catch (CannotProceed ex)
 236:             {
 237:               out = rh.createExceptionReply();
 238:               CannotProceedHelper.write(out, ex);
 239:             }
 240:           catch (InvalidName ex)
 241:             {
 242:               out = rh.createExceptionReply();
 243:               InvalidNameHelper.write(out, ex);
 244:             }
 245:           break;
 246:         }
 247: 
 248:         case 4 : // resolve
 249:         {
 250:           try
 251:             {
 252:               NameComponent[] a_name = NameHelper.read(in);
 253:               org.omg.CORBA.Object __result = null;
 254:               __result = resolve(a_name);
 255:               out = rh.createReply();
 256:               ObjectHelper.write(out, __result);
 257:             }
 258:           catch (NotFound ex)
 259:             {
 260:               out = rh.createExceptionReply();
 261:               NotFoundHelper.write(out, ex);
 262:             }
 263:           catch (CannotProceed ex)
 264:             {
 265:               out = rh.createExceptionReply();
 266:               CannotProceedHelper.write(out, ex);
 267:             }
 268:           catch (InvalidName ex)
 269:             {
 270:               out = rh.createExceptionReply();
 271:               InvalidNameHelper.write(out, ex);
 272:             }
 273:           break;
 274:         }
 275: 
 276:         case 5 : // unbind
 277:         {
 278:           try
 279:             {
 280:               NameComponent[] a_name = NameHelper.read(in);
 281:               unbind(a_name);
 282:               out = rh.createReply();
 283:             }
 284:           catch (NotFound ex)
 285:             {
 286:               out = rh.createExceptionReply();
 287:               NotFoundHelper.write(out, ex);
 288:             }
 289:           catch (CannotProceed ex)
 290:             {
 291:               out = rh.createExceptionReply();
 292:               CannotProceedHelper.write(out, ex);
 293:             }
 294:           catch (InvalidName ex)
 295:             {
 296:               out = rh.createExceptionReply();
 297:               InvalidNameHelper.write(out, ex);
 298:             }
 299:           break;
 300:         }
 301: 
 302:         case 6 : // new_context
 303:         {
 304:           NamingContext __result = null;
 305:           __result = new_context();
 306:           out = rh.createReply();
 307:           NamingContextHelper.write(out, __result);
 308:           break;
 309:         }
 310: 
 311:         case 7 : // bind_new_context
 312:         {
 313:           try
 314:             {
 315:               NameComponent[] a_name = NameHelper.read(in);
 316:               NamingContext __result = null;
 317:               __result = bind_new_context(a_name);
 318:               out = rh.createReply();
 319:               NamingContextHelper.write(out, __result);
 320:             }
 321:           catch (NotFound ex)
 322:             {
 323:               out = rh.createExceptionReply();
 324:               NotFoundHelper.write(out, ex);
 325:             }
 326:           catch (AlreadyBound ex)
 327:             {
 328:               out = rh.createExceptionReply();
 329:               AlreadyBoundHelper.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 8 : // destroy
 345:         {
 346:           try
 347:             {
 348:               destroy();
 349:               out = rh.createReply();
 350:             }
 351:           catch (NotEmpty ex)
 352:             {
 353:               out = rh.createExceptionReply();
 354:               NotEmptyHelper.write(out, ex);
 355:             }
 356:           break;
 357:         }
 358: 
 359:         case 9 : // list
 360:         {
 361:           int amount = in.read_ulong();
 362:           BindingListHolder a_list = new BindingListHolder();
 363:           BindingIteratorHolder an_iter = new BindingIteratorHolder();
 364:           list(amount, a_list, an_iter);
 365:           out = rh.createReply();
 366:           BindingListHelper.write(out, a_list.value);
 367:           BindingIteratorHelper.write(out, an_iter.value);
 368:           break;
 369:         }
 370: 
 371:         default :
 372:           throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
 373:       }
 374: 
 375:     return out;
 376:   }
 377: 
 378:   /**
 379:    * The obsolete invocation using server request. Implemented for
 380:    * compatibility reasons, but is it more effectinve to use
 381:    * {@link #_invoke}.
 382:    *
 383:    * @param request a server request.
 384:    */
 385:   public void invoke(ServerRequest request)
 386:   {
 387:     Streamable result = null;
 388: 
 389:     // The server request contains no required result type.
 390:     Integer call_method = (Integer) methods.get(request.operation());
 391:     if (call_method == null)
 392:       throw new BAD_OPERATION(0, CompletionStatus.COMPLETED_MAYBE);
 393: 
 394:     switch (call_method.intValue())
 395:       {
 396:         case 4 : // resolve, object
 397:           result = new ObjectHolder();
 398:           break;
 399: 
 400:         case 6 : // new_context, NamingContext
 401:         case 7 : // bind_new_context, NamingContext
 402:         {
 403:           result = new NamingContextHolder();
 404:           break;
 405:         }
 406: 
 407:         default : // void for others.
 408:           result = null;
 409:       }
 410: 
 411:     gnu.CORBA.ServiceRequestAdapter.invoke(request, this, result);
 412:   }