List of usage examples for java.util Hashtable Hashtable
public Hashtable()
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 w w .j a va2 s .c o m*/ }
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 w w w. j a v a2s . c o 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[] argv) throws Exception { Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute("sn", "YourName")); matchAttrs.put(new BasicAttribute("mail")); 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); NamingEnumeration e = ctx.search("ou=People", matchAttrs); if (e.hasMore()) { SearchResult entry = (SearchResult) e.next(); // Abandon rest of results e.close();/*from w ww . ja v a2 s . c om*/ } }
From source file:KeymapExample.java
public static void main(String[] args) { JTextArea area = new JTextArea(6, 32); Keymap parent = area.getKeymap(); Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent); KeyStroke u = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK); Action actionU = new UpWord(); newmap.addActionForKeyStroke(u, actionU); Action actionList[] = area.getActions(); Hashtable lookup = new Hashtable(); for (int j = 0; j < actionList.length; j += 1) lookup.put(actionList[j].getValue(Action.NAME), actionList[j]); KeyStroke L = KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK); Action actionL = (Action) lookup.get(DefaultEditorKit.selectLineAction); newmap.addActionForKeyStroke(L, actionL); KeyStroke W = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK); Action actionW = (Action) lookup.get(DefaultEditorKit.selectWordAction); newmap.addActionForKeyStroke(W, actionW); area.setKeymap(newmap);/*w ww.j av a 2 s . com*/ JFrame f = new JFrame("KeymapExample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); area.setText("www.\n java2s \n .com."); f.pack(); f.setVisible(true); }
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);/* w w w. ja v a 2 s . c o m*/ Object obj = "yourObject"; 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); ctx.bind("cn=Sample", obj, 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); ModificationItem[] mods = new ModificationItem[2]; Attribute mod0 = new BasicAttribute("number", "555-555-5555"); Attribute mod1 = new BasicAttribute("1", "AAA"); mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0); mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, mod1); ctx.modifyAttributes("uid=mewilcox, ou=People, o=airius.com", mods); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] attrIDs = { "sn", "number", "value", "mail" }; Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute("sn", "YourName")); matchAttrs.put(new BasicAttribute("mail")); Object obj = "yourObject"; 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); NamingEnumeration e = ctx.search("ou=People", matchAttrs, attrIDs); while (e.hasMore()) { SearchResult entry = (SearchResult) e.next(); System.out.println(entry.getName()); }// www . ja v a2s . com }
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:JndiDataSource.java
public static void main(String args[]) throws Exception { String sp = "com.sun.jndi.fscontext.RefFSContextFactory"; String file = "file:/e:/JNDI"; String dataSourceName = "jdbc/myDatabase"; Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, sp); env.put(Context.PROVIDER_URL, file); ctx = new InitialContext(env); bindDataSource(ctx, dataSourceName); DataSource ds = null;//from w ww. j a va 2s .com ds = (DataSource) ctx.lookup(dataSourceName); Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT Name FROM Employees"); while (rs.next()) System.out.println(rs.getString("name")); ctx.close(); rs.close(); stmt.close(); conn.close(); ctx.close(); conn.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX); env.put(Context.PROVIDER_URL, MY_HOST); DirContext ctx = new InitialDirContext(env); SearchControls constraints = new SearchControls(); constraints.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration results = ctx.search(MY_SEARCHBASE, MY_FILTER, constraints); while (results != null && results.hasMore()) { SearchResult sr = (SearchResult) results.next(); String dn = sr.getName() + ", " + MY_SEARCHBASE; System.out.println("Distinguished Name is " + dn); Attributes ar = ctx.getAttributes(dn, MY_ATTRS); if (ar == null) { System.out.println("Entry " + dn + " has none of the specified attributes\n"); return; }//from w ww . j a va 2s. c om for (int i = 0; i < MY_ATTRS.length; i++) { Attribute attr = ar.get(MY_ATTRS[i]); if (attr == null) { continue; } System.out.println(MY_ATTRS[i] + ":"); for (Enumeration vals = attr.getAll(); vals.hasMoreElements();) { System.out.println("\t" + vals.nextElement()); } } } }