1 26 27 package com.rift.coad.client.naming; 29 30 import java.io.Serializable ; 32 import java.util.Hashtable ; 33 import java.util.Properties ; 34 import javax.naming.CompoundName ; 35 import javax.naming.Context ; 36 import javax.naming.Name ; 37 import javax.naming.NameParser ; 38 import javax.naming.NamingEnumeration ; 39 import javax.naming.NamingException ; 40 import javax.naming.InitialContext ; 41 import org.omg.CORBA.ORB ; 42 43 import org.apache.log4j.Logger; 45 46 import com.rift.coad.lib.interceptor.credentials.Login; 47 48 54 public class CoadunationContext implements Context { 55 56 62 public class NamingParser implements NameParser ,Serializable { 63 64 67 public NamingParser() { 68 } 69 70 71 78 public Name parse(String name) throws NamingException { 79 return new CompoundName (name,syntax); 80 } 81 } 82 83 private static Properties syntax = new Properties (); 85 static { 86 syntax.setProperty("jndi.syntax.direction","left_to_right"); 87 syntax.setProperty("jndi.syntax.separator","/"); 88 syntax.setProperty("jndi.syntax.ignorecase","false"); 89 syntax.setProperty("jndi.syntax.escape","\\"); 90 } 91 protected static Logger log = 92 Logger.getLogger(CoadunationContext.class.getName()); 93 94 private ORB orb = null; 96 private Hashtable env = null; 97 private Context primaryContext = null; 98 private Name prefix = null; 99 100 106 public CoadunationContext(ORB orb,Hashtable env) { 107 this.orb = orb; 108 this.env = env; 109 try { 110 prefix = new NamingParser().parse(""); 111 } catch (Exception ex) { 112 log.error("Failed to parse the name : " + ex.getMessage(),ex); 113 } 114 } 115 116 119 public CoadunationContext(Hashtable env,Name prefix) { 120 this.env = env; 121 this.prefix = prefix; 122 } 123 124 131 public Object addToEnvironment(String propName, Object propVal) throws 132 NamingException { 133 throw new NamingException ("Not implemented"); 134 } 135 136 137 144 public void bind(Name name, Object obj) throws NamingException { 145 throw new NamingException ("Not implemented"); 146 } 147 148 149 152 public void bind(String name, Object obj) throws NamingException { 153 throw new NamingException ("Not implemented"); 154 } 155 156 157 160 public void close() throws NamingException { 161 if (primaryContext != null) { 162 primaryContext.close(); 163 primaryContext = null; 164 } 165 } 166 167 168 176 public Name composeName(Name name, Name prefix) throws NamingException { 177 return null; 178 } 179 180 181 188 public String composeName(String name, String prefix) throws 189 NamingException { 190 return null; 191 } 192 193 194 201 public Context createSubcontext(Name name) throws NamingException { 202 throw new NamingException ("Not implemented"); 203 } 204 205 206 213 public Context createSubcontext(String name) throws NamingException { 214 throw new NamingException ("Not implemented"); 215 } 216 217 218 224 public void destroySubcontext(Name name) throws NamingException { 225 throw new NamingException ("Not implemented"); 226 } 227 228 229 234 public void destroySubcontext(String name) throws NamingException { 235 throw new NamingException ("Not implemented"); 236 } 237 238 239 245 public Hashtable getEnvironment() throws NamingException { 246 return null; 247 } 248 249 250 253 public String getNameInNamespace() throws NamingException { 254 return null; 255 } 256 257 258 265 public NameParser getNameParser(Name name) throws NamingException { 266 return null; 267 } 268 269 270 273 public NameParser getNameParser(String name) throws NamingException { 274 return null; 275 } 276 277 278 282 public NamingEnumeration list(Name name) throws NamingException { 283 throw new NamingException ("Not implemented"); 284 } 285 286 287 295 public NamingEnumeration list(String name) throws NamingException { 296 throw new NamingException ("Not implemented"); 297 } 298 299 300 308 public NamingEnumeration listBindings(Name name) throws NamingException { 309 throw new NamingException ("Not implemented"); 310 } 311 312 313 321 public NamingEnumeration listBindings(String name) throws NamingException { 322 throw new NamingException ("Not implemented"); 323 } 324 325 326 333 public Object lookup(Name name) throws NamingException { 334 Context context = getContext(); 335 String currentName = null; 336 try { 337 if (this.env.containsKey(CoadunationInitialContextFactory.USERNAME) && 338 this.env.containsKey( 339 CoadunationInitialContextFactory.PASSWORD)) { 340 CoadunationInitialContextFactory.userLogin.set( 341 new Login((String )this.env.get( 342 CoadunationInitialContextFactory.USERNAME), 343 (String )this.env.get( 344 CoadunationInitialContextFactory.PASSWORD))); 345 } else { 346 CoadunationInitialContextFactory.userLogin.set(null); 347 } 348 Name composedName = (Name )prefix.clone(); 349 composedName.addAll(name); 350 for (int index =0; index < (composedName.size() - 1); index++ ) { 351 currentName = composedName.get(index); 352 context = (Context )context.lookup(currentName); 353 } 354 currentName = composedName.get(composedName.size() - 1); 355 Object result = context.lookup(currentName); 356 if (result instanceof com.sun.corba.se.impl.corba.CORBAObjectImpl) { 357 com.sun.corba.se.impl.corba.CORBAObjectImpl obj = 358 (com.sun.corba.se.impl.corba.CORBAObjectImpl)result; 359 if (result instanceof Context ) { 360 return new CoadunationContext(env,composedName); 361 } 362 } 363 return result; 364 } catch (NamingException ex) { 365 this.invalidateContext(); 366 log.error("Failed to lookup the object [" + currentName + "] :" + 367 ex.getMessage(),ex); 368 throw ex; 369 } catch (Exception ex) { 370 this.invalidateContext(); 371 log.error("Failed to lookup the object [" + currentName + "] :" + 372 ex.getMessage(),ex); 373 throw new NamingException ( 374 "Failed to lookup the object [" + currentName + "] :" + 375 ex.getMessage()); 376 } 377 } 378 379 380 387 public Object lookup(String name) throws NamingException { 388 return lookup(new NamingParser().parse(name)); 389 } 390 391 392 400 public Object lookupLink(Name name) throws NamingException { 401 throw new NamingException ("Not implemented"); 402 } 403 404 405 413 public Object lookupLink(String name) throws NamingException { 414 throw new NamingException ("Not implemented"); 415 } 416 417 418 425 public void rebind(Name name, Object obj) throws NamingException { 426 throw new NamingException ("Not implemented"); 427 } 428 429 430 437 public void rebind(String name, Object obj) throws NamingException { 438 throw new NamingException ("Not implemented"); 439 } 440 441 442 448 public Object removeFromEnvironment(String propName) throws NamingException { 449 throw new NamingException ("Not implemented"); 450 } 451 452 453 461 public void rename(Name oldName, Name newName) throws NamingException { 462 throw new NamingException ("Not implemented"); 463 } 464 465 466 474 public void rename(String oldName, String newName) throws NamingException { 475 throw new NamingException ("Not implemented"); 476 } 477 478 479 485 public void unbind(Name name) throws NamingException { 486 throw new NamingException ("Not implemented"); 487 } 488 489 490 496 public void unbind(String name) throws NamingException { 497 throw new NamingException ("Not implemented"); 498 } 499 500 501 504 public synchronized Context getContext() throws NamingException { 505 if (primaryContext != null) { 506 return primaryContext; 507 } 508 return primaryContext = new InitialContext (env); 509 } 510 511 512 515 public synchronized void invalidateContext() { 516 primaryContext = null; 517 } 518 } 519 | Popular Tags |