001    /* _IDLTypeStub.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.CORBA;
040    
041    import gnu.CORBA.Minor;
042    import gnu.CORBA.TypeCodeHelper;
043    
044    import org.omg.CORBA.portable.ApplicationException;
045    import org.omg.CORBA.portable.Delegate;
046    import org.omg.CORBA.portable.InputStream;
047    import org.omg.CORBA.portable.ObjectImpl;
048    import org.omg.CORBA.portable.OutputStream;
049    import org.omg.CORBA.portable.RemarshalException;
050    
051    import java.io.Serializable;
052    
053    /**
054     * The stub for the IDL type. This stub can be used to access the
055     * remote IDL type object, if its IOR is known. To create the
056     * working instance with the known IOR, pass {@link gnu.CORBA.IorDelegate}
057     * to the constructor.
058     *
059     * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
060     */
061    public class _IDLTypeStub
062      extends ObjectImpl
063      implements IDLType, Serializable
064    {
065      /**
066      * Use serialVersionUID (v1.4) for interoperability.
067      */
068      private static final long serialVersionUID = 9150293942452453626L;
069    
070      /**
071       * Create the instance of the IDL type stub without
072       * the set delegate. The delegate must be set anyway before calling
073       * any remote method.
074       */
075      public _IDLTypeStub()
076      {
077      }
078    
079      /**
080       * Create an instance with the given delegate.
081       *
082       * @see gnu.CORBA.IorDelegate
083       */
084      public _IDLTypeStub(Delegate delegate)
085      {
086        _set_delegate(delegate);
087      }
088    
089      /**
090       * Get the typecode of the remote IDL type object. The method is
091       * written following OMG specification, treating the typecode
092       * as a read only attribute rather than a method. This means,
093       * the operation name is "_get_type".
094       *
095       * @return a typecode, returned by the remote IDL type object.
096       */
097      public TypeCode type()
098      {
099        InputStream in = null;
100        try
101          {
102            OutputStream out = _request("_get_type", true);
103            in = _invoke(out);
104            return TypeCodeHelper.read(in);
105          }
106        catch (ApplicationException ex)
107          {
108            in = ex.getInputStream();
109            throw new org.omg.CORBA.MARSHAL(ex.getId());
110          }
111        catch (RemarshalException rex)
112          {
113            return type();
114          }
115        catch (UserException ex)
116          {
117            MARSHAL m = new MARSHAL();
118            m.minor = Minor.UserException;
119            m.initCause(ex);
120            throw m;
121          }
122        finally
123          {
124            _releaseReply(in);
125          }
126      }
127    
128      /**
129       * Get the definition kind of the remote IDL type object. The method is
130       * written following OMG specification, treating the typecode
131       * as a read only attribute rather than a method. This means,
132       * the operation name is "_get_def_kind".
133       *
134       * @return a definition kind, returned by remote IDL type object.
135       */
136      public DefinitionKind def_kind()
137      {
138        InputStream in = null;
139        try
140          {
141            OutputStream out = _request("_get_def_kind", true);
142            in = _invoke(out);
143            return DefinitionKindHelper.read(in);
144          }
145        catch (ApplicationException ex)
146          {
147            in = ex.getInputStream();
148            throw new org.omg.CORBA.MARSHAL(ex.getId());
149          }
150        catch (RemarshalException rex)
151          {
152            return def_kind();
153          }
154        finally
155          {
156            _releaseReply(in);
157          }
158      }
159    
160      /**
161       * Destroy the remote IDL type object.
162       */
163      public void destroy()
164      {
165        InputStream in = null;
166        try
167          {
168            OutputStream out = _request("destroy", true);
169            in = _invoke(out);
170          }
171        catch (ApplicationException ex)
172          {
173            in = ex.getInputStream();
174            throw new org.omg.CORBA.MARSHAL(ex.getId());
175          }
176        catch (RemarshalException rex)
177          {
178            destroy();
179          }
180        finally
181          {
182            _releaseReply(in);
183          }
184      }
185    
186      /**
187       * Return the array of repository ids of the IDL type.
188       *
189       * @return "IDL:omg.org/CORBA/IDLType:1.0" and
190       *  "IDL:omg.org/CORBA/IRObject:1.0", always.
191       */
192      public String[] _ids()
193      {
194        return new String[]
195               {
196                 "IDL:omg.org/CORBA/IDLType:1.0", "IDL:omg.org/CORBA/IRObject:1.0"
197               };
198      }
199    }