KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jnditester


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 import java.rmi.*;
23 import java.awt.*;
24 import java.util.*;
25 import javax.ejb.*;
26 import javax.naming.*;
27 import java.awt.event.*;
28 import java.util.*;
29 import java.lang.*;
30 import java.io.*;
31
32 public class jnditester
33 {
34     public static void main(String JavaDoc[] args)
35     {
36         try
37         {
38             Properties p = new Properties();
39             
40             p.put(Context.INITIAL_CONTEXT_FACTORY,
41                   "org.jnp.interfaces.NamingContextFactory");
42             p.put(Context.PROVIDER_URL, "10.10.10.13:1100,10.10.10.14:1100");
43             //p.put(Context.PROVIDER_URL, "localhost:1100");
44
p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
45             InitialContext ctx = new InitialContext(p);
46             String JavaDoc hello = "hello world";
47
48             try
49             {
50                 String JavaDoc found = (String JavaDoc)ctx.lookup("testit");
51             }
52             catch (NameNotFoundException nfe)
53             {
54                 System.out.println("creating testit!!!");
55                 ctx.bind("testit", hello);
56             }
57
58             while (true)
59             {
60                 String JavaDoc found = null;
61                 try
62                 {
63                     found = (String JavaDoc)ctx.lookup("testit");
64                     System.out.println("found: " + found);
65                 }
66                 catch (NameNotFoundException nfe)
67                 {
68                     System.err.println("could not find testit");
69                 }
70                 Thread.sleep(2000);
71             }
72         }
73         catch (Exception JavaDoc ex)
74         {
75             ex.printStackTrace();
76         }
77     }
78 }
79
Popular Tags