1 25 26 package org.jacorb.naming; 27 28 import java.io.File ; 30 import java.io.FileInputStream ; 31 import java.io.FileOutputStream ; 32 import java.io.IOException ; 33 import java.io.ObjectInputStream ; 34 import java.io.ObjectOutputStream ; 35 import java.io.PrintWriter ; 36 37 import org.apache.avalon.framework.configuration.Configuration; 39 import org.apache.avalon.framework.configuration.ConfigurationException; 40 import org.apache.avalon.framework.logger.Logger; 41 42 import org.jacorb.imr.util.ImRManager; 44 import org.jacorb.util.ObjectUtil; 45 46 import org.omg.CORBA.ORB ; 48 import org.omg.PortableServer.ForwardRequest ; 49 import org.omg.PortableServer.IdAssignmentPolicyValue ; 50 import org.omg.PortableServer.LifespanPolicyValue ; 51 import org.omg.PortableServer.RequestProcessingPolicyValue ; 52 import org.omg.PortableServer.POA ; 53 import org.omg.PortableServer.Servant ; 54 import org.omg.PortableServer._ServantActivatorLocalBase; 55 56 57 64 public class EmbeddedNameServer { 65 66 69 public EmbeddedNameServer(ORB orb, POA poa) throws NameServerException { 70 try { 71 Configuration config = 73 ((org.jacorb.orb.ORB)orb).getConfiguration(); 74 75 76 NameServer.configure(config); 77 78 79 org.omg.CORBA.Policy [] policies = new org.omg.CORBA.Policy [3]; 80 policies[0] = 81 poa.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID); 82 policies[1] = 83 poa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT); 84 policies[2] = 85 poa.create_request_processing_policy( 86 RequestProcessingPolicyValue.USE_SERVANT_MANAGER); 87 POA nsPOA = poa.create_POA("NameServer-POA", 88 poa.the_POAManager(), 89 policies); 90 91 NamingContextImpl.init(orb, poa); 92 NameServer.NameServantActivatorImpl servantActivator = 93 new NameServer.NameServantActivatorImpl( orb ); 94 servantActivator.configure(config); 95 NamingContextImpl namingContext = new NamingContextImpl(); 96 nsPOA.set_servant_manager( servantActivator ); 97 nsPOA.the_POAManager().activate(); 98 99 byte[] oid = ( new String ("_root").getBytes() ); 100 org.omg.CORBA.Object obj = 101 nsPOA.create_reference_with_id( oid, 102 "IDL:omg.org/CosNaming/NamingContextExt:1.0"); 103 104 System.out.println("NS SERVER IOR: " + orb.object_to_string(obj)); 105 106 for (int i = 0; i < policies.length; i++) 108 policies[i].destroy(); 109 110 } catch( ConfigurationException ex ) { 111 throw new NameServerException("Failed to init the " + 112 "EmbeddedNameServer : " + ex.getMessage(),ex); 113 } catch( Exception ex ) { 114 throw new NameServerException("Failed to init the " + 115 "EmbeddedNameServer : " + ex.getMessage(),ex); 116 } 117 } 118 119 } 120 | Popular Tags |