Source for org.omg.CosNaming._BindingIteratorImplBase

   1: /* _BindingIteratorImplBase.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.BooleanHolder;
  43: import org.omg.CORBA.CompletionStatus;
  44: import org.omg.CORBA.DynamicImplementation;
  45: import org.omg.CORBA.ServerRequest;
  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.CORBA.portable.Streamable;
  51: 
  52: /**
  53:  * The binding iterator implementation base.
  54:  *
  55:  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  56:  */
  57: public abstract class _BindingIteratorImplBase
  58:   extends DynamicImplementation
  59:   implements BindingIterator, InvokeHandler
  60: {
  61:   /**
  62:    * Use serialVersionUID (v1.4) for interoperability.
  63:    */
  64:   private static final long serialVersionUID = 3472591176635005503L;
  65: 
  66:   /**
  67:    * The binding interator repository id.
  68:    */
  69:   private static String[] ids = { BindingIteratorHelper.id() };
  70: 
  71:   /**
  72:    * Return the list of repository ids.
  73:    */
  74:   public String[] _ids()
  75:   {
  76:     return ids;
  77:   }
  78: 
  79:   /**
  80:    * Call the required method.
  81:    */
  82:   public OutputStream _invoke(String method, InputStream in, ResponseHandler rh)
  83:   {
  84:     OutputStream out = null;
  85: 
  86:     // We suppose that the next_n should be the most popular.
  87:     if (method.equals("next_n"))
  88:       {
  89:         // The next_n has been invoked.
  90:         int amount = in.read_ulong();
  91:         BindingListHolder a_list = new BindingListHolder();
  92: 
  93:         boolean result = next_n(amount, a_list);
  94: 
  95:         out = rh.createReply();
  96:         out.write_boolean(result);
  97:         BindingListHelper.write(out, a_list.value);
  98:       }
  99:     else if (method.equals("next_one"))
 100:       {
 101:         // The next_one has been invoked.
 102:         BindingHolder a_binding = new BindingHolder();
 103: 
 104:         boolean result = next_one(a_binding);
 105: 
 106:         out = rh.createReply();
 107:         out.write_boolean(result);
 108:         BindingHelper.write(out, a_binding.value);
 109:       }
 110:     else if (method.equals("destroy"))
 111:       {
 112:         // The destroy has been invoked.
 113:         destroy();
 114:         out = rh.createReply();
 115:       }
 116:     else
 117:       throw new BAD_OPERATION(method, 0, CompletionStatus.COMPLETED_MAYBE);
 118: 
 119:     return out;
 120:   }
 121: 
 122:   /**
 123:    * The obsolete invocation using server request. Implemented for
 124:    * compatibility reasons, but is it more effectinve to use
 125:    * {@link #_invoke}.
 126:    *
 127:    * @param request a server request.
 128:    */
 129:   public void invoke(ServerRequest request)
 130:   {
 131:     // "destroy" has a void return type, the two other methods - boolean.
 132:     Streamable result =
 133:       request.operation().equals("destroy") ? null : new BooleanHolder();
 134:     gnu.CORBA.ServiceRequestAdapter.invoke(request, this, result);
 135:   }