001 /*
002 * The MIT License
003 * Copyright (c) 2012 Microsoft Corporation
004 *
005 * Permission is hereby granted, free of charge, to any person obtaining a copy
006 * of this software and associated documentation files (the "Software"), to deal
007 * in the Software without restriction, including without limitation the rights
008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
009 * copies of the Software, and to permit persons to whom the Software is
010 * furnished to do so, subject to the following conditions:
011 *
012 * The above copyright notice and this permission notice shall be included in
013 * all copies or substantial portions of the Software.
014 *
015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
021 * THE SOFTWARE.
022 */
023
024 package microsoft.exchange.webservices.data.dns;
025
026 import microsoft.exchange.webservices.data.core.exception.dns.DnsException;
027
028 import java.util.NoSuchElementException;
029 import java.util.StringTokenizer;
030
031 /**
032 * Represents a DNS SRV Record.
033 */
034 public class DnsSrvRecord extends DnsRecord {
035 /*
036 * The string representing the target host
037 */
038 /**
039 * The target.
040 */
041 private String target;
042
043 /*
044 * priority of the target host specified in the owner name.
045 */
046 /**
047 * The priority.
048 */
049 private int priority;
050 /*
051 * weight of the target host
052 */
053 /**
054 * The weight.
055 */
056 private int weight;
057 /*
058 * port used on the target for the service
059 */
060 /**
061 * The port.
062 */
063 private int port;
064
065 /**
066 * Retrieves the value of the target property.
067 *
068 * @return target
069 */
070 public String getNameTarget() {
071 return this.target;
072 }
073
074 /**
075 * Retrieves the value of the priority property.
076 *
077 * @return priority
078 */
079 public int getPriority() {
080 return priority;
081 }
082
083 /**
084 * Retrieves the value of the weight property.
085 *
086 * @return weight
087 */
088 public int getWeight() {
089 return weight;
090 }
091
092 /**
093 * Retrieves the value of the port property.
094 *
095 * @return port
096 */
097 public int getPort() {
098 return port;
099 }
100
101 /**
102 * Initializes a new instance of the DnsSrvRecord class.
103 *
104 * @param srvRecord srvRecord that is fetched from JNDI
105 * @throws DnsException the dns exception
106 */
107 protected void load(String srvRecord) throws DnsException {
108 super.load(null);
109 StringTokenizer strTokens = new StringTokenizer(srvRecord);
110 try {
111 while (strTokens.hasMoreTokens()) {
112 String priority = strTokens.nextToken();
113 this.priority = Integer.parseInt(priority);
114
115 String weight = strTokens.nextToken();
116 this.weight = Integer.parseInt(weight);
117
118 String port = strTokens.nextToken();
119 this.port = Integer.parseInt(port);
120
121 String target = strTokens.nextToken();
122 this.target = target;
123 }
124 } catch (NumberFormatException ne) {
125 throw new DnsException("NumberFormatException " + ne.getMessage());
126 } catch (NoSuchElementException ne) {
127 throw new DnsException("NoSuchElementException " + ne.getMessage());
128 }
129
130 }
131 }