List of usage examples for javax.naming Context list
public NamingEnumeration<NameClassPair> list(String name) throws NamingException;
From source file:Main.java
public static void main(String[] argv) throws Exception { String url = "iiop://localhost/"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"); env.put(Context.PROVIDER_URL, url); Context ctx = new InitialContext(env); NamingEnumeration e = ctx.list("child"); while (e.hasMore()) { NameClassPair entry = (NameClassPair) e.next(); System.out.println(entry.getName()); }/*www . ja v a2 s .com*/ }
From source file:List.java
public static void main(String[] args) throws Exception { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:/tmp/marketing"); Object item = null;/*from w w w.jav a 2 s . co m*/ Context initCtx = new InitialContext(env); NamingEnumeration nl = initCtx.list("reports"); if (nl == null) System.out.println("\nNo items in name list"); else while (nl.hasMore()) { item = nl.next(); System.out.println("item's class is " + item.getClass().getName()); System.out.println(item); System.out.println(""); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); // Set up the environment for creating the initial context Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:/jdbc"); Context context = new InitialContext(env); NamingEnumeration list = context.list("jdbc"); while (list.hasMore()) { NameClassPair nc = (NameClassPair) list.next(); System.out.println(nc);// w w w . jav a 2s.c o m } OracleDataSource ods = new OracleDataSource(); ods.setDriverType("thin"); ods.setServerName("localhost"); ods.setNetworkProtocol("tcp"); ods.setDatabaseName("databaseName"); ods.setPortNumber(1521); ods.setUser("userName"); ods.setPassword("Password"); Context ctx = new InitialContext(); ctx.bind("file:/jdbc/mydb", ods); // Get the initial context of JNDI and lookup the datasource. InitialContext ic = new InitialContext(); javax.sql.DataSource ds = (javax.sql.DataSource) ic.lookup("file:/jdbc/mydb"); // Set the optional printwriter where the trace log is to be directed. ds.setLogWriter(new PrintWriter(new FileOutputStream("c:/datasource.log"))); Connection con1 = ds.getConnection(); Connection con2 = ds.getConnection("userName", "password"); conn.close(); }
From source file:List.java
public static void main(String[] args) { // Set up the environment for creating the initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); try {/*ww w. ja v a2s .c om*/ // Create the initial context Context ctx = new InitialContext(env); // Get listing of context NamingEnumeration list = ctx.list("ou=People"); // Go through each item in list while (list.hasMore()) { NameClassPair nc = (NameClassPair) list.next(); System.out.println(nc); } // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("List failed: " + e); } }
From source file:Destroy.java
public static void main(String[] args) { // Set up the environment for creating the initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); try {/*from w ww .jav a 2s. c om*/ // Create the initial context Context ctx = new InitialContext(env); // Destroy the context ctx.destroySubcontext("ou=NewOu"); // Check that it has been destroyed by listing its parent NamingEnumeration list = ctx.list(""); // Go through each item in list while (list.hasMore()) { NameClassPair nc = (NameClassPair) list.next(); System.out.println(nc); } // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("destroy failed: " + e); } }
From source file:be.fedict.eid.dss.sp.StartupServletContextListener.java
public static void bindComponent(String jndiName, Object component) throws NamingException { LOG.debug("bind component: " + jndiName); InitialContext initialContext = new InitialContext(); String[] names = jndiName.split("/"); Context context = initialContext; for (int idx = 0; idx < names.length - 1; idx++) { String name = names[idx]; LOG.debug("name: " + name); NamingEnumeration<NameClassPair> listContent = context.list(""); boolean subContextPresent = false; while (listContent.hasMore()) { NameClassPair nameClassPair = listContent.next(); if (!name.equals(nameClassPair.getName())) { continue; }/*from w w w . j a v a 2 s .co m*/ subContextPresent = true; } if (!subContextPresent) { context = context.createSubcontext(name); } else { context = (Context) context.lookup(name); } } String name = names[names.length - 1]; context.rebind(name, component); }
From source file:com.egt.core.util.Utils.java
public static void traceContext(Context c, String name) { NameClassPair ncp;//from w ww.j a v a2 s . co m NamingEnumeration<NameClassPair> ncpenum; try { ncpenum = c.list(name); while (ncpenum.hasMore()) { ncp = ncpenum.next(); if (ncp.getClassName().endsWith("javaURLContext")) { traceContext(c, ncp.getName()); } else { Bitacora.logTrace(ncp.getName() + " = " + ncp.getClassName()); } } } catch (NamingException ex) { Bitacora.logFatal(ThrowableUtils.getString(ex)); } }
From source file:com.netspective.axiom.connection.JndiConnectionProvider.java
public Set getAvailableDataSources() { Set result = new HashSet(); try {// w ww . j a v a2 s . co m String envPath = getRootContextName(); Context env = getRootContext(); if (env != null) { for (NamingEnumeration e = env.list(""); e.hasMore();) { NameClassPair entry = (NameClassPair) e.nextElement(); result.add(envPath != null ? (envPath + "/" + entry.getName()) : entry.getName()); } } } catch (NamingException e) { log.debug(JndiConnectionProvider.class.getName() + ".getAvailableDataSources()", e); } return result; }
From source file:com.netspective.axiom.connection.JndiConnectionProvider.java
public ConnectionProviderEntries getDataSourceEntries(ValueContext vc) { ConnectionProviderEntries entries = new BasicConnectionProviderEntries(); try {//from w w w . ja va 2 s . co m String envPath = getRootContextName(); Context env = getRootContext(); if (env != null) { for (NamingEnumeration e = env.list(""); e.hasMore();) { NameClassPair entry = (NameClassPair) e.nextElement(); String dataSourceId = envPath != null ? (envPath + "/" + entry.getName()) : entry.getName(); try { DataSource source = (DataSource) env.lookup(entry.getName()); entries.add(getDataSourceEntry(dataSourceId, source)); } catch (NamingException ex) { log.debug(JndiConnectionProvider.class.getName() + ".getDataSourceEntries()", ex); } catch (SQLException ex) { log.debug(JndiConnectionProvider.class.getName() + ".getDataSourceEntries()", ex); } } } } catch (NamingException e) { log.error("Errorw in getDataSourceEntries()", e); throw new NestableRuntimeException(e); } return entries; }
From source file:com.dattack.naming.AbstractContext.java
@Override public void destroySubcontext(final Name name) throws NamingException { if (name.size() > 1) { if (subContexts.containsKey(name.getPrefix(1))) { final Context subContext = subContexts.get(name.getPrefix(1)); subContext.destroySubcontext(name.getSuffix(1)); return; }// w w w .j av a 2s .c o m throw new NameNotFoundException(); } if (objectTable.containsKey(name) || !subContexts.containsKey(name)) { throw new NameNotFoundException(String.format("Context not found: %s", name)); } final Context subContext = subContexts.get(name); final NamingEnumeration<NameClassPair> names = subContext.list(""); if (names.hasMore()) { throw new ContextNotEmptyException(); } subContexts.get(name).close(); subContexts.remove(name); }