1 7 22 23 package com.sun.corba.se.impl.naming.pcosnaming; 24 25 import java.io.File ; 26 import java.util.Properties ; 27 28 import org.omg.CORBA.Policy ; 29 import org.omg.PortableServer.POA ; 30 import org.omg.PortableServer.LifespanPolicyValue ; 31 import org.omg.PortableServer.RequestProcessingPolicyValue ; 32 import org.omg.PortableServer.IdAssignmentPolicyValue ; 33 import org.omg.PortableServer.ServantRetentionPolicyValue ; 34 import org.omg.CosNaming.NamingContext ; 35 import org.omg.CosNaming.NamingContextHelper ; 36 import org.omg.PortableServer.*; 37 38 import com.sun.corba.se.spi.orb.ORB ; 39 40 import com.sun.corba.se.impl.orbutil.ORBConstants ; 41 42 47 48 public class NameService 49 { 50 private NamingContext rootContext = null; 51 private POA nsPOA = null; 52 private ServantManagerImpl contextMgr; 53 private ORB theorb; 54 55 61 public NameService(ORB orb, File logDir) 62 throws Exception 63 { 64 theorb = orb; 65 66 75 POA rootPOA = (POA )orb.resolve_initial_references( 77 ORBConstants.ROOT_POA_NAME ) ; 78 rootPOA.the_POAManager().activate(); 79 80 int i=0; 86 Policy [] poaPolicy = new Policy [4]; 87 poaPolicy[i++] = rootPOA.create_lifespan_policy( 88 LifespanPolicyValue.PERSISTENT); 89 poaPolicy[i++] = rootPOA.create_request_processing_policy( 90 RequestProcessingPolicyValue.USE_SERVANT_MANAGER); 91 poaPolicy[i++] = rootPOA.create_id_assignment_policy( 92 IdAssignmentPolicyValue.USER_ID); 93 poaPolicy[i++] = rootPOA.create_servant_retention_policy( 94 ServantRetentionPolicyValue.NON_RETAIN); 95 96 97 nsPOA = rootPOA.create_POA("NameService", null, poaPolicy); 98 nsPOA.the_POAManager().activate( ); 99 100 contextMgr = new 102 ServantManagerImpl(orb, logDir, this ); 103 104 String rootKey = contextMgr.getRootObjectKey( ); 106 NamingContextImpl nc = 108 new NamingContextImpl( orb, rootKey, this, contextMgr ); 109 nc = contextMgr.addContext( rootKey, nc ); 110 nc.setServantManagerImpl( contextMgr ); 111 nc.setORB( orb ); 112 nc.setRootNameService( this ); 113 114 nsPOA.set_servant_manager(contextMgr); 115 rootContext = NamingContextHelper.narrow( 116 nsPOA.create_reference_with_id( rootKey.getBytes( ), 117 NamingContextHelper.id( ) ) ); 118 } 119 120 123 public NamingContext initialNamingContext() 124 { 125 return rootContext; 126 } 127 128 132 POA getNSPOA( ) { 133 return nsPOA; 134 } 135 136 137 143 public NamingContext NewContext( ) throws org.omg.CORBA.SystemException 144 { 145 try 146 { 147 String newKey = 150 contextMgr.getNewObjectKey( ); 151 NamingContextImpl theContext = 154 new NamingContextImpl( theorb, newKey, 155 this, contextMgr ); 156 NamingContextImpl tempContext = contextMgr.addContext( newKey, 157 theContext ); 158 if( tempContext != null ) 159 { 160 theContext = tempContext; 161 } 162 theContext.setServantManagerImpl( contextMgr ); 165 theContext.setORB( theorb ); 166 theContext.setRootNameService( this ); 167 NamingContext theNewContext = 168 NamingContextHelper.narrow( 169 nsPOA.create_reference_with_id( newKey.getBytes( ), 170 NamingContextHelper.id( )) ); 171 return theNewContext; 172 } 173 catch( org.omg.CORBA.SystemException e ) 174 { 175 throw e; 176 } 177 catch( java.lang.Exception e ) 178 { 179 } 181 return null; 182 } 183 184 189 org.omg.CORBA.Object getObjectReferenceFromKey( String key ) 190 { 191 org.omg.CORBA.Object theObject = null; 192 try 193 { 194 theObject = nsPOA.create_reference_with_id( key.getBytes( ), NamingContextHelper.id( ) ); 195 } 196 catch (Exception e ) 197 { 198 theObject = null; 199 } 200 return theObject; 201 } 202 203 208 String getObjectKey( org.omg.CORBA.Object reference ) 209 { 210 byte theId[]; 211 try 212 { 213 theId = nsPOA.reference_to_id( reference ); 214 } 215 catch( org.omg.PortableServer.POAPackage.WrongAdapter e ) 216 { 217 return null; 218 } 219 catch( org.omg.PortableServer.POAPackage.WrongPolicy e ) 220 { 221 return null; 222 } 223 catch( Exception e ) 224 { 225 return null; 226 } 227 String theKey = new String ( theId ); 228 return theKey; 229 } 230 231 232 } 233 | Popular Tags |