1 19 package gcc.rmi.iiop.server; 20 21 import gcc.rmi.iiop.*; 22 import gcc.org.omg.CosNaming.*; 23 import gcc.org.omg.CosNaming.NamingContextPackage.*; 24 import gcc.org.omg.CosNaming.NamingContextExtPackage.*; 25 import gcc.naming.NameService; 26 import gcc.naming.NameServiceLog; 27 import gcc.adapter.Adapter; 28 29 import javax.naming.*; 30 31 public class ServerNamingContext 32 implements gcc.rmi.iiop.NameServiceOperations 33 { 34 protected static ServerNamingContext _snc = null; 35 36 public static ServerNamingContext getInstance() 37 { 38 if (_snc == null) 39 { 40 synchronized( ServerNamingContext.class ) 41 { 42 _snc = new ServerNamingContext(); 43 _snc.init(); 44 } 45 } 46 47 return _snc; 48 } 49 50 54 private NameService _nameService; 55 56 private volatile int _cycle; 57 58 62 public org.omg.CORBA.Object resolve_str(String name) throws NotFound, CannotProceed, InvalidName 63 { 64 return lookup(name, null); 65 } 66 67 68 public String to_string (NameComponent[] n) throws InvalidName 69 { 70 throw NoImplement(); 71 } 72 73 public NameComponent[] to_name (String sn) throws InvalidName 74 { 75 throw NoImplement(); 76 } 77 78 public String to_url (String addr, String sn) throws InvalidAddress, InvalidName 79 { 80 throw NoImplement(); 81 } 82 83 87 public org.omg.CORBA.Object resolve(NameComponent[] name) throws NotFound, CannotProceed, InvalidName 88 { 89 return lookup(toString(name), name); 90 } 91 92 public void bind (NameComponent[] n, org.omg.CORBA.Object obj) throws NotFound, CannotProceed, InvalidName, AlreadyBound 93 { 94 throw NoImplement(); 95 } 96 97 public void bind_context (gcc.org.omg.CosNaming.NameComponent[] n, gcc.org.omg.CosNaming.NamingContext nc) throws NotFound, CannotProceed, InvalidName, AlreadyBound 98 { 99 throw NoImplement(); 100 } 101 102 public void rebind (gcc.org.omg.CosNaming.NameComponent[] n, org.omg.CORBA.Object obj) throws NotFound, CannotProceed, InvalidName 103 { 104 throw NoImplement(); 105 } 106 107 public void rebind_context (gcc.org.omg.CosNaming.NameComponent[] n, gcc.org.omg.CosNaming.NamingContext nc) throws NotFound, CannotProceed, InvalidName 108 { 109 throw NoImplement(); 110 } 111 112 public void unbind (NameComponent[] n) throws NotFound, CannotProceed, InvalidName 113 { 114 throw NoImplement(); 115 } 116 117 public void list (int how_many, BindingListHolder bl, BindingIteratorHolder bi) 118 { 119 throw NoImplement(); 120 } 121 122 public NamingContext new_context () 123 { 124 throw NoImplement(); 125 } 126 127 public NamingContext bind_new_context (NameComponent[] n) throws NotFound, AlreadyBound, CannotProceed, InvalidName 128 { 129 throw NoImplement(); 130 } 131 132 protected org.omg.CORBA.NO_IMPLEMENT NoImplement() 133 { 134 return new org.omg.CORBA.NO_IMPLEMENT(); 135 } 136 137 141 public String resolve_host(String host) 142 { 143 System.out.println( "ServerNamingContext.resolve_host(): TODO host = " + host ); 144 145 148 151 return host; 152 } 153 154 158 protected void init() 159 { 160 _nameService = NameService.getInstance(); 161 } 162 163 protected org.omg.CORBA.Object lookup(String nameString, NameComponent[] name) throws NotFound 164 { 165 try 166 { 167 Object object = _nameService.lookup(nameString); 168 169 181 182 if (object instanceof Adapter) 183 { 184 Adapter a = (Adapter)object; 185 RemoteInterface remote = a.getRemoteInterface(); 186 return remote.$getObjectRef(); 187 } 188 else 189 { 190 NameServiceLog.getInstance().warnObjectHasNoRemoteInterface(nameString, object.getClass().getName()); 191 throw new NotFound(NotFoundReason.not_object, name); 192 } 193 } 194 catch (NameNotFoundException notFound) 195 { 196 throw new NotFound(NotFoundReason.missing_node, name); 198 } 199 catch (NamingException ex) 200 { 201 NameServiceLog.getInstance().warnNameNotFound(nameString, ex); 202 throw new NotFound(NotFoundReason.missing_node, name); 203 } 204 } 205 206 protected String toString(NameComponent[] name) 207 { 208 int n = name.length; 209 if (n == 1) 210 { 211 return name[0].id; 212 } 213 else 214 { 215 StringBuffer nameBuffer = new StringBuffer(); 216 for (int i = 0; i < n; i++) 217 { 218 if (i > 0) 219 { 220 nameBuffer.append('/'); 221 } 222 nameBuffer.append(name[i].id); 223 if (name[i].kind.length() > 0) 224 { 225 nameBuffer.append(",kind="); 226 nameBuffer.append(name[i].kind); 227 } 228 } 229 return nameBuffer.toString(); 230 } 231 } 232 } 233 | Popular Tags |