| 1 |
14 |
jlechner |
/* ORB_1_4.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.CORBA.Poa;
|
| 40 |
|
|
|
| 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;
|
| 51 |
|
|
|
| 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;
|
| 64 |
|
|
|
| 65 |
|
|
import java.applet.Applet;
|
| 66 |
|
|
import java.util.Properties;
|
| 67 |
|
|
|
| 68 |
|
|
/**
|
| 69 |
|
|
* The ORB, supporting POAs that are the feature of jdk 1.4.
|
| 70 |
|
|
*
|
| 71 |
|
|
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
| 72 |
|
|
*/
|
| 73 |
|
|
public class ORB_1_4
|
| 74 |
|
|
extends OrbFunctional
|
| 75 |
|
|
{
|
| 76 |
|
|
/**
|
| 77 |
|
|
* The root POA.
|
| 78 |
|
|
*/
|
| 79 |
|
|
public final gnuPOA rootPOA;
|
| 80 |
|
|
|
| 81 |
|
|
/**
|
| 82 |
|
|
* Maps the active threads to the invocation data ("POA Current's").
|
| 83 |
|
|
*/
|
| 84 |
|
|
public gnuPoaCurrent currents = new gnuPoaCurrent();
|
| 85 |
|
|
|
| 86 |
|
|
/**
|
| 87 |
|
|
* Maps the active threads to the interceptor data ("Interceptor Current's").
|
| 88 |
|
|
*/
|
| 89 |
|
|
public gnuIcCurrent ic_current = new gnuIcCurrent(this);
|
| 90 |
|
|
|
| 91 |
|
|
/**
|
| 92 |
|
|
* Creates dynamic anys.
|
| 93 |
|
|
*/
|
| 94 |
|
|
public gnuDynAnyFactory factory = new gnuDynAnyFactory(this);
|
| 95 |
|
|
|
| 96 |
|
|
/**
|
| 97 |
|
|
* Calls the parent constructor and additionally puts the "RootPOA",
|
| 98 |
|
|
* "RootPOAManager", "POACurrent" and "DynAnyFactory" into initial references.
|
| 99 |
|
|
*/
|
| 100 |
|
|
public ORB_1_4()
|
| 101 |
|
|
{
|
| 102 |
|
|
super();
|
| 103 |
|
|
try
|
| 104 |
|
|
{
|
| 105 |
|
|
rootPOA = new gnuPOA(null, "RootPOA", null, StandardPolicies.rootPoa(), this);
|
| 106 |
|
|
}
|
| 107 |
|
|
catch (InvalidPolicy ex)
|
| 108 |
|
|
{
|
| 109 |
|
|
// Invalid default policy set.
|
| 110 |
|
|
InternalError ierr = new InternalError();
|
| 111 |
|
|
ierr.initCause(ex);
|
| 112 |
|
|
throw ierr;
|
| 113 |
|
|
}
|
| 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);
|
| 119 |
|
|
}
|
| 120 |
|
|
|
| 121 |
|
|
/**
|
| 122 |
|
|
* If the super method detects that the object is not connected to this ORB,
|
| 123 |
|
|
* try to find and activate the object.
|
| 124 |
|
|
*/
|
| 125 |
|
|
public String object_to_string(org.omg.CORBA.Object forObject)
|
| 126 |
|
|
{
|
| 127 |
|
|
try
|
| 128 |
|
|
{
|
| 129 |
|
|
return super.object_to_string(forObject);
|
| 130 |
|
|
}
|
| 131 |
|
|
catch (Exception ex)
|
| 132 |
|
|
{
|
| 133 |
|
|
try
|
| 134 |
|
|
{
|
| 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]);
|
| 144 |
|
|
}
|
| 145 |
|
|
catch (Exception bex)
|
| 146 |
|
|
{
|
| 147 |
|
|
BAD_PARAM bad = new BAD_PARAM("Unable to activate " + forObject);
|
| 148 |
|
|
bad.initCause(bex);
|
| 149 |
|
|
throw bad;
|
| 150 |
|
|
}
|
| 151 |
|
|
|
| 152 |
|
|
return super.object_to_string(forObject);
|
| 153 |
|
|
}
|
| 154 |
|
|
}
|
| 155 |
|
|
|
| 156 |
|
|
/**
|
| 157 |
|
|
* Destroy all poas and then call the superclass method.
|
| 158 |
|
|
*/
|
| 159 |
|
|
public void destroy()
|
| 160 |
|
|
{
|
| 161 |
|
|
// This will propagate through the whole POA tree.
|
| 162 |
|
|
rootPOA.destroy(true, false);
|
| 163 |
|
|
|
| 164 |
|
|
super.destroy();
|
| 165 |
|
|
}
|
| 166 |
|
|
|
| 167 |
|
|
/**
|
| 168 |
|
|
* Do interceptor registration.
|
| 169 |
|
|
*
|
| 170 |
|
|
* @param properties the properties, between those names the agreed prefix
|
| 171 |
|
|
* "org.omg.PortableInterceptor.ORBInitializerClass." is searched.
|
| 172 |
|
|
*
|
| 173 |
|
|
* @param args the string array, passed to the ORB.init
|
| 174 |
|
|
*/
|
| 175 |
|
|
protected void registerInterceptors(Properties properties, String[] args)
|
| 176 |
|
|
{
|
| 177 |
|
|
Registrator registrator = new Registrator(this, properties, args);
|
| 178 |
|
|
|
| 179 |
|
|
policyFactories = registrator.m_policyFactories;
|
| 180 |
|
|
|
| 181 |
|
|
registrator.pre_init();
|
| 182 |
|
|
initial_references.putAll(registrator.getRegisteredReferences());
|
| 183 |
|
|
registrator.post_init();
|
| 184 |
|
|
|
| 185 |
|
|
if (registrator.hasIorInterceptors())
|
| 186 |
|
|
iIor = new IORInterceptors(registrator);
|
| 187 |
|
|
|
| 188 |
|
|
if (registrator.hasServerRequestInterceptors())
|
| 189 |
|
|
iServer = new ServerRequestInterceptors(registrator);
|
| 190 |
|
|
|
| 191 |
|
|
if (registrator.hasClientRequestInterceptors())
|
| 192 |
|
|
iClient = new ClientRequestInterceptors(registrator);
|
| 193 |
|
|
|
| 194 |
|
|
policyFactories = registrator.m_policyFactories;
|
| 195 |
|
|
}
|
| 196 |
|
|
|
| 197 |
|
|
/**
|
| 198 |
|
|
* Create IOR and allow registered interceptors to add additional components.
|
| 199 |
|
|
*/
|
| 200 |
|
|
protected IOR createIOR(cObject ref)
|
| 201 |
|
|
throws BAD_OPERATION
|
| 202 |
|
|
{
|
| 203 |
|
|
IOR ior = super.createIOR(ref);
|
| 204 |
|
|
if (iIor != null)
|
| 205 |
|
|
{
|
| 206 |
|
|
AOM.Obj obj = rootPOA.findIorKey(ior.key);
|
| 207 |
|
|
|
| 208 |
|
|
gnuPOA poa;
|
| 209 |
|
|
|
| 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;
|
| 215 |
|
|
|
| 216 |
|
|
gnuIorInfo info = new gnuIorInfo(this, poa, ior);
|
| 217 |
|
|
|
| 218 |
|
|
// This may modify the ior.
|
| 219 |
|
|
iIor.establish_components(info);
|
| 220 |
|
|
iIor.components_established(info);
|
| 221 |
|
|
}
|
| 222 |
|
|
return ior;
|
| 223 |
|
|
}
|
| 224 |
|
|
|
| 225 |
|
|
/**
|
| 226 |
|
|
* Create policy using the previously registered factory.
|
| 227 |
|
|
*/
|
| 228 |
|
|
public Policy create_policy(int type, Any value)
|
| 229 |
|
|
throws PolicyError
|
| 230 |
|
|
{
|
| 231 |
|
|
Integer policy = new Integer(type);
|
| 232 |
|
|
|
| 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);
|
| 239 |
|
|
}
|
| 240 |
|
|
|
| 241 |
|
|
/**
|
| 242 |
|
|
* Set the parameters and then register interceptors.
|
| 243 |
|
|
*/
|
| 244 |
|
|
protected void set_parameters(Applet app, Properties props)
|
| 245 |
|
|
{
|
| 246 |
|
|
super.set_parameters(app, props);
|
| 247 |
|
|
registerInterceptors(props, new String[0]);
|
| 248 |
|
|
}
|
| 249 |
|
|
|
| 250 |
|
|
/**
|
| 251 |
|
|
* Set the parameters and then register interceptors.
|
| 252 |
|
|
*/
|
| 253 |
|
|
protected void set_parameters(String[] para, Properties props)
|
| 254 |
|
|
{
|
| 255 |
|
|
super.set_parameters(para, props);
|
| 256 |
|
|
registerInterceptors(props, para);
|
| 257 |
|
|
}
|
| 258 |
|
|
|
| 259 |
|
|
/**
|
| 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).
|
| 265 |
|
|
*/
|
| 266 |
|
|
public void set_delegate(java.lang.Object wrapper)
|
| 267 |
|
|
{
|
| 268 |
|
|
if (wrapper instanceof org.omg.CORBA.Object)
|
| 269 |
|
|
{
|
| 270 |
|
|
org.omg.CORBA.Object object = (org.omg.CORBA.Object) wrapper;
|
| 271 |
|
|
if (connected_objects.getKey(object) == null)
|
| 272 |
|
|
connect(object);
|
| 273 |
|
|
}
|
| 274 |
|
|
else if (wrapper instanceof Servant)
|
| 275 |
|
|
{
|
| 276 |
|
|
Servant s = (Servant) wrapper;
|
| 277 |
|
|
if (rootPOA.findServant(s) == null)
|
| 278 |
|
|
try
|
| 279 |
|
|
{
|
| 280 |
|
|
rootPOA.servant_to_reference(s);
|
| 281 |
|
|
if (rootPOA.the_POAManager().get_state().value() == State._HOLDING)
|
| 282 |
|
|
rootPOA.the_POAManager().activate();
|
| 283 |
|
|
}
|
| 284 |
|
|
catch (Exception e)
|
| 285 |
|
|
{
|
| 286 |
|
|
BAD_OPERATION bad = new BAD_OPERATION("Unable to connect "
|
| 287 |
|
|
+ wrapper + " to " + this);
|
| 288 |
|
|
throw bad;
|
| 289 |
|
|
}
|
| 290 |
|
|
}
|
| 291 |
|
|
}
|
| 292 |
|
|
|
| 293 |
|
|
}
|