}
void uTestReferenceToServant(ORB orb, POA root)
{
org.omg.CORBA.Object obj;
POA retain;
POA defaultPOA;
byte[] id1;
byte[] id2;
byte[] tmpid;
Policy[] policies;
Test_impl def;
Test_impl servant1;
Test_impl servant2;
Servant tmpservant;
POAManager manager = root.the_POAManager();
//
// Create POA w/ RETAIN
//
policies = new Policy[ 3 ];
policies [ 0 ] =
root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN);
policies [ 1 ] =
root.create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.TRANSIENT);
policies [ 2 ] =
root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID);
try
{
retain = root.create_POA("retain", manager, policies);
}
catch (AdapterAlreadyExists ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (InvalidPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
//
// Create POA w/ USE_DEFAULT_SERVANT
//
policies = new Policy[ 5 ];
policies [ 0 ] =
root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID);
policies [ 1 ] =
root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN);
policies [ 2 ] =
root.create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_DEFAULT_SERVANT);
policies [ 3 ] =
root.create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.TRANSIENT);
policies [ 4 ] =
root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID);
try
{
defaultPOA = root.create_POA("default", manager, policies);
}
catch (AdapterAlreadyExists ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (InvalidPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
def = new Test_impl(orb, "default", false);
try
{
defaultPOA.set_servant(def);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
servant1 = new Test_impl(orb, "test1", false);
servant2 = new Test_impl(orb, "test2", false);
//
// Test: ObjectNotActive exception
//
try
{
tmpid = ("bad_id").getBytes();
obj = retain.create_reference_with_id(tmpid, "IDL:Test:1.0");
retain.reference_to_servant(obj);
TEST(false); // reference_to_servant should not have succeeded
}
catch (ObjectNotActive ex)
{
// expected
}
catch (WrongAdapter ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
id1 = ("test1").getBytes();
id2 = ("test2").getBytes();
try
{
retain.activate_object_with_id(id1, servant1);
retain.activate_object_with_id(id2, servant2);
}
catch (ObjectAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ServantAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
//
// Test: reference_to_servant (USE_DEFAULT_SERVANT)
//
try
{
defaultPOA.activate_object_with_id(id1, servant1);
defaultPOA.activate_object_with_id(id2, servant2);
}
catch (ObjectAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ServantAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
//
// Test: reference_to_servant (USE_DEFAULT_SERVANT) - should return
// default servant for all unknown IDs
//
tmpid = ("test99").getBytes();
obj = defaultPOA.create_reference_with_id(tmpid, "IDL:Test:1.0");
try
{
tmpservant = defaultPOA.reference_to_servant(obj);
}
catch (WrongAdapter ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(tmpservant == def);
tmpservant = null;
retain.destroy(true, true);
defaultPOA.destroy(true, true);
}