List of usage examples for javax.naming Binding getObject
public Object getObject()
From source file:ListBindings.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 w w. j a va 2 s . c o m // Create the initial context Context ctx = new InitialContext(env); // Get listing of context NamingEnumeration bindings = ctx.listBindings("ou=People"); // Go through each item in list while (bindings.hasMore()) { Binding bd = (Binding) bindings.next(); System.out.println(bd.getName() + ": " + bd.getObject()); } // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("List Bindings failed: " + e); } }
From source file:JNDIUtil.java
public static void tearDownRecursively(Context c) throws Exception { for (NamingEnumeration ne = c.listBindings(""); ne.hasMore();) { Binding b = (Binding) ne.next(); String name = b.getName(); Object object = b.getObject(); if (object instanceof Context) { tearDownRecursively((Context) object); }// ww w . j av a 2s . c o m c.unbind(name); } }
From source file:de.micromata.genome.util.runtime.jndi.JndiDumper.java
public static void dumpJndiBinding(InitialContext initialContext, String parentKey, Binding binding, StringBuilder sb, String indent) throws NamingException { try {//from ww w . ja v a 2 s. c om Object obj = binding.getObject(); ClassLoader bindClassLoader = obj.getClass().getClassLoader(); sb.append(indent).append(parentKey + "/" + binding.getName()).append("(") .append(System.identityHashCode(binding)).append(", cl: ").append(bindClassLoader).append("): ") .append(binding.toString()); if (obj instanceof Context) { sb.append("\n"); Context ctx = (Context) obj; indent += " "; NamingEnumeration<Binding> bindings = ctx.listBindings(""); while (bindings.hasMore()) { Binding cbinding = bindings.next(); dumpJndiBinding(initialContext, parentKey + "/" + binding.getName(), cbinding, sb, indent); } } else if (obj instanceof Reference) { Reference ref = (Reference) obj; // binding.get // ref. sb.append("\n"); } else if (obj instanceof Session) { Session sess = (Session) obj; sb.append("\n"); } else if (obj instanceof DataSource) { DataSource ds = (DataSource) obj; if (ds instanceof BasicDataSource) { BasicDataSource dbds = (BasicDataSource) ds; sb.append(" '" + dbds.getUrl() + "'"); } sb.append("\n"); } else if (obj != null) { Class<? extends Object> clazz = obj.getClass(); sb.append(" unkown type: " + clazz); sb.append("\n"); } } catch (NamingException ex) { sb.append("Error access binding: " + binding.getName() + ": " + ex.getMessage()); } }
From source file:com.ironiacorp.persistence.datasource.HibernateConfigurationUtil.java
/** * Retrieve the data sources registered at JNDI in the given context. * /*from www. j av a 2 s .co m*/ * @param namingContext * Start point context. * * @return A collection of the data sources found within the context. */ private static Collection<String> getAvailableDataSources(Context namingContext) { Collection<String> datasources = new ArrayList<String>(); Class<?> type = null; // Acquire global JNDI resources if available try { type = Class.forName("xyz"); } catch (ClassNotFoundException e) { } try { NamingEnumeration<Binding> items = namingContext.listBindings(""); while (items.hasMore()) { Binding item = (Binding) items.next(); if (item.getObject() instanceof Context) { datasources.addAll(getAvailableDataSources((Context) item.getObject())); } else { if (type.isInstance(item.getObject())) { datasources.add(item.getName()); } } } } catch (Throwable t) { } return datasources; }
From source file:EnvEntry.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); try {//from ww w . j a v a2s . c o m Context initCtx = new InitialContext(); NamingEnumeration e = initCtx.listBindings("java:comp/env"); while (e.hasMore()) { Binding binding = (Binding) e.next(); out.println("Name: " + binding.getName()); out.println("Type: " + binding.getClassName()); out.println("Value: " + binding.getObject()); out.println(); } } catch (NamingException e) { e.printStackTrace(out); } }
From source file:binky.reportrunner.ui.actions.datasource.SaveDataSource.java
private List<String> listJNDINames(Context ctx, String ident) throws NamingException { List<String> names = new LinkedList<String>(); NamingEnumeration<Binding> list = ctx.listBindings(""); while (list.hasMore()) { Binding item = (Binding) list.next(); String name = item.getName(); Object o = item.getObject(); if (o instanceof javax.naming.Context) { names.addAll(listJNDINames((Context) o, name)); } else {/*from w ww . j a v a 2s .c om*/ names.add(ident + "/" + name); } } return names; }
From source file:jndi.view.JndiView.java
/** * @param path//from w w w.j ava 2 s .c o m * the path to browse * @return {@link List} of {@link JndiEntry}s * @throws NamingException * on exception */ private List<JndiEntry> browse(final String path) throws NamingException { final JndiCallback<List<JndiEntry>> contextCallback = new JndiCallback<List<JndiEntry>>() { @Override public List<JndiEntry> doInContext(final Context context) throws NamingException { if (JAVA_GLOBAL.equals(path)) { // Do a little trick to handle "java:global" final NamingEnumeration<Binding> root = context.listBindings(""); Context javaGlobalContext = null; while (root.hasMore()) { final Binding binding = root.next(); if (JAVA_GLOBAL.equals(binding.getName())) { final Object obj = binding.getObject(); if (obj instanceof Context) { javaGlobalContext = (Context) obj; } break; } } if (javaGlobalContext != null) { return examineBindings(javaGlobalContext, path, javaGlobalContext.listBindings("")); } logger.warning("Unable to browse \"" + JAVA_GLOBAL + "\" namespace!"); return emptyList(); } return examineBindings(context, path, context.listBindings(path)); } }; return jndiTemplate.execute(contextCallback); }
From source file:binky.reportrunner.ui.actions.datasource.SetupEditJNDIDataSource.java
private List<String> listJNDINames(Context ctx, String ident) throws NamingException { List<String> names = new LinkedList<String>(); String indent = ""; NamingEnumeration<Binding> list = ctx.listBindings(""); while (list.hasMore()) { Binding item = (Binding) list.next(); String className = item.getClassName(); String name = item.getName(); logger.debug(indent + className + " " + name); Object o = item.getObject(); if (o instanceof javax.naming.Context) { names.addAll(listJNDINames((Context) o, name)); } else {/*from w w w . j av a 2 s .co m*/ names.add(ident + "/" + name); } } return names; }
From source file:jndi.view.JndiView.java
/** * @param ctx/*from w w w . ja v a2s .c o m*/ * the Context we're examining * @param path * the path to examine * @param bindings * the {@link NamingEnumeration} of {@link Binding}s * @return List of {@link JndiEntry} * @throws NamingException * on exception */ private List<JndiEntry> examineBindings(final Context ctx, final String path, final NamingEnumeration<Binding> bindings) throws NamingException { if (null == bindings) { throw new NullPointerException("bindings is null!"); } final List<JndiEntry> entries = new ArrayList<JndiEntry>(); while (bindings.hasMore()) { final Binding binding = bindings.next(); final String name = binding.getName(); final String className = binding.getClassName(); logger.finest("name: " + name + " [" + className + "]"); final JndiEntry entry = new JndiEntry(name, className); final Object obj = binding.getObject(); if (obj instanceof Context) { entry.setContext(true); String link = name; if (!path.isEmpty()) { link = path + "/" + name; } entry.setLink(link); } else if (obj instanceof Reference) { final Reference ref = (Reference) obj; entry.setTargetClassName(ref.getClassName()); } else if ("org.glassfish.javaee.services.ResourceProxy".equals(className)) { // SUPPRESS CHECKSTYLE AvoidInlineConditionals final Object lookup = ctx.lookup(path.isEmpty() ? name : path + "/" + name); if (lookup != null) { final String lookedUpClassName = lookup.getClass().getName(); logger.finest("lookup(\"" + name + "\") returned " + lookedUpClassName); entry.setTargetClassName(lookedUpClassName); } } else if ("com.sun.ejb.containers.JavaGlobalJndiNamingObjectProxy".equals(className)) { inspectJndiNamingObjectProxy(entry, obj); } entries.add(entry); } return entries; }
From source file:com.jsmartframework.web.manager.BeanHandler.java
private void lookupInContext(Context context, String prefix) { try {//from w w w.j a v a2 s. c o m prefix += "/"; NamingEnumeration<Binding> bindList = context.listBindings(""); while (bindList.hasMore()) { Binding bind = bindList.next(); if (bind != null) { if (bind.getObject() instanceof Context) { lookupInContext((Context) bind.getObject(), prefix + bind.getName()); } String[] binds = bind.getName().split("!"); if (binds.length > 1) { try { jndiMapping.put(Class.forName(binds[1]), prefix + binds[0]); } catch (Throwable ex) { LOGGER.log(Level.WARNING, "Class could not be found for EJB mapping: " + ex.getMessage()); } } } } } catch (Throwable ex) { LOGGER.log(Level.WARNING, "Bindings could not be found for EJB context: " + ex.getMessage()); } }