public static void main(String[] args) throws Exception {
// Initialize ORB
ORB orb = ORB.init(new String[0], null);
System.out.println("ORB: " + orb.getClass().getName());
POA rootPoa = (POA) orb.resolve_initial_references("RootPOA");
// Create a POA
Policy[] tpolicy = new Policy[3];
tpolicy[0] = rootPoa.create_lifespan_policy(
LifespanPolicyValue.TRANSIENT );
tpolicy[1] = rootPoa.create_request_processing_policy(
RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY );
tpolicy[2] = rootPoa.create_servant_retention_policy(
ServantRetentionPolicyValue.RETAIN);
POA poa = rootPoa.create_POA("SamplePOA", null, tpolicy);
poa.the_POAManager().activate();
// Create a SampleImpl and bind it to the POA
Sample sample = new SampleImpl();
Tie tie = javax.rmi.CORBA.Util.getTie(sample);
byte[] id = poa.activate_object((Servant) tie);
org.omg.CORBA.Object obj = poa.create_reference_with_id(id, ((Servant)tie)._all_interfaces(poa, id)[0]);
// Write a IOR to a file so the client can obtain a reference to the Sample
File sampleRef = new File("Sample.ref");
PrintWriter writer = new PrintWriter(new FileOutputStream(sampleRef));
writer.write(orb.object_to_string(obj));