List of usage examples for javax.naming Context unbind
public void unbind(String name) throws NamingException;
From source file:Delete.java
public static void main(String[] args) throws Exception { String initalContextString = "/tmp/marketing/reports"; if (args.length < 1) { System.out.println("Usage: java Delete filename"); System.exit(-1);/* w w w . j av a2s . com*/ } System.out.println("This program assumes the context is " + initalContextString); Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:" + initalContextString); Context initCtx = new InitialContext(env); System.out.println("Attempting to unbind " + args[0]); initCtx.unbind(args[0]); System.out.println("Done."); }
From source file:Unbind.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 v a 2 s . co m*/ // Create the initial context Context ctx = new InitialContext(env); // Remove the binding ctx.unbind("cn=Favorite Fruit"); // Check that it is gone Object obj = null; try { obj = ctx.lookup("cn=Favorite Fruit"); } catch (NameNotFoundException ne) { System.out.println("unbind successful"); return; } System.out.println("unbind failed; object still there: " + obj); // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("Operation 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); // Add a binding. ctx.bind("Name", null); // Replace a binding. ctx.rebind("Name", null); // Remove a binding. ctx.unbind("Name"); // Rename a binding. ctx.rename("Name", "NewSample"); }
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); }/*from ww w .ja va 2s. co m*/ c.unbind(name); } }
From source file:Util.java
/** * Unbinds a name from ctx, and removes parents if they are empty * /*w w w .j a v a 2 s. 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:Util.java
/** * Remove the link ref/* ww w . ja v a2s .c o m*/ * * @param ctx * the context * @param name * the name of the link binding * @throws NamingException * for any error */ public static void removeLinkRef(Context ctx, String name) throws NamingException { System.out.println("Unbinding link " + name); ctx.unbind(name); }
From source file:com.clican.pluto.common.util.JndiUtils.java
/** * Unbind the rsource manager instance from the JNDI directory. * <p>/* w ww . j av a2 s. c o m*/ * After this method is called, it is no longer possible to obtain the * resource manager instance from the JNDI directory. * <p> * Note that this method will not remove the JNDI contexts corresponding to * the individual path segments of the full resource manager JNDI path. * * @param jndiName * The full JNDI path at which the resource manager instance was * previously bound. * @return <b>true</b> if the resource manager was successfully unbound * from JNDI; otherwise <b>false</b>. * * @see #bind(String, Object) */ public static boolean unbind(String jndiName) { if (log.isDebugEnabled()) { log.debug("Unbinding object at path [" + jndiName + "] from the JNDI repository."); } Context ctx = null; try { Hashtable<String, String> ht = new Hashtable<String, String>(); // If a special JNDI initial context factory was specified in the // constructor, then use it. if (jndiInitialContextFactory != null) { ht.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialContextFactory); } ctx = new InitialContext(ht); Object obj = lookupObject(jndiName); if (obj instanceof Serializable || jndiInitialContextFactory != null) { ctx.unbind(jndiName); } else { NonSerializableFactory.unbind(jndiName); } } catch (NamingException ex) { log.error("An error occured while unbinding [" + jndiName + "] from JNDI:", ex); return false; } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException ne) { log.error("Close context error:", ne); } } } return true; }
From source file:blueprint.sdk.experimental.florist.db.ConnectionListener.java
public void contextDestroyed(final ServletContextEvent arg0) { try {//from w ww .java 2s.c o m Context initContext = new InitialContext(); for (String s : boundDsrs.keySet()) { try { DataSource dsr = boundDsrs.get(s); initContext.unbind(s); // Close all BasicDataSources created by this class. // No need to close JNDI DataSources. It's not this class's // responsibility. if (dsr instanceof BasicDataSource) { ((BasicDataSource) dsr).close(); } } catch (SQLException e) { LOGGER.trace(e); } } boundDsrs.clear(); } catch (NamingException e) { LOGGER.trace(e); } }
From source file:com.paxxis.cornerstone.messaging.service.shell.ServiceShell.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void doUnbind(String[] vals) throws NamingException { String url = "rmi://localhost:" + vals[1]; String serviceName = vals[0]; System.out.println("Unbinding " + url + "/" + serviceName); Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); env.put(Context.PROVIDER_URL, url); Context ictx = new InitialContext(env); try {// ww w . j a v a 2 s . co m ictx.unbind(serviceName); System.out.println("Done"); } catch (Exception ex) { System.err.println(ex.getMessage() + ex.getCause().getMessage()); } }
From source file:io.apiman.gateway.test.junit.servlet.ServletGatewayTestServer.java
/** * Called after stopping the gateway.//from ww w.j av a2 s. co m */ private void postStop() throws Exception { if (node != null) { client.execute(new DeleteIndex.Builder("apiman_gateway").build()); SimpleJestClientFactory.clearClientCache(); } if (ds != null) { try (Connection connection = ds.getConnection()) { connection.prepareStatement("DROP ALL OBJECTS").execute(); } ds.close(); ds = null; InitialContext ctx = TestUtil.initialContext(); Context pctx = (Context) ctx.lookup("java:/comp/env/jdbc"); pctx.unbind("ApiGatewayDS"); } if (cacheContainer != null) { cacheContainer.stop(); cacheContainer = null; InitialContext ctx = TestUtil.initialContext(); Context pctx = (Context) ctx.lookup("java:jboss/infinispan"); pctx.unbind("apiman"); } }