1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +02:00

SMACK-225 Converted abstract class to interface, added missing hashcode method, fixed typos and some minor name changes and added licensing text

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_0@13600 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2013-04-01 13:40:02 +00:00
parent 0a1e72bb5f
commit 9da54ecbce
7 changed files with 81 additions and 23 deletions

View file

@ -22,18 +22,19 @@ import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
import org.xbill.DNS.Type;
public class DNSJavaResolver extends DNSResolver {
/**
* This implementation uses the <a href="http://www.dnsjava.org/">dnsjava</a> implementation for resolving DNS addresses.
*
*/
public class DNSJavaResolver implements DNSResolver {
private static DNSJavaResolver instance;
private static DNSJavaResolver instance = new DNSJavaResolver();
private DNSJavaResolver() {
}
public static DNSResolver getInstance() {
if (instance == null) {
instance = new DNSJavaResolver();
}
return instance;
}

View file

@ -17,8 +17,17 @@ package org.jivesoftware.smack.util.dns;
import java.util.List;
public abstract class DNSResolver {
/**
* Implementations of this interface define a class that is capable of resolving DNS addresses.
*
*/
public interface DNSResolver {
public abstract List<SRVRecord> lookupSRVRecords(String name);
/**
* Gets a list of service records for the specified service.
* @param name The symbolic name of the service.
* @return The list of SRV records mapped to the service name.
*/
List<SRVRecord> lookupSRVRecords(String name);
}

View file

@ -23,10 +23,10 @@ public class HostAddress {
/**
* Creates a new HostAddress with the given FQDN. The port will be set to the default XMPP client port: 5222
*
* @param fqdn
* @throws IllegalArgumentException
* @param fqdn Fully qualified domain name.
* @throws IllegalArgumentException If the fqdn is null.
*/
public HostAddress(String fqdn) throws IllegalArgumentException {
public HostAddress(String fqdn) {
if (fqdn == null)
throw new IllegalArgumentException("FQDN is null");
if (fqdn.charAt(fqdn.length() - 1) == '.') {
@ -39,7 +39,14 @@ public class HostAddress {
this.port = 5222;
}
public HostAddress(String fqdn, int port) throws IllegalArgumentException {
/**
* Creates a new HostAddress with the given FQDN. The port will be set to the default XMPP client port: 5222
*
* @param fqdn Fully qualified domain name.
* @param port The port to connect on.
* @throws IllegalArgumentException If the fqdn is null or port is out of valid range (0 - 65535).
*/
public HostAddress(String fqdn, int port) {
this(fqdn);
if (port < 0 || port > 65535)
throw new IllegalArgumentException(
@ -60,10 +67,12 @@ public class HostAddress {
this.exception = e;
}
@Override
public String toString() {
return fqdn + ":" + port;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
@ -80,6 +89,13 @@ public class HostAddress {
return port == address.port;
}
@Override
public int hashCode() {
int result = 1;
result = 37 * result + fqdn.hashCode();
return result * 37 + port;
}
public String getErrorMessage() {
String error;
if (exception == null) {

View file

@ -28,12 +28,12 @@ import javax.naming.directory.InitialDirContext;
import org.jivesoftware.smack.util.DNSUtil;
/**
* A DNS resolver (mostly for SRV records), which makes use of the API provided in the javax.* namepsace.
* A DNS resolver (mostly for SRV records), which makes use of the API provided in the javax.* namespace.
*
* @author Florian Schmaus
*
*/
public class JavaxResolver extends DNSResolver {
public class JavaxResolver implements DNSResolver {
private static JavaxResolver instance;
private static DirContext dirContext;
@ -48,14 +48,14 @@ public class JavaxResolver extends DNSResolver {
}
// Try to set this DNS resolver as primary one
DNSUtil.setDNSResolver(maybeGetInstance());
DNSUtil.setDNSResolver(getInstance());
}
private JavaxResolver() {
}
public static DNSResolver maybeGetInstance() {
public static DNSResolver getInstance() {
if (instance == null && isSupported()) {
instance = new JavaxResolver();
}

View file

@ -29,13 +29,13 @@ public class SRVRecord extends HostAddress implements Comparable<SRVRecord> {
/**
* Create a new SRVRecord
*
* @param fqdn
* @param port
* @param priority
* @param weight
* @throws IllegalArgumentException
* @param fqdn Fully qualified domain name
* @param port The connection port
* @param priority Priority of the target host
* @param weight Relative weight for records with same priority
* @throws IllegalArgumentException fqdn is null or any other field is not in valid range (0-65535).
*/
public SRVRecord(String fqdn, int port, int priority, int weight) throws IllegalArgumentException {
public SRVRecord(String fqdn, int port, int priority, int weight) {
super(fqdn, port);
if (weight < 0 || weight > 65535)
throw new IllegalArgumentException(
@ -60,6 +60,7 @@ public class SRVRecord extends HostAddress implements Comparable<SRVRecord> {
return weight;
}
@Override
public int compareTo(SRVRecord other) {
// According to RFC2782,
// "[a] client MUST attempt to contact the target host with the lowest-numbered priority it can reach".
@ -71,6 +72,7 @@ public class SRVRecord extends HostAddress implements Comparable<SRVRecord> {
return res;
}
@Override
public String toString() {
return super.toString() + " prio:" + priority + ":w:" + weight;
}