001    /* _NamingContextExtStub.java --
002       Copyright (C) 2005, 2006 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package org.omg.CosNaming;
040    
041    import gnu.CORBA.NamingService.NameTransformer;
042    
043    import org.omg.CORBA.MARSHAL;
044    import org.omg.CORBA.ObjectHelper;
045    import org.omg.CORBA.portable.ApplicationException;
046    import org.omg.CORBA.portable.Delegate;
047    import org.omg.CORBA.portable.InputStream;
048    import org.omg.CORBA.portable.OutputStream;
049    import org.omg.CORBA.portable.RemarshalException;
050    import org.omg.CosNaming.NamingContextExtPackage.AddressHelper;
051    import org.omg.CosNaming.NamingContextExtPackage.InvalidAddress;
052    import org.omg.CosNaming.NamingContextExtPackage.InvalidAddressHelper;
053    import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
054    import org.omg.CosNaming.NamingContextExtPackage.URLStringHelper;
055    import org.omg.CosNaming.NamingContextPackage.CannotProceed;
056    import org.omg.CosNaming.NamingContextPackage.InvalidName;
057    import org.omg.CosNaming.NamingContextPackage.InvalidNameHelper;
058    import org.omg.CosNaming.NamingContextPackage.NotFound;
059    
060    /**
061     * The extended naming context stub (proxy), used on the client side.
062     * The most of the {@link NamingContextExt} methods contain the code
063     * for remote invocaton. However as remote invocation is potencially an
064     * expensive step, some trivial methods, not requiring access to the
065     * naming database, are handled locally (see the method descriptions for
066     * details).
067     *
068     * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
069     */
070    public class _NamingContextExtStub
071      extends _NamingContextStub
072      implements NamingContextExt
073    {
074      /**
075       * Use serialVersionUID (v1.4) for interoperability.
076       */
077      private static final long serialVersionUID = 6333293895664182866L;
078    
079      /**
080       * This stub can be the base of the two CORBA objects, so it
081       * has two repository ids.
082       */
083      private static String[] __ids =
084        { NamingContextExtHelper.id(), NamingContextHelper.id() };
085    
086      /**
087       * The local name form converter.
088       */
089      private NameTransformer converter = new NameTransformer();
090    
091      /**
092       * Create the naming context stub.
093       */
094      public _NamingContextExtStub()
095      {
096        super();
097      }
098    
099      /**
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    }