Source for org.omg.CosNaming._NamingContextExtStub

   1: /* _NamingContextExtStub.java --
   2:    Copyright (C) 2005, 2006 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.NamingService.NameTransformer;
  42: 
  43: import org.omg.CORBA.MARSHAL;
  44: import org.omg.CORBA.ObjectHelper;
  45: import org.omg.CORBA.portable.ApplicationException;
  46: import org.omg.CORBA.portable.Delegate;
  47: import org.omg.CORBA.portable.InputStream;
  48: import org.omg.CORBA.portable.OutputStream;
  49: import org.omg.CORBA.portable.RemarshalException;
  50: import org.omg.CosNaming.NamingContextExtPackage.AddressHelper;
  51: import org.omg.CosNaming.NamingContextExtPackage.InvalidAddress;
  52: import org.omg.CosNaming.NamingContextExtPackage.InvalidAddressHelper;
  53: import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
  54: import org.omg.CosNaming.NamingContextExtPackage.URLStringHelper;
  55: import org.omg.CosNaming.NamingContextPackage.CannotProceed;
  56: import org.omg.CosNaming.NamingContextPackage.InvalidName;
  57: import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper;
  58: import org.omg.CosNaming.NamingContextPackage.NotFound;
  59: 
  60: /**
  61:  * The extended naming context stub (proxy), used on the client side.
  62:  * The most of the {@link NamingContextExt} methods contain the code
  63:  * for remote invocaton. However as remote invocation is potencially an
  64:  * expensive step, some trivial methods, not requiring access to the
  65:  * naming database, are handled locally (see the method descriptions for
  66:  * details).
  67:  *
  68:  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  69:  */
  70: public class _NamingContextExtStub
  71:   extends _NamingContextStub
  72:   implements NamingContextExt
  73: {
  74:   /**
  75:    * Use serialVersionUID (v1.4) for interoperability.
  76:    */
  77:   private static final long serialVersionUID = 6333293895664182866L;
  78: 
  79:   /**
  80:    * This stub can be the base of the two CORBA objects, so it
  81:    * has two repository ids.
  82:    */
  83:   private static String[] __ids =
  84:     { NamingContextExtHelper.id(), NamingContextHelper.id() };
  85: 
  86:   /**
  87:    * The local name form converter.
  88:    */
  89:   private NameTransformer converter = new NameTransformer();
  90: 
  91:   /**
  92:    * Create the naming context stub.
  93:    */
  94:   public _NamingContextExtStub()
  95:   {
  96:     super();
  97:   }
  98: 
  99:   /**
 100:    * Create the naming context stub with the given delegate.
 101:    */
 102:   _NamingContextExtStub(Delegate delegate)
 103:   {
 104:     super(delegate);
 105:   }
 106: 
 107:   /**
 108:    * Return the array of repository ids for this object.
 109:    * This stub can be the base of the two CORBA objects, so it
 110:    * has two repository ids, for {@link NamingContext} and
 111:    * for {@link NamingContextExt}.
 112:    */
 113:   public String[] _ids()
 114:   {
 115:     return (String[]) __ids.clone();
 116:   }
 117: 
 118:   /** {@inheritDoc} */
 119:   public org.omg.CORBA.Object resolve_str(String a_name_string)
 120:                                    throws NotFound, CannotProceed, InvalidName
 121:   {
 122:     InputStream in = null;
 123:     try
 124:       {
 125:         OutputStream _out = _request("resolve_str", true);
 126:         StringNameHelper.write(_out, a_name_string);
 127:         in = _invoke(_out);
 128: 
 129:         return ObjectHelper.read(in);
 130:       }
 131:     catch (ApplicationException ex)
 132:       {
 133:         in = ex.getInputStream();
 134: 
 135:         String id = ex.getId();
 136:         throw4(in, id);
 137: 
 138:         // Should never happen.
 139:         throw new InternalError();
 140:       }
 141:     catch (RemarshalException _rm)
 142:       {
 143:         return resolve_str(a_name_string);
 144:       }
 145:     finally
 146:       {
 147:         _releaseReply(in);
 148:       }
 149:   }
 150: 
 151:   /**
 152:    * Converts the string name representation into the array
 153:    * name representation.
 154:    *
 155:    * This method is handled locally.
 156:    */
 157:   public NameComponent[] to_name(String a_name_string)
 158:                           throws InvalidName
 159:   {
 160:     return converter.toName(a_name_string);
 161:   }
 162: 
 163:   /**
 164:    * Convert the name array representation to the name string
 165:    * representation.
 166:    *
 167:    * This method is handled locally.
 168:    */
 169:   public String to_string(NameComponent[] a_name)
 170:                    throws InvalidName
 171:   {
 172:     return converter.toString(a_name);
 173:   }
 174: 
 175:   /** {@inheritDoc} */
 176:   public String to_url(String an_address, String a_name_string)
 177:                 throws InvalidAddress, InvalidName
 178:   {
 179:     InputStream in = null;
 180:     try
 181:       {
 182:         OutputStream _out = _request("to_url", true);
 183:         AddressHelper.write(_out, an_address);
 184:         StringNameHelper.write(_out, a_name_string);
 185:         in = _invoke(_out);
 186: 
 187:         return URLStringHelper.read(in);
 188:       }
 189:     catch (ApplicationException ex)
 190:       {
 191:         in = ex.getInputStream();
 192: 
 193:         String id = ex.getId();
 194:         if (id.equals(InvalidAddressHelper.id()))
 195:           throw InvalidAddressHelper.read(in);
 196:         else if (id.equals(InvalidNameHelper.id()))
 197:           throw InvalidNameHelper.read(in);
 198:         else
 199:           throw new MARSHAL(id);
 200:       }
 201:     catch (RemarshalException _rm)
 202:       {
 203:         return to_url(an_address, a_name_string);
 204:       }
 205:     finally
 206:       {
 207:         _releaseReply(in);
 208:       }
 209:   }
 210: }