List of usage examples for javax.naming InitialContext getNameParser
public NameParser getNameParser(Name name) throws NamingException
From source file:jdao.JDAO.java
public static Context retrieveContext(String jndi_path) { InitialContext jndiContext = null; Context env = null;//ww w. ja va 2s . co m try { log("INFO: resolving " + jndi_path); env = jndiContext = new InitialContext(); env = (Context) jndiContext.lookup(jndi_path); } catch (Exception xe) { try { Name jname = jndiContext.getNameParser(jndi_path).parse(jndi_path); Enumeration<String> en = jname.getAll(); while (en.hasMoreElements()) { String name = en.nextElement(); Context tmp = null; try { tmp = (Context) env.lookup(name); env = (Context) env.lookup(name); } catch (NameNotFoundException nnf) { log("INFO: creating " + name); env = env.createSubcontext(name); } } } catch (Exception xe2) { log("ERROR: resolving " + jndi_path, xe2); } } return env; }
From source file:org.nuxeo.runtime.binding.ServiceBindings.java
public static void createAlias(InitialContext ctx, String existingName, String aliasName) throws NamingException { LinkRef link = new LinkRef(existingName); Context aliasCtx = ctx;//w w w. j av a 2s . c om Name name = ctx.getNameParser("").parse(aliasName); int len = name.size() - 1; String atom = name.get(len); for (int i = 0; i < len; i++) { String comp = name.get(i); try { aliasCtx = (Context) aliasCtx.lookup(comp); } catch (NameNotFoundException e) { aliasCtx = aliasCtx.createSubcontext(comp); } } aliasCtx.rebind(atom, link); if (log.isDebugEnabled()) { log.debug("Created JNDI link [" + aliasName + "] pointing to [" + existingName + "]"); } }