List of usage examples for java.util Hashtable put
public synchronized V put(K key, V value)
From source file:Main.java
public static void main(String[] args) { Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put("1", "One"); ht.put("2", "Two"); ht.put("3", "Three"); Object obj = ht.remove("2"); System.out.println(obj + " was Removed "); Enumeration e = ht.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); }/*from www . j av a2 s.c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "yourURL"); DirContext ctx = new InitialDirContext(env); DirContext tedClasses = ctx.getSchemaClassDefinition("cn=YourName, ou=People"); NamingEnumeration e = tedClasses.search("", null); while (e.hasMore()) { DirContext entry = (DirContext) e.next(); System.out.println(entry); }//from w w w .jav a 2 s . co m }
From source file:Main.java
public static void main(String args[]) { Hashtable<String, String> h = new Hashtable<String, String>(); h.put("a", "b"); h.put("c", "d"); h.put("e", "f"); for (String str : h.keySet()) { System.out.println(str);//from w w w . j a va 2 s.c o m } List<String> v = new ArrayList<String>(h.keySet()); Collections.sort(v); for (String str : v) { System.out.println(str + " " + (String) h.get(str)); } }
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:Main.java
public static void main(String[] argv) throws Exception { Attributes attrs = new BasicAttributes(true); Attribute objclass = new BasicAttribute("objectclass"); objclass.add("top"); objclass.add("extensible"); attrs.put(objclass);//from ww w. j a v a 2 s. co m Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "yourURL"); DirContext ctx = new InitialDirContext(env); Context entry = ctx.createSubcontext("cn=Sample", attrs); }
From source file:Main.java
public static void main(String args[]) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX); env.put(Context.PROVIDER_URL, MY_HOST); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, MGR_DN); env.put(Context.SECURITY_CREDENTIALS, MGR_PW); DirContext ctx = new InitialDirContext(env); ctx.destroySubcontext(MY_ENTRY);/* w ww. j a v a 2s.c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { ModificationItem[] mods = new ModificationItem[3]; mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("mail", "g@w.com")); mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("number", "5555")); mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("jpeg")); String url = "ldap://localhost/o=JNDITutorial"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); DirContext ctx = new InitialDirContext(env); ctx.modifyAttributes("cn=Name, ou=People", mods); }
From source file:Main.java
public static void main(String[] s) { Hashtable<String, String> table = new Hashtable<String, String>(); table.put("1", "Sunday"); table.put("2", "Monday"); table.put("3", "Tuesday"); table.put("4", "Wednesday"); table.put("5", "Thursday"); table.put("6", "Friday"); table.put("7", "Saturday"); System.out.println("Initial collection: " + table); Map m = Collections.unmodifiableMap(table); // m.put("key3", "value3"); }
From source file:AttributeExample.java
public static void main(String[] argc) throws Exception { Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://MyHost/o=JNDIExample"); DirContext dctx = new InitialDirContext(env); Attributes attrs = new BasicAttributes(true); attrs.put(new BasicAttribute("email")); attrs.put(new BasicAttribute("website", "www.pri.com")); NamingEnumeration result = dctx.search("ou=People", attrs); while (result.hasMore()) { SearchResult sr = (SearchResult) result.next(); System.out.println("Result = " + sr.getName()); Attributes srchAttrs = sr.getAttributes(); NamingEnumeration attributes = srchAttrs.getAll(); while (attributes.hasMore()) { Attribute attr = (Attribute) attributes.next(); System.out.println("Attribute: " + attr.getID()); NamingEnumeration values = attr.getAll(); while (values.hasMore()) { Object value = values.next(); System.out.println("Value = " + value); }// w w w. j ava 2s .co m } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "yourURL"); DirContext ctx = new InitialDirContext(env); // Get an attribute of that type Attributes attrs = ctx.getAttributes("cn=YourName, ou=People", new String[] { "cn" }); Attribute cnAttr = attrs.get("cn"); // Get its attribute definition DirContext cnSchema = cnAttr.getAttributeDefinition(); // Get cnSchema's attributes Attributes cnAttrs = cnSchema.getAttributes(""); }