List of usage examples for javax.naming Context destroySubcontext
public void destroySubcontext(String name) throws NamingException;
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.ja v a2s .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: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); // Create a subcontext. Context childCtx = ctx.createSubcontext("child"); // Destroy the subcontext. ctx.destroySubcontext("child"); }
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); // Create a subcontext. Context childCtx = ctx.createSubcontext("child"); // Destroy the subcontext. ctx.destroySubcontext("child"); Context obj = (Context) childCtx.lookup("grandChild"); String fullname = obj.getNameInNamespace(); }
From source file:com.dattack.naming.loader.NamingLoader.java
private static void execBind(final Context context, final String key, final Object value) throws NamingException { Object obj = context.lookup(key); if (obj instanceof Context) { LOGGER.debug("Destroying context with name '{}'", key); context.destroySubcontext(key); obj = null;// w w w .j a v a 2 s . c o m } if (obj == null) { LOGGER.debug("Executing bind method for '{}'", key); context.bind(key, value); } else { LOGGER.debug("Executing rebind method for '{}'", key); context.rebind(key, value); } }
From source file:Util.java
/** * Unbinds a name from ctx, and removes parents if they are empty * //w w w . ja va 2s .c o m * @param ctx * the parent JNDI Context under which the name will be unbound * @param name * The name to unbind * @throws NamingException * for any error */ public static void unbind(Context ctx, Name name) throws NamingException { ctx.unbind(name); // unbind the end node in the name int sz = name.size(); // walk the tree backwards, stopping at the domain while (--sz > 0) { Name pname = name.getPrefix(sz); try { ctx.destroySubcontext(pname); } catch (NamingException e) { System.out.println("Unable to remove context " + pname + e); break; } } }
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 .ja v a 2 s. 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); }
From source file:org.nuxeo.runtime.test.runner.JndiHelper.java
/** * Unbinds a name from ctx, and removes parents if they are empty * * @param ctx the parent JNDI Context under which the name will be unbound * @param name The name to unbind/* w w w. j av a2s .c o m*/ * @throws NamingException for any error */ public static void unbind(Context ctx, Name name) throws NamingException { ctx.unbind(name); // unbind the end node in the name int sz = name.size(); // walk the tree backwards, stopping at the domain while (--sz > 0) { Name pname = name.getPrefix(sz); try { ctx.destroySubcontext(pname); } catch (NamingException e) { log.error(e, e); break; } } }