1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-12 19:02:06 +01: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

@ -203,6 +203,36 @@ last release.
to use these icons outside of Smack.</li>
<li>Third-party source code is licensed as noted in their source files.
<li>Third-party binary code is licensed as follows.
<pre>
<b>dnsjava</b> <a href="http://dnsjava.org">(http://dnsjava.org)</a>
Copyright (c) 1999-2005, Brian Wellington
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the dnsjava project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre></li>
</ul>
</div>

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;
}

View file

@ -24,7 +24,7 @@ public class DNSUtilTest {
@Test
public void xmppClientDomainJavaXTest() {
DNSResolver resolver = JavaxResolver.maybeGetInstance();
DNSResolver resolver = JavaxResolver.getInstance();
assertNotNull(resolver);
DNSUtil.setDNSResolver(resolver);
xmppClientDomainTest();
@ -32,7 +32,7 @@ public class DNSUtilTest {
@Test
public void xmppServerDomainJavaXTest() {
DNSResolver resolver = JavaxResolver.maybeGetInstance();
DNSResolver resolver = JavaxResolver.getInstance();
assertNotNull(resolver);
DNSUtil.setDNSResolver(resolver);
xmppServerDomainTest();