1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

Make resolver-dnsjava, -minidns initializer

and OSGi components.

There is really no need to treat them different then
resolver-javax. This also allows the removal of the DNSUtil.init() method.
This commit is contained in:
Florian Schmaus 2014-08-11 19:21:43 +02:00
parent a5eebf3840
commit 0c0737942c
10 changed files with 55 additions and 50 deletions

View file

@ -38,7 +38,6 @@ import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.initializer.SmackInitializer;
import org.jivesoftware.smack.parsing.ExceptionThrowingCallback;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.util.DNSUtil;
import org.jivesoftware.smack.util.FileUtils;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParser;
@ -169,9 +168,6 @@ public final class SmackConfiguration {
catch (Exception e) {
// Ignore.
}
// Initialize the DNS resolvers
DNSUtil.init();
}
/**

View file

@ -16,6 +16,8 @@
*/
package org.jivesoftware.smack.initializer;
import java.util.List;
public abstract class SmackAndOsgiInitializer implements SmackInitializer {
/**
@ -25,4 +27,10 @@ public abstract class SmackAndOsgiInitializer implements SmackInitializer {
public final void activate() {
initialize();
}
@Override
public List<Exception> initialize(ClassLoader classLoader) {
return initialize();
}
}

View file

@ -16,8 +16,6 @@
*/
package org.jivesoftware.smack.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
@ -41,31 +39,6 @@ public class DNSUtil {
private static final Logger LOGGER = Logger.getLogger(DNSUtil.class.getName());
private static DNSResolver dnsResolver = null;
/**
* Initializes DNSUtil. This method is automatically called by SmackConfiguration, you don't
* have to call it manually.
*/
public static void init() {
final String[] RESOLVERS = new String[] { "javax.JavaxResolver", "minidns.MiniDnsResolver",
"dnsjava.DNSJavaResolver" };
for (String resolver :RESOLVERS) {
DNSResolver availableResolver = null;
String resolverFull = "org.jivesoftware.smack.util.dns" + resolver;
try {
Class<?> resolverClass = Class.forName(resolverFull);
Method getInstanceMethod = resolverClass.getMethod("getInstance");
availableResolver = (DNSResolver) getInstanceMethod.invoke(null);
if (availableResolver != null) {
setDNSResolver(availableResolver);
break;
}
}
catch (ClassNotFoundException|NoSuchMethodException|SecurityException|IllegalAccessException|IllegalArgumentException|InvocationTargetException e) {
LOGGER.log(Level.FINE, "Exception on init", e);
}
}
}
/**
* Set the DNS resolver that should be used to perform DNS lookups.
*

View file

@ -9,6 +9,8 @@
<optionalStartupClasses>
<className>org.jivesoftware.smack.util.dns.javax.JavaxResolver</className>
<className>org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver</className>
<className>org.jivesoftware.smack.util.dns.dnsjava.DNSJavaResolver</className>
<className>org.jivesoftware.smack.initializer.extensions.ExtensionsInitializer</className>
<className>org.jivesoftware.smack.initializer.experimental.ExperimentalInitializer</className>
<className>org.jivesoftware.smack.initializer.legacy.LegacyInitializer</className>