List of usage examples for javax.naming Binding getName
public String getName()
From source file:org.geoserver.security.ldap.LDAPTestUtils.java
/** * Clear the directory sub-tree starting with the node represented by the * supplied distinguished name./*from ww w . j av a 2 s .c o m*/ * * @param ctx The DirContext to use for cleaning the tree. * @param name the distinguished name of the root node. * @throws NamingException if anything goes wrong removing the sub-tree. */ public static void clearSubContexts(DirContext ctx, Name name) throws NamingException { NamingEnumeration enumeration = null; try { enumeration = ctx.listBindings(name); while (enumeration.hasMore()) { Binding element = (Binding) enumeration.next(); DistinguishedName childName = new DistinguishedName(element.getName()); childName.prepend((DistinguishedName) name); try { ctx.destroySubcontext(childName); } catch (ContextNotEmptyException e) { clearSubContexts(ctx, childName); ctx.destroySubcontext(childName); } } } catch (NamingException e) { e.printStackTrace(); } finally { try { enumeration.close(); } catch (Exception e) { // Never mind this } } }
From source file:org.nuxeo.ecm.core.storage.sql.management.RepositoryStatus.java
protected List<RepositoryManagement> getRepositories() throws NamingException { List<RepositoryManagement> list = new LinkedList<RepositoryManagement>(); InitialContext context;/*from ww w .j a v a 2s . c o m*/ ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(RepositoryStatus.class.getClassLoader()); try { context = new InitialContext(); } finally { Thread.currentThread().setContextClassLoader(cl); } // we search both JBoss-like and Glassfish-like prefixes // @see NXCore#getRepository for (String prefix : new String[] { "java:NXRepository", "NXRepository" }) { NamingEnumeration<Binding> bindings; try { bindings = context.listBindings(prefix); } catch (NamingException e) { continue; } NamingEnumeration<Binding> e = null; try { for (e = bindings; e.hasMore();) { Binding binding = e.nextElement(); String name = binding.getName(); if (binding.isRelative()) { name = prefix + '/' + name; } Object object = context.lookup(name); if (!(object instanceof RepositoryManagement)) { continue; } list.add((RepositoryManagement) object); } } finally { if (e != null) { e.close(); } } } if (list.size() == 0) { List<Repository> repos = RepositoryResolver.getRepositories(); for (Repository repo : repos) { list.add(repo); } } return list; }
From source file:org.nuxeo.ecm.core.storage.sql.reload.RepositoryReloader.java
public static List<Repository> getRepositories() throws NamingException { List<Repository> list = new LinkedList<Repository>(); InitialContext context = new InitialContext(); // we search both JBoss-like and Glassfish-like prefixes // @see NXCore#getRepository for (String prefix : new String[] { "java:NXRepository", "NXRepository" }) { NamingEnumeration<Binding> bindings; try {//ww w . j a v a 2 s. co m bindings = context.listBindings(prefix); } catch (NamingException e) { continue; } NamingEnumeration<Binding> e = null; try { for (e = bindings; e.hasMore();) { Binding binding = e.nextElement(); String name = binding.getName(); if (binding.isRelative()) { name = prefix + '/' + name; } Object object = context.lookup(name); if (!(object instanceof Repository)) { continue; } list.add((Repository) object); } } finally { if (e != null) { e.close(); } } } return list; }
From source file:org.springframework.ejb.support.JndiEnvironmentBeanDefinitionReader.java
/** * Creates new JNDIBeanFactory/*from w w w . ja va2 s.c om*/ * @param root likely to be "java:comp/env" */ public JndiEnvironmentBeanDefinitionReader(BeanDefinitionRegistry beanFactory, String root) throws BeansException { // We'll take everything from the NamingContext and dump it in a // Properties object, so that the superclass can efficiently manipulate it // after we've closed the context. HashMap m = new HashMap(); Context initCtx = null; try { initCtx = new InitialContext(); // Parameterize NamingEnumeration bindings = initCtx.listBindings(root); // Orion 1.5.2 doesn't seem to regard anything under a / // as a true subcontext, so we need to search all bindings // Not all that fast, but it doesn't matter while (bindings.hasMore()) { Binding binding = (Binding) bindings.next(); logger.debug("Name: " + binding.getName()); logger.debug("Type: " + binding.getClassName()); logger.debug("Value: " + binding.getObject()); m.put(binding.getName(), binding.getObject()); } bindings.close(); PropertiesBeanDefinitionReader propReader = new PropertiesBeanDefinitionReader(beanFactory); propReader.registerBeanDefinitions(m, BEANS_PREFIX); } catch (NamingException ex) { logger.debug("----- NO PROPERTIES FOUND " + ex); } finally { try { if (initCtx != null) { initCtx.close(); } } catch (NamingException ex) { // IGNORE OR THROW RTE? } } }
From source file:org.springframework.ldap.core.LdapTemplate.java
/** * Delete all subcontexts including the current one recursively. * //from w w w.j av a 2 s . c om * @param ctx The context to use for deleting. * @param name The starting point to delete recursively. * @throws NamingException if any error occurs */ protected void deleteRecursively(DirContext ctx, DistinguishedName name) { NamingEnumeration enumeration = null; try { enumeration = ctx.listBindings(name); while (enumeration.hasMore()) { Binding binding = (Binding) enumeration.next(); DistinguishedName childName = new DistinguishedName(binding.getName()); childName.prepend((DistinguishedName) name); deleteRecursively(ctx, childName); } ctx.unbind(name); if (log.isDebugEnabled()) { log.debug("Entry " + name + " deleted"); } } catch (javax.naming.NamingException e) { throw LdapUtils.convertLdapException(e); } finally { try { enumeration.close(); } catch (Exception e) { // Never mind this } } }
From source file:org.springframework.ldap.test.unboundid.LdapTestUtils.java
/** * Clear the directory sub-tree starting with the node represented by the * supplied distinguished name./*from w w w . j a v a 2 s .c om*/ * * @param ctx The DirContext to use for cleaning the tree. * @param name the distinguished name of the root node. * @throws NamingException if anything goes wrong removing the sub-tree. */ public static void clearSubContexts(DirContext ctx, Name name) throws NamingException { NamingEnumeration<?> enumeration = null; try { enumeration = ctx.listBindings(name); while (enumeration.hasMore()) { Binding element = (Binding) enumeration.next(); Name childName = LdapUtils.newLdapName(element.getName()); childName = LdapUtils.prepend(childName, name); try { ctx.unbind(childName); } catch (ContextNotEmptyException e) { clearSubContexts(ctx, childName); ctx.unbind(childName); } } } catch (NamingException e) { LOGGER.debug("Error cleaning sub-contexts", e); } finally { try { enumeration.close(); } catch (Exception e) { // Never mind this } } }