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