Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/jndi/dns/DnsUrl.java
38924 views
/*1* Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jndi.dns;262728import java.net.MalformedURLException;29import java.util.Hashtable;30import java.util.StringTokenizer;3132import com.sun.jndi.toolkit.url.Uri;33import com.sun.jndi.toolkit.url.UrlUtil;343536/**37* A DnsUrl represents a DNS pseudo-URL of the form38* <pre>39* dns://[host][:port][/[domain]]40* or41* dns:[/][domain]42* </pre>43* The host names a DNS server. If the host is not provided, it44* indicates that the underlying platform's DNS server(s) should be45* used if possible, or that "localhost" should be used otherwise. If46* the port is not provided, the DNS default port 53 will be used.47* The domain indicates the domain name of the context, and is not48* necessarily related to the domain of the server; if it is not49* provided, the root domain "." is used. Special characters in50* the domain name must be %-escaped as described in RFC 2396.51*52* @author Scott Seligman53*/545556public class DnsUrl extends Uri {5758private String domain; // domain name of the context596061/**62* Given a space-separated list of DNS URLs, returns an array of DnsUrl63* objects.64*/65public static DnsUrl[] fromList(String urlList)66throws MalformedURLException {6768DnsUrl[] urls = new DnsUrl[(urlList.length() + 1) / 2];69int i = 0; // next available index in urls70StringTokenizer st = new StringTokenizer(urlList, " ");7172while (st.hasMoreTokens()) {73urls[i++] = new DnsUrl(st.nextToken());74}75DnsUrl[] trimmed = new DnsUrl[i];76System.arraycopy(urls, 0, trimmed, 0, i);77return trimmed;78}7980public DnsUrl(String url) throws MalformedURLException {81super(url);8283if (!scheme.equals("dns")) {84throw new MalformedURLException(85url + " is not a valid DNS pseudo-URL");86}8788domain = path.startsWith("/")89? path.substring(1)90: path;91domain = domain.equals("")92? "."93: UrlUtil.decode(domain);9495// Debug96// System.out.println("host=" + host + " port=" + port +97// " domain=" + domain);98}99100/**101* Returns the domain of this URL, or "." if none is provided.102* Never null.103*/104public String getDomain() {105return domain;106}107108109/*110// Debug111public static void main(String args[]) throws MalformedURLException {112DnsUrl[] urls = fromList(args[0]);113for (int i = 0; i < urls.length; i++) {114System.out.println(urls[i].toString());115}116}117*/118}119120121