List of usage examples for java.util Hashtable put
public synchronized V put(K key, V value)
From source file:SearchTimeLimit.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 ww w . ja va2 s.c om*/ // Create initial context DirContext ctx = new InitialDirContext(env); // Set search controls to limit count to 'timeout' SearchControls ctls = new SearchControls(); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); ctls.setTimeLimit(timeout); // // Search for objects with those matching attributes NamingEnumeration answer = ctx.search("", "(objectclass=*)", ctls); // Print the answer printSearchEnumeration(answer); // Close the context when we're done ctx.close(); } catch (TimeLimitExceededException e) { System.out.println("time limit exceeded"); } catch (Exception e) { System.err.println(e); } }
From source file:Main.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 UppercaseAction(); 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); area.setKeymap(newmap);// www. j a v a 2 s.co m JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(area), BorderLayout.CENTER); area.setText("this is a test"); f.setSize(300, 300); f.setVisible(true); }
From source file:SampleSliders.java
public static void main(String args[]) { String title = (args.length == 0 ? "Sample Slider" : args[0]); JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider js1 = new JSlider(); js1.putClientProperty("JSlider.isFilled", Boolean.TRUE); JSlider js2 = new JSlider(); js2.setMajorTickSpacing(25);// www.j ava 2s .c o m js2.setPaintTicks(true); js2.setSnapToTicks(true); JSlider js3 = new JSlider(JSlider.VERTICAL); js3.setPaintTrack(false); js3.setMinorTickSpacing(5); js3.setMajorTickSpacing(10); js3.setPaintTicks(true); js3.setPaintLabels(true); js3.setSnapToTicks(true); JSlider js4 = new JSlider(JSlider.VERTICAL); Hashtable table = new Hashtable(); table.put(new Integer(0), new JLabel(new DiamondIcon(Color.red))); table.put(new Integer(10), new JLabel("Ten")); table.put(new Integer(25), new JLabel("Twenty-Five")); table.put(new Integer(34), new JLabel("Thirty-Four")); table.put(new Integer(52), new JLabel("Fifty-Two")); table.put(new Integer(70), new JLabel("Seventy")); table.put(new Integer(82), new JLabel("Eighty-Two")); table.put(new Integer(100), new JLabel(new DiamondIcon(Color.black))); js4.setLabelTable(table); js4.setPaintLabels(true); js4.setSnapToTicks(true); Container c = f.getContentPane(); c.add(js1, BorderLayout.NORTH); c.add(js2, BorderLayout.SOUTH); c.add(js3, BorderLayout.WEST); c.add(js4, BorderLayout.EAST); f.setSize(300, 200); f.setVisible(true); }
From source file:RegUnsol.java
public static void main(String[] args) { // Set up environment for creating 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 . j av a 2s. c o m*/ // Get event context for registering listener EventContext ctx = (EventContext) (new InitialContext(env).lookup("ou=People")); // Create listener NamingListener listener = new UnsolListener(); // Register listener with context (all targets equivalent) ctx.addNamingListener("", EventContext.ONELEVEL_SCOPE, listener); // Wait 1 minutes for listener to receive events try { Thread.sleep(60000); } catch (InterruptedException e) { System.out.println("sleep interrupted"); } // Not strictly necessary if we're going to close context anyhow ctx.removeNamingListener(listener); // Close context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }
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);// www .j a v a 2 s .co m JFrame f = new JFrame("KeymapExample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); area.setText("This is a test."); f.pack(); f.setVisible(true); }
From source file:SortedResults.java
public static void main(String[] args) throws IOException { // Set up environment for creating 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 {/* w w w . ja va2 s . co m*/ // Create initial context with no connection request controls LdapContext ctx = new InitialLdapContext(env, null); // Create a sort control that sorts based on CN String sortKey = "cn"; ctx.setRequestControls(new Control[] { new SortControl(sortKey, Control.CRITICAL) }); // Perform a search NamingEnumeration results = ctx.search("", "(objectclass=*)", new SearchControls()); // Iterate over search results System.out.println("---->sort by cn"); while (results != null && results.hasMore()) { // Display an entry SearchResult entry = (SearchResult) results.next(); System.out.println(entry.getName()); // Handle the entry's response controls (if any) if (entry instanceof HasControls) { // ((HasControls)entry).getControls(); } } // Examine the sort control response Control[] controls = ctx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof SortResponseControl) { SortResponseControl src = (SortResponseControl) controls[i]; if (!src.isSorted()) { throw src.getException(); } } else { // Handle other response controls (if any) } } } // Close when no longer needed ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:PagedSearch.java
public static void main(String[] args) { Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); /* Specify host and port to use for directory service */ env.put(Context.PROVIDER_URL, "ldap://localhost:389/ou=People,o=JNDITutorial"); try {//from www . j a va 2 s . com LdapContext ctx = new InitialLdapContext(env, null); // Activate paged results int pageSize = 5; byte[] cookie = null; ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, Control.NONCRITICAL) }); int total; do { /* perform the search */ NamingEnumeration results = ctx.search("", "(objectclass=*)", new SearchControls()); /* for each entry print out name + all attrs and values */ while (results != null && results.hasMore()) { SearchResult entry = (SearchResult) results.next(); System.out.println(entry.getName()); } // Examine the paged results control response Control[] controls = ctx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i]; total = prrc.getResultSize(); if (total != 0) { System.out.println("(total : " + total); } else { System.out.println("(total: unknown)"); } cookie = prrc.getCookie(); } } } else { System.out.println("No controls were sent from the server"); } ctx.setRequestControls( new Control[] { new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } while (cookie != null); ctx.close(); } catch (NamingException e) { System.err.println("PagedSearch failed."); e.printStackTrace(); } catch (IOException ie) { System.err.println("PagedSearch failed."); ie.printStackTrace(); } }
From source file:ModAttrs.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 {// w w w . j a v a2 s .co m // Create the initial context DirContext ctx = new InitialDirContext(env); String name = "cn=Ted Geisel, ou=People"; // Save original attributes Attributes orig = ctx.getAttributes(name, new String[] { "mail", "telephonenumber", "jpegphoto" }); // Specify the changes to make ModificationItem[] mods = new ModificationItem[3]; // Replace the "mail" attribute with a new value mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("mail", "geisel@wizards.com")); // Add additional value to "telephonenumber" mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("telephonenumber", "+1 555 555 5555")); // Remove the "jpegphoto" attribute mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("jpegphoto")); // Perform the requested modifications on the named object ctx.modifyAttributes(name, mods); // Check attributes System.out.println("**** new attributes *****"); printAttrs(ctx.getAttributes(name)); // Revert changes ctx.modifyAttributes(name, DirContext.REPLACE_ATTRIBUTE, orig); // Check that the attributes got restored System.out.println("**** reverted to original attributes *****"); printAttrs(ctx.getAttributes(name)); // Close the context when we're done ctx.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:PagedSearch.java
public static void main(String[] args) { Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); /* Specify host and port to use for directory service */ env.put(Context.PROVIDER_URL, "ldap://localhost:389/ou=People,o=JNDITutorial"); try {/*from ww w .jav a2s .c o m*/ LdapContext ctx = new InitialLdapContext(env, null); // Activate paged results int pageSize = 5; byte[] cookie = null; ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, Control.NONCRITICAL) }); int total; do { /* perform the search */ NamingEnumeration results = ctx.search("", "(objectclass=*)", new SearchControls()); /* for each entry print out name + all attrs and values */ while (results != null && results.hasMore()) { SearchResult entry = (SearchResult) results.next(); System.out.println(entry.getName()); } // Examine the paged results control response Control[] controls = ctx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i]; total = prrc.getResultSize(); if (total != 0) { System.out.println("***************** END-OF-PAGE " + "(total : " + total + ") *****************\n"); } else { System.out.println( "***************** END-OF-PAGE " + "(total: unknown) ***************\n"); } cookie = prrc.getCookie(); } } } else { System.out.println("No controls were sent from the server"); } // Re-activate paged results ctx.setRequestControls( new Control[] { new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } while (cookie != null); ctx.close(); } catch (NamingException e) { System.err.println("PagedSearch failed."); e.printStackTrace(); } catch (IOException ie) { System.err.println("PagedSearch failed."); ie.printStackTrace(); } }
From source file:UseFactory.java
public static void main(String[] args) { // Set up environment for creating 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"); // Specify the socket factory env.put("java.naming.ldap.factory.socket", "CustomSocketFactory"); // Authenticate as S. User and password "mysecret" env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial"); env.put(Context.SECURITY_CREDENTIALS, "mysecret"); try {//from ww w . j a v a 2s .c om // Create initial context DirContext ctx = new InitialDirContext(env); System.out.println(ctx.lookup("ou=NewHires")); // ... do something useful with ctx // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }