OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / classpath / examples / gnu / classpath / examples / CORBA / swing / x5 / _GameManagerImpl_Tie.java
1 /* _GameManagerImpl_Tie.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 gnu.classpath.examples.CORBA.swing.x5;
40
41 import java.rmi.Remote;
42
43 import javax.rmi.PortableRemoteObject;
44 import javax.rmi.CORBA.Tie;
45
46 import org.omg.CORBA.BAD_OPERATION;
47 import org.omg.CORBA.ORB;
48 import org.omg.CORBA.SystemException;
49 import org.omg.CORBA.portable.InputStream;
50 import org.omg.CORBA.portable.OutputStream;
51 import org.omg.CORBA.portable.ResponseHandler;
52 import org.omg.CORBA.portable.UnknownException;
53 import org.omg.PortableServer.Servant;
54
55 /**
56  * Normally generated with rmic compiler, this class represents the GameManager
57  * Tie on the client side. The Game Manager methods contain the code for remote
58  * invocation.
59  * 
60  * This class is normally generated with rmic or grmic from the 
61  * {@link GameManagerImpl}. See tools/gnu/classpath/tools/giop/README.
62  * 
63  * In this example the class was manually edited and commented for better
64  * understanding of functionality.
65  * 
66  * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) 
67  */
68 public class _GameManagerImpl_Tie
69   extends Servant
70   implements Tie
71 {
72   /**
73    * The target, where remote invocations are forwarded.
74    */
75   private GameManagerImpl target = null;
76
77   /**
78    * The GameManager repository Id.
79    */
80   private static final String[] _type_ids = 
81   { "RMI:gnu.classpath.examples.CORBA.swing.x5.GameManager:0000000000000000" };
82
83   /**
84    * Set the target where the remote invocations are forwarded.
85    */
86   public void setTarget(Remote a_target)
87   {
88     this.target = (GameManagerImpl) a_target;
89   }
90
91   /**
92    * Get the target where the remote invocations are forwarded.
93    */
94   public Remote getTarget()
95   {
96     return target;
97   }
98
99   /**
100    * Get the CORBA object for that this Tie is currently serving the request.
101    * The same tie may serve multiple requests for the different objects in
102    * parallel threads.
103    */
104   public org.omg.CORBA.Object thisObject()
105   {
106     return _this_object();
107   }
108
109   /**
110    * Deactivate this object.
111    */
112   public void deactivate()
113   {
114     try
115       {
116         _poa().deactivate_object(_poa().servant_to_id(this));
117       }
118     catch (org.omg.PortableServer.POAPackage.WrongPolicy exception)
119       {
120       }
121     catch (org.omg.PortableServer.POAPackage.ObjectNotActive exception)
122       {
123       }
124     catch (org.omg.PortableServer.POAPackage.ServantNotActive exception)
125       {
126       }
127   }
128
129   /**
130    * Get the ORB for this tie.
131    */
132   public ORB orb()
133   {
134     return _orb();
135   }
136
137   /**
138    * Set the ORB for this tie.
139    */
140   public void orb(ORB orb)
141   {
142     try
143       {
144         ((org.omg.CORBA_2_3.ORB) orb).set_delegate(this);
145       }
146     catch (ClassCastException e)
147       {
148         throw new org.omg.CORBA.BAD_PARAM(
149           "POA Servant requires an instance of org.omg.CORBA_2_3.ORB");
150       }
151   }
152
153   /**
154    * Return all interfaces, supported by this method.
155    */
156   public String[] _all_interfaces(org.omg.PortableServer.POA poa,
157     byte[] objectId)
158   {
159     return _type_ids;
160   }
161
162   /**
163    * This method is invoked by CORBA system to handle the remote invocation.
164    * 
165    * @param method the name of the method being invoked.
166    * @param _in the stream to read the method parameters.
167    * @param reply the responsed handler that can create the output stream to
168    * write the parameters being returned.
169    */
170   public OutputStream _invoke(String method, InputStream _in,
171     ResponseHandler reply)
172     throws SystemException
173   {
174     try
175       {
176         org.omg.CORBA_2_3.portable.InputStream in = 
177           (org.omg.CORBA_2_3.portable.InputStream) _in;
178         if (method.equals("requestTheGame"))
179           {
180             Player p = (Player) PortableRemoteObject.narrow(
181               in.read_Object(), Player.class);
182             target.requestTheGame(p);
183
184             OutputStream out = reply.createReply();
185             return out;
186           }
187         else if (method.equals("unregister"))
188           {
189             Player p = (Player) PortableRemoteObject.narrow(
190               in.read_Object(), Player.class);
191             target.unregister(p);
192
193             OutputStream out = reply.createReply();
194             return out;
195           }
196         else
197           throw new BAD_OPERATION();
198       }
199     catch (SystemException ex)
200       {
201         throw ex;
202       }
203     catch (Throwable ex)
204       {
205         ex.printStackTrace();
206         throw new UnknownException(ex);
207       }
208   }
209 }