List of usage examples for javax.naming Context rename
public void rename(String oldName, String newName) throws NamingException;
From source file:Rename.java
public static void main(String[] args) throws Exception { String initialContextString = "/"; if (args.length < 2) { System.out.println("Useage: java Rename filename1 filename2"); System.exit(-1);// w w w . j av a2 s.c o m } Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:" + initialContextString); Context initCtx = new InitialContext(env); System.out.println("Renaming " + args[0] + " to " + args[1]); initCtx.rename(args[0], args[1]); }
From source file:Rename.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/ou=People,o=JNDITutorial"); try {/*from ww w . ja v a 2s .c o m*/ // Create the initial context Context ctx = new InitialContext(env); // Rename to Scott S ctx.rename("cn=Scott Seligman", "cn=Scott S"); // Check that it is there using new name Object obj = ctx.lookup("cn=Scott S"); System.out.println(obj); // Rename back to Scott Seligman ctx.rename("cn=Scott S", "cn=Scott Seligman"); // Check that it is there with original name obj = ctx.lookup("cn=Scott Seligman"); System.out.println(obj); // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("Rename 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"); }