Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / CORBA / Poa / ORB_1_4.java
blobbb00aab70eb1c2307966ea26c50d2364999e4373
1 /* ORB_1_4.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)
9 any later version.
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
19 02110-1301 USA.
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.
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.OrbFunctional;
42 import gnu.CORBA.IOR;
43 import gnu.CORBA.Connected_objects.cObject;
44 import gnu.CORBA.DynAn.gnuDynAnyFactory;
45 import gnu.CORBA.Interceptor.ClientRequestInterceptors;
46 import gnu.CORBA.Interceptor.IORInterceptors;
47 import gnu.CORBA.Interceptor.Registrator;
48 import gnu.CORBA.Interceptor.ServerRequestInterceptors;
49 import gnu.CORBA.Interceptor.gnuIcCurrent;
50 import gnu.CORBA.Interceptor.gnuIorInfo;
52 import org.omg.CORBA.Any;
53 import org.omg.CORBA.BAD_OPERATION;
54 import org.omg.CORBA.BAD_PARAM;
55 import org.omg.CORBA.OBJECT_NOT_EXIST;
56 import org.omg.CORBA.ORB;
57 import org.omg.CORBA.Policy;
58 import org.omg.CORBA.PolicyError;
59 import org.omg.CORBA.portable.ObjectImpl;
60 import org.omg.PortableInterceptor.PolicyFactory;
61 import org.omg.PortableServer.Servant;
62 import org.omg.PortableServer.POAManagerPackage.State;
63 import org.omg.PortableServer.POAPackage.InvalidPolicy;
65 import java.applet.Applet;
66 import java.util.Properties;
68 /**
69 * The ORB, supporting POAs that are the feature of jdk 1.4.
71 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
73 public class ORB_1_4
74 extends OrbFunctional
76 /**
77 * The root POA.
79 public final gnuPOA rootPOA;
81 /**
82 * Maps the active threads to the invocation data ("POA Current's").
84 public gnuPoaCurrent currents = new gnuPoaCurrent();
86 /**
87 * Maps the active threads to the interceptor data ("Interceptor Current's").
89 public gnuIcCurrent ic_current = new gnuIcCurrent(this);
91 /**
92 * Creates dynamic anys.
94 public gnuDynAnyFactory factory = new gnuDynAnyFactory(this);
96 /**
97 * Calls the parent constructor and additionally puts the "RootPOA",
98 * "RootPOAManager", "POACurrent" and "DynAnyFactory" into initial references.
100 public ORB_1_4()
102 super();
105 rootPOA = new gnuPOA(null, "RootPOA", null, StandardPolicies.rootPoa(), this);
107 catch (InvalidPolicy ex)
109 // Invalid default policy set.
110 InternalError ierr = new InternalError();
111 ierr.initCause(ex);
112 throw ierr;
114 initial_references.put("RootPOA", rootPOA);
115 initial_references.put("RootPOAManager", rootPOA.the_POAManager());
116 initial_references.put("POACurrent", currents);
117 initial_references.put("DynAnyFactory", factory);
118 initial_references.put("PICurrent", ic_current);
122 * If the super method detects that the object is not connected to this ORB,
123 * try to find and activate the object.
125 public String object_to_string(org.omg.CORBA.Object forObject)
129 return super.object_to_string(forObject);
131 catch (Exception ex)
135 AOM.Obj exists = rootPOA.findObject(forObject);
136 if (exists == null)
137 throw new OBJECT_NOT_EXIST(forObject == null ? "null"
138 : forObject.toString());
139 else if (exists.poa instanceof gnuPOA)
140 ((gnuPOA) exists.poa).connect_to_orb(exists.key, forObject);
141 else
142 exists.poa.create_reference_with_id(exists.key,
143 ((ObjectImpl) exists.object)._ids()[0]);
145 catch (Exception bex)
147 BAD_PARAM bad = new BAD_PARAM("Unable to activate " + forObject);
148 bad.initCause(bex);
149 throw bad;
152 return super.object_to_string(forObject);
157 * Destroy all poas and then call the superclass method.
159 public void destroy()
161 // This will propagate through the whole POA tree.
162 rootPOA.destroy(true, false);
164 super.destroy();
168 * Do interceptor registration.
170 * @param properties the properties, between those names the agreed prefix
171 * "org.omg.PortableInterceptor.ORBInitializerClass." is searched.
173 * @param args the string array, passed to the ORB.init
175 protected void registerInterceptors(Properties properties, String[] args)
177 Registrator registrator = new Registrator(this, properties, args);
179 policyFactories = registrator.m_policyFactories;
181 registrator.pre_init();
182 initial_references.putAll(registrator.getRegisteredReferences());
183 registrator.post_init();
185 if (registrator.hasIorInterceptors())
186 iIor = new IORInterceptors(registrator);
188 if (registrator.hasServerRequestInterceptors())
189 iServer = new ServerRequestInterceptors(registrator);
191 if (registrator.hasClientRequestInterceptors())
192 iClient = new ClientRequestInterceptors(registrator);
194 policyFactories = registrator.m_policyFactories;
198 * Create IOR and allow registered interceptors to add additional components.
200 protected IOR createIOR(cObject ref)
201 throws BAD_OPERATION
203 IOR ior = super.createIOR(ref);
204 if (iIor != null)
206 AOM.Obj obj = rootPOA.findIorKey(ior.key);
208 gnuPOA poa;
210 // Null means that the object was connected to the ORB directly.
211 if (obj == null)
212 poa = rootPOA;
213 else
214 poa = obj.poa;
216 gnuIorInfo info = new gnuIorInfo(this, poa, ior);
218 // This may modify the ior.
219 iIor.establish_components(info);
220 iIor.components_established(info);
222 return ior;
226 * Create policy using the previously registered factory.
228 public Policy create_policy(int type, Any value)
229 throws PolicyError
231 Integer policy = new Integer(type);
233 PolicyFactory forge = (PolicyFactory) policyFactories.get(policy);
234 if (forge == null)
235 throw new PolicyError("No factory registered for policy " + type,
236 (short) type);
237 else
238 return forge.create_policy(type, value);
242 * Set the parameters and then register interceptors.
244 protected void set_parameters(Applet app, Properties props)
246 super.set_parameters(app, props);
247 registerInterceptors(props, new String[0]);
251 * Set the parameters and then register interceptors.
253 protected void set_parameters(String[] para, Properties props)
255 super.set_parameters(para, props);
256 registerInterceptors(props, para);
260 * This method is called by RMI-IIOP {@link javax.rmi.Tie#orb(ORB)}, passing
261 * <code>this</code> as parameter. The ORB will try to connect that tie as
262 * one of its objects, if it is not already connected. If the wrapper is an
263 * instance of Servant this method also activates the root poa (if not already
264 * active).
266 public void set_delegate(java.lang.Object wrapper)
268 if (wrapper instanceof org.omg.CORBA.Object)
270 org.omg.CORBA.Object object = (org.omg.CORBA.Object) wrapper;
271 if (connected_objects.getKey(object) == null)
272 connect(object);
274 else if (wrapper instanceof Servant)
276 Servant s = (Servant) wrapper;
277 if (rootPOA.findServant(s) == null)
280 rootPOA.servant_to_reference(s);
281 if (rootPOA.the_POAManager().get_state().value() == State._HOLDING)
282 rootPOA.the_POAManager().activate();
284 catch (Exception e)
286 BAD_OPERATION bad = new BAD_OPERATION("Unable to connect "
287 + wrapper + " to " + this);
288 throw bad;