001    /* _PolicyStub.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 org.omg.CORBA.MARSHAL;
042    import org.omg.CORBA.portable.ApplicationException;
043    import org.omg.CORBA.portable.Delegate;
044    import org.omg.CORBA.portable.InputStream;
045    import org.omg.CORBA.portable.ObjectImpl;
046    import org.omg.CORBA.portable.OutputStream;
047    import org.omg.CORBA.portable.RemarshalException;
048    
049    import java.io.Serializable;
050    
051    /**
052     * The Policy stub (proxy), used on the client side.
053     * The {@link Policy} methods contain the code for remote
054     * invocaton.
055     *
056     * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
057     */
058    public class _PolicyStub
059      extends ObjectImpl
060      implements Policy, Serializable
061    {
062      /**
063       * Use serialVersionUID (v1.4) for interoperability.
064       */
065      private static final long serialVersionUID = 2453656196708903849L;
066    
067      /**
068       * Create the Policy stub. To get the stub working,
069       * you must later set the delegate with
070       * {@link ObjectImpl#_set_delegate(Delegate)}.
071       */
072      public _PolicyStub()
073      {
074      }
075    
076      /**
077       * Create the naming context stub with the given delegate.
078       */
079      public _PolicyStub(Delegate delegate)
080      {
081        _set_delegate(delegate);
082      }
083    
084      /**
085       * Return the array of repository ids for this object.
086       */
087      public String[] _ids()
088      {
089        return new String[] { PolicyHelper.id() };
090      }
091    
092      /** {@inheritDoc} */
093      public void destroy()
094      {
095        InputStream input = null;
096        try
097          {
098            OutputStream output = _request("destroy", true);
099            input = _invoke(output);
100          }
101        catch (ApplicationException ex)
102          {
103            input = ex.getInputStream();
104    
105            String id = ex.getId();
106            throw new MARSHAL(id);
107          }
108        catch (RemarshalException remarsh)
109          {
110            destroy();
111          }
112        finally
113          {
114            _releaseReply(input);
115          }
116      }
117    
118      /** {@inheritDoc} */
119      public Policy copy()
120      {
121        InputStream input = null;
122        try
123          {
124            OutputStream output = _request("copy", true);
125            input = _invoke(output);
126            return PolicyHelper.read(input);
127          }
128        catch (ApplicationException ex)
129          {
130            input = ex.getInputStream();
131    
132            String id = ex.getId();
133            throw new MARSHAL(id);
134          }
135        catch (RemarshalException remarsh)
136          {
137            return copy();
138          }
139        finally
140          {
141            _releaseReply(input);
142          }
143      }
144    
145      /** {@inheritDoc} */
146      public int policy_type()
147      {
148        InputStream input = null;
149        try
150          {
151            OutputStream output = _request("policy_type", true);
152            input = _invoke(output);
153    
154            int returns = input.read_long();
155    
156            return returns;
157          }
158        catch (ApplicationException ex)
159          {
160            input = ex.getInputStream();
161    
162            String id = ex.getId();
163            throw new MARSHAL(id);
164          }
165        catch (RemarshalException remarsh)
166          {
167            return policy_type();
168          }
169        finally
170          {
171            _releaseReply(input);
172          }
173      }
174    }