1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-22 02:27:58 +01:00

Make smack-resolver-javax an OSGi ServiceComponent

Fixes SMACK-576
This commit is contained in:
Florian Schmaus 2014-06-17 18:01:36 +02:00
parent a77adc018b
commit 298822eaef
4 changed files with 31 additions and 7 deletions

View file

@ -200,7 +200,7 @@ subprojects {
}
}
['smack-extensions', 'smack-experimental', 'smack-legacy'].each { name ->
['smack-resolver-javax', 'smack-extensions', 'smack-experimental', 'smack-legacy'].each { name ->
project(":$name") {
jar {
manifest {

View file

@ -29,6 +29,7 @@ task dnsJar(type: Jar) {
from sourceSets.main.output
include('org/jivesoftware/smack/util/dns/**')
include('org/jivesoftware/smack/util/DNSUtil.class')
include('org/jivesoftware/smack/initializer/**')
}
artifacts {

View file

@ -17,6 +17,7 @@
package org.jivesoftware.smack.util.dns.javax;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
@ -27,6 +28,7 @@ import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import org.jivesoftware.smack.initializer.SmackInitializer;
import org.jivesoftware.smack.util.DNSUtil;
import org.jivesoftware.smack.util.dns.DNSResolver;
import org.jivesoftware.smack.util.dns.SRVRecord;
@ -37,7 +39,7 @@ import org.jivesoftware.smack.util.dns.SRVRecord;
* @author Florian Schmaus
*
*/
public class JavaxResolver implements DNSResolver {
public class JavaxResolver implements DNSResolver, SmackInitializer {
private static JavaxResolver instance;
private static DirContext dirContext;
@ -52,24 +54,28 @@ public class JavaxResolver implements DNSResolver {
}
// Try to set this DNS resolver as primary one
DNSUtil.setDNSResolver(getInstance());
setup();
}
private JavaxResolver() {
public JavaxResolver() {
}
public static DNSResolver getInstance() {
public static synchronized DNSResolver getInstance() {
if (instance == null && isSupported()) {
instance = new JavaxResolver();
}
return instance;
}
public static boolean isSupported() {
return dirContext != null;
}
public static void setup() {
DNSUtil.setDNSResolver(getInstance());
}
@Override
public List<SRVRecord> lookupSRVRecords(String name) throws NamingException {
List<SRVRecord> res = new ArrayList<SRVRecord>();
@ -93,4 +99,15 @@ public class JavaxResolver implements DNSResolver {
}
return res;
}
@Override
public List<Exception> initialize() {
return initialize(null);
}
@Override
public List<Exception> initialize(ClassLoader classLoader) {
setup();
return Collections.emptyList();
}
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.2.0"
enabled="true" immediate="true" name="Smack Resolver JavaX API">
<implementation
class="org.jivesoftware.smack.util.dns.javax.JavaxResolver" />
</scr:component>