logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject svn commit: r1599075 - /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java
Date Sun, 01 Jun 2014 22:56:57 GMT
Author: mattsicker
Date: Sun Jun  1 22:56:57 2014
New Revision: 1599075

URL: http://svn.apache.org/r1599075
Log:
Add member to visitor, refactor how factory method is used.

  - Pass the Method instead of the arrays in order to access its 
  Member interface.
  - Pass the Method and Field as the Member to the visitor in their 
  respective blocks.
  - Don't overwrite fields in builders if the converted value is null.

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java?rev=1599075&r1=1599074&r2=1599075&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java
Sun Jun  1 22:56:57 2014
@@ -122,7 +122,7 @@ public class PluginBuilder<T> implements
         // or fall back to factory method if no builder class is available
         try {
             final Method factory = findFactoryMethod(this.clazz);
-            final Object[] params = generateParameters(factory.getParameterTypes(), factory.getParameterAnnotations());
+            final Object[] params = generateParameters(factory);
             @SuppressWarnings("unchecked")
             final T plugin = (T) factory.invoke(null, params);
             return plugin;
@@ -170,8 +170,12 @@ public class PluginBuilder<T> implements
                         .setAnnotation(a)
                         .setConversionType(field.getType())
                         .setStrSubstitutor(configuration.getStrSubstitutor())
+                        .setMember(field)
                         .visit(configuration, node, event);
-                    field.set(builder, value);
+                    // don't overwrite default values if the visitor gives us no value to
inject
+                    if (value != null) {
+                        field.set(builder, value);
+                    }
                 }
             }
         }
@@ -191,7 +195,9 @@ public class PluginBuilder<T> implements
         return null;
     }
 
-    private Object[] generateParameters(final Class<?>[] types, final Annotation[][]
annotations) {
+    private Object[] generateParameters(final Method factory) {
+        final Class<?>[] types = factory.getParameterTypes();
+        final Annotation[][] annotations = factory.getParameterAnnotations();
         final Object[] args = new Object[annotations.length];
         for (int i = 0; i < annotations.length; i++) {
             final String[] aliases = extractPluginAliases(annotations[i]);
@@ -207,6 +213,7 @@ public class PluginBuilder<T> implements
                         .setAnnotation(a)
                         .setConversionType(types[i])
                         .setStrSubstitutor(configuration.getStrSubstitutor())
+                        .setMember(factory)
                         .visit(configuration, node, event);
                 }
             }



Mime
View raw message