28 29 import java.net.MalformedURLException; 30 import java.util.Hashtable; 31 32 import javax.naming.*; 33 import javax.naming.spi.ResolveResult; 34 import com.sun.jndi.dns.*; 35 import com.sun.jndi.toolkit.url.GenericURLDirContext; 36 37 38 /** 39 * A DNS URL context resolves names that are DNS pseudo-URLs. 40 * See com.sun.jndi.dns.DnsUrl for a description of the URL format. 41 * 42 * @author Scott Seligman 43 */ 44 45 46 public class dnsURLContext extends GenericURLDirContext { 47 48 public dnsURLContext(Hashtable env) { 49 super(env); 50 } 51 52 /** 53 * Resolves the host and port of "url" to a root context connected 54 * to the named DNS server, and returns the domain name as the 55 * remaining name. 56 */ 57 protected ResolveResult getRootURLContext(String url, Hashtable env) 58 throws NamingException { 59 60 DnsUrl dnsUrl; 61 try { 62 dnsUrl = new DnsUrl(url); 63 } catch (MalformedURLException e) { 64 throw new InvalidNameException(e.getMessage()); 65 } 66 67 DnsUrl[] urls = new DnsUrl[] { dnsUrl }; 68 String domain = dnsUrl.getDomain(); 69 70 return new ResolveResult( 71 DnsContextFactory.getContext(".", urls, env), 72 new CompositeName().add(domain)); 73 } 74 } | 28 29 import java.net.MalformedURLException; 30 import java.util.Hashtable; 31 32 import javax.naming.*; 33 import javax.naming.spi.ResolveResult; 34 import com.sun.jndi.dns.*; 35 import com.sun.jndi.toolkit.url.GenericURLDirContext; 36 37 38 /** 39 * A DNS URL context resolves names that are DNS pseudo-URLs. 40 * See com.sun.jndi.dns.DnsUrl for a description of the URL format. 41 * 42 * @author Scott Seligman 43 */ 44 45 46 public class dnsURLContext extends GenericURLDirContext { 47 48 public dnsURLContext(Hashtable<?,?> env) { 49 super(env); 50 } 51 52 /** 53 * Resolves the host and port of "url" to a root context connected 54 * to the named DNS server, and returns the domain name as the 55 * remaining name. 56 */ 57 protected ResolveResult getRootURLContext(String url, Hashtable<?,?> env) 58 throws NamingException { 59 60 DnsUrl dnsUrl; 61 try { 62 dnsUrl = new DnsUrl(url); 63 } catch (MalformedURLException e) { 64 throw new InvalidNameException(e.getMessage()); 65 } 66 67 DnsUrl[] urls = new DnsUrl[] { dnsUrl }; 68 String domain = dnsUrl.getDomain(); 69 70 return new ResolveResult( 71 DnsContextFactory.getContext(".", urls, env), 72 new CompositeName().add(domain)); 73 } 74 } |