13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

488Chapter 21Introducti<strong>on</strong> to Enterprise JavaBeansExample 21.1 A sample JNDI applicati<strong>on</strong>import java.util.*;import javax.naming.*;import javax.naming.directory.*;5public class GetDomain {private Hashtable env = new Hashtable();private DirC<strong>on</strong>text dctx;private String domainQuery;10public GetDomain(String dom2Query) throws NamingExcepti<strong>on</strong> {domainQuery = dom2Query;env.put(C<strong>on</strong>text.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsC<strong>on</strong>textFactory");dctx = new InitialDirC<strong>on</strong>text(env);15 }20public NamingEnumerati<strong>on</strong> getDomainMembers() throws NamingExcepti<strong>on</strong> {return dctx.list(domainQuery);}public static void main(String[] args) {GetDomain gd = null;NamingEnumerati<strong>on</strong> ne = null;25 try {gd = new GetDomain(args[0]);ne = gd.getDomainMembers();while (ne.hasMore()) {30 Object o = ne.next();System.out.println("Object ["+o+"]");}} catch (Excepti<strong>on</strong> e) {35 e.printStackTrace();}}}40

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!