Return-Path: X-Original-To: apmail-logging-commits-archive@minotaur.apache.org Delivered-To: apmail-logging-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2FD2810B0C for ; Tue, 15 Apr 2014 04:53:44 +0000 (UTC) Received: (qmail 90632 invoked by uid 500); 15 Apr 2014 04:53:43 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 90544 invoked by uid 500); 15 Apr 2014 04:53:29 -0000 Mailing-List: contact commits-help@logging.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@logging.apache.org Delivered-To: mailing list commits@logging.apache.org Received: (qmail 90351 invoked by uid 99); 15 Apr 2014 04:53:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Apr 2014 04:53:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Apr 2014 04:53:23 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7736A23889E1; Tue, 15 Apr 2014 04:53:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1587411 - /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java Date: Tue, 15 Apr 2014 04:53:03 -0000 To: commits@logging.apache.org From: mattsicker@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140415045303.7736A23889E1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mattsicker Date: Tue Apr 15 04:53:03 2014 New Revision: 1587411 URL: http://svn.apache.org/r1587411 Log: Use Loader.loadClass. - Also shortened reflection usage thanks to varargs. Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java?rev=1587411&r1=1587410&r2=1587411&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java (original) +++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDNSAdvertiser.java Tue Apr 15 04:53:03 2014 @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.helpers.Integers; +import org.apache.logging.log4j.core.helpers.Loader; import org.apache.logging.log4j.status.StatusLogger; /** @@ -163,26 +164,17 @@ public class MulticastDNSAdvertiser impl return null; } - private Object buildServiceInfoVersion1(final String zone, final int port, final String name, final Map properties) { + private static Object buildServiceInfoVersion1(final String zone, + final int port, + final String name, + final Map properties) { //version 1 uses a hashtable + @SuppressWarnings("UseOfObsoleteCollectionType") final Hashtable hashtableProperties = new Hashtable(properties); try { - final Class[] args = new Class[6]; - args[0] = String.class; - args[1] = String.class; - args[2] = int.class; - args[3] = int.class; //weight (0) - args[4] = int.class; //priority (0) - args[5] = Hashtable.class; - final Constructor constructor = serviceInfoClass.getConstructor(args); - final Object[] values = new Object[6]; - values[0] = zone; - values[1] = name; - values[2] = port; - values[3] = 0; - values[4] = 0; - values[5] = hashtableProperties; - return constructor.newInstance(values); + return serviceInfoClass + .getConstructor(String.class, String.class, int.class, int.class, int.class, Hashtable.class) + .newInstance(zone, name, port, 0, 0, hashtableProperties); } catch (final IllegalAccessException e) { LOGGER.warn("Unable to construct ServiceInfo instance", e); } catch (final NoSuchMethodException e) { @@ -195,24 +187,14 @@ public class MulticastDNSAdvertiser impl return null; } - private Object buildServiceInfoVersion3(final String zone, final int port, final String name, final Map properties) { + private static Object buildServiceInfoVersion3(final String zone, + final int port, + final String name, + final Map properties) { try { - final Class[] args = new Class[6]; - args[0] = String.class; //zone/type - args[1] = String.class; //display name - args[2] = int.class; //port - args[3] = int.class; //weight (0) - args[4] = int.class; //priority (0) - args[5] = Map.class; - final Method serviceInfoCreateMethod = serviceInfoClass.getMethod("create", args); - final Object[] values = new Object[6]; - values[0] = zone; - values[1] = name; - values[2] = port; - values[3] = 0; - values[4] = 0; - values[5] = properties; - return serviceInfoCreateMethod.invoke(null, values); + return serviceInfoClass // zone/type display name port weight priority properties + .getMethod("create", String.class, String.class, int.class, int.class, int.class, Map.class) + .invoke(null, zone, name, port, 0, 0, properties); } catch (final IllegalAccessException e) { LOGGER.warn("Unable to invoke create method", e); } catch (final NoSuchMethodException e) { @@ -225,9 +207,8 @@ public class MulticastDNSAdvertiser impl private static Object initializeJMDNS() { try { - // FIXME: don't use Class.forName without a ClassLoader - jmDNSClass = Class.forName("javax.jmdns.JmDNS"); - serviceInfoClass = Class.forName("javax.jmdns.ServiceInfo"); + jmDNSClass = Loader.loadClass("javax.jmdns.JmDNS"); + serviceInfoClass = Loader.loadClass("javax.jmdns.ServiceInfo"); //if version 3 is available, use it to constuct a serviceInfo instance, otherwise support the version1 API boolean isVersion3 = false; try {