1 /* ServantDelegateImpl.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
39 package gnu
.CORBA
.Poa
;
41 import gnu
.CORBA
.Unexpected
;
43 import org
.omg
.CORBA
.NO_IMPLEMENT
;
44 import org
.omg
.CORBA
.ORB
;
45 import org
.omg
.CORBA
.ORBPackage
.InvalidName
;
46 import org
.omg
.CORBA
.Object
;
47 import org
.omg
.PortableServer
.CurrentPackage
.NoContext
;
48 import org
.omg
.PortableServer
.POA
;
49 import org
.omg
.PortableServer
.POAHelper
;
50 import org
.omg
.PortableServer
.Servant
;
51 import org
.omg
.PortableServer
.portable
.Delegate
;
54 * The implementation of the servant delegate for the locally existing
55 * servant.The associated servant that must also implement the
56 * {@link InvokeHandler} interface. Each servant requires a separate
57 * instance of this delegate and can serve a single object only.
58 * Hence the fields are final, but the delegate is typically reused
59 * unless the same servant is connected to different objects.
61 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
63 public class ServantDelegateImpl
67 * The servant, associated with this object.
69 final Servant servant
;
72 * The servant (not object) id.
74 final byte[] servant_id
;
77 * The POA, where the servant is connected.
82 * The object, exposed as an object, served by this servant.
84 final gnuServantObject object
;
87 * Create the delegat for the servant that will be connected to the
88 * given poa. The method is normally called from inside of gnuPOA.
89 * The constructor sets the newly created delegate as the delegate to this
90 * servant by calling Servant._set_delegate.
92 * @param a_poa the poa.
93 * @param a_servant the servant.
94 * @param a_servant_id the servant id.
96 public ServantDelegateImpl(Servant a_servant
, gnuPOA a_poa
, byte[] a_servant_id
)
100 servant_id
= a_servant_id
;
101 servant
._set_delegate(this);
103 new gnuServantObject(servant
, servant_id
, (ORB_1_4
) servant
._orb(), a_poa
);
104 object
._set_delegate(new LocalDelegate(object
, poa
, a_servant_id
));
108 * Check if this object could be named by the given repository id.
109 * @param idl_id the repository id to check.
111 * @return true if it is one of the possible repository ids of this
114 public boolean is_a(Servant a_servant
, String idl_id
)
118 String
[] maybe
= object
.repository_ids
;
120 maybe
= servant
._all_interfaces(poa
, object
.Id
);
121 for (int i
= 0; i
< maybe
.length
; i
++)
123 if (maybe
[ i
].equals(idl_id
))
130 * Return the ORB's default POA.
132 public POA
default_POA(Servant a_servant
)
137 return POAHelper
.narrow(orb(a_servant
).resolve_initial_references("RootPOA"));
139 catch (InvalidName ex
)
141 throw new Unexpected(ex
);
148 public ORB
orb(Servant a_servant
)
155 * Get the object, exposing the servant.
157 public Object
this_object(Servant a_servant
)
162 return poa
.aom
.get(poa
.m_orb
.currents
.get_object_id()).object
;
173 * @specnote Same as for Sun up till 1.5 inclusive.
175 public Object
get_interface_def(Servant a_servant
)
178 throw new NO_IMPLEMENT();
182 * Get the Id of the object being currently served.
184 public byte[] object_id(Servant a_servant
)
189 byte[] id
= poa
.m_orb
.currents
.get_object_id();
199 * Always returns false;
201 public boolean non_existent(Servant a_servant
)
208 * Return the associated POA.
210 public POA
poa(Servant a_servant
)
215 return poa
.m_orb
.currents
.get_POA();
224 * Checks if the passed servant is the same as the servant, associated with
225 * this delegate. This class requires a single servant per delegate.
227 void same(Servant some_servant
)
229 if (servant
!= some_servant
)
230 throw new InternalError("Only one servant per delegate is supported.");