Repository: logging-log4j2
Updated Branches:
  refs/heads/master 182df44c6 -> f5f20f7a9


Introduce AbstractLookup as a common superclass for many lookups to
reduce code duplication.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f5f20f7a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f5f20f7a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f5f20f7a

Branch: refs/heads/master
Commit: f5f20f7a95b4035bd4313e8484dd270069593a94
Parents: 182df44
Author: Gary Gregory <[email protected]>
Authored: Sat Sep 20 15:40:07 2014 -0400
Committer: Gary Gregory <[email protected]>
Committed: Sat Sep 20 15:40:07 2014 -0400

----------------------------------------------------------------------
 .../log4j/core/lookup/AbstractLookup.java       | 36 ++++++++++++++++++++
 .../log4j/core/lookup/EnvironmentLookup.java    | 12 +------
 .../logging/log4j/core/lookup/Interpolator.java | 19 +----------
 .../logging/log4j/core/lookup/JndiLookup.java   | 12 +------
 .../log4j/core/lookup/ResourceBundleLookup.java | 24 +++----------
 .../core/lookup/SystemPropertiesLookup.java     | 20 +++--------
 .../org/apache/logging/log4j/web/WebLookup.java | 12 ++-----
 7 files changed, 52 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f5f20f7a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/AbstractLookup.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/AbstractLookup.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/AbstractLookup.java
new file mode 100644
index 0000000..f2a2027
--- /dev/null
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/AbstractLookup.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.lookup;
+
+/**
+ * A default lookup for others to extend.
+ * 
+ * @since 2.1
+ */
+public abstract class AbstractLookup implements StrLookup {
+
+    /**
+     * Calls {@code lookup(null, key);}
+     * 
+     * @see StrLookup#lookup(LogEvent, String)
+     */
+    @Override
+    public String lookup(String key) {
+        return lookup(null, key);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f5f20f7a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/EnvironmentLookup.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/EnvironmentLookup.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/EnvironmentLookup.java
index 919bfe2..133dcfe 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/EnvironmentLookup.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/EnvironmentLookup.java
@@ -23,17 +23,7 @@ import org.apache.logging.log4j.core.config.plugins.Plugin;
  * Looks up keys from environment variables.
  */
 @Plugin(name = "env", category = "Lookup")
-public class EnvironmentLookup implements StrLookup {
-
-    /**
-     * Looks up the value of the environment variable.
-     * @param key  the key to be looked up, may be null
-     * @return The value of the environment variable.
-     */
-    @Override
-    public String lookup(final String key) {
-        return System.getenv(key);
-    }
+public class EnvironmentLookup extends AbstractLookup {
 
     /**
      * Looks up the value of the environment variable.

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f5f20f7a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
index d315d4e..0282bd0 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
@@ -30,7 +30,7 @@ import java.util.Map;
 /**
  * Proxies all the other {@link StrLookup}s.
  */
-public class Interpolator implements StrLookup {
+public class Interpolator extends AbstractLookup {
 
     private static final Logger LOGGER = StatusLogger.getLogger();
 
@@ -123,23 +123,6 @@ public class Interpolator implements StrLookup {
         }
     }
 
-     /**
-     * Resolves the specified variable. This implementation will try to extract
-     * a variable prefix from the given variable name (the first colon (':') is
-     * used as prefix separator). It then passes the name of the variable with
-     * the prefix stripped to the lookup object registered for this prefix. If
-     * no prefix can be found or if the associated lookup object cannot resolve
-     * this variable, the default lookup object will be used.
-     *
-     * @param var the name of the variable whose value is to be looked up
-     * @return the value of this variable or <b>null</b> if it cannot be
-     * resolved
-     */
-    @Override
-    public String lookup(final String var) {
-        return lookup(null, var);
-    }
-
     /**
      * Resolves the specified variable. This implementation will try to extract
      * a variable prefix from the given variable name (the first colon (':') is

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f5f20f7a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
index 813230c..be97f1f 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
@@ -32,7 +32,7 @@ import org.apache.logging.log4j.status.StatusLogger;
  * Looks up keys from JNDI resources.
  */
 @Plugin(name = "jndi", category = "Lookup")
-public class JndiLookup implements StrLookup {
+public class JndiLookup extends AbstractLookup {
 
     private static final Logger LOGGER = StatusLogger.getLogger();
     private static final Marker LOOKUP = MarkerManager.getMarker("LOOKUP");
@@ -42,16 +42,6 @@ public class JndiLookup implements StrLookup {
 
     /**
      * Looks up the value of the JNDI resource.
-     * @param key  the JNDI resource name to be looked up, may be null
-     * @return The value of the JNDI resource.
-     */
-    @Override
-    public String lookup(final String key) {
-        return lookup(null, key);
-    }
-
-    /**
-     * Looks up the value of the JNDI resource.
      * @param event The current LogEvent (is ignored by this StrLookup).
      * @param key  the JNDI resource name to be looked up, may be null
      * @return The value of the JNDI resource.

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f5f20f7a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookup.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookup.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookup.java
index 07bf419..3bbf1f5 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookup.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ResourceBundleLookup.java
@@ -30,7 +30,7 @@ import org.apache.logging.log4j.status.StatusLogger;
  * Looks up keys from resource bundles.
  */
 @Plugin(name = "bundle", category = "Lookup")
-public class ResourceBundleLookup implements StrLookup {
+public class ResourceBundleLookup extends AbstractLookup {
 
     private static final Logger LOGGER = StatusLogger.getLogger();
     private static final Marker LOOKUP = MarkerManager.getMarker("LOOKUP");
@@ -40,12 +40,14 @@ public class ResourceBundleLookup implements StrLookup {
      *
      * For example: "com.domain.messages:MyKey".
      *
+     * @param event
+     *            The current LogEvent.
      * @param key
      *            the key to be looked up, may be null
-     * @return The value for the key.
+     * @return The value associated with the key.
      */
     @Override
-    public String lookup(final String key) {
+    public String lookup(final LogEvent event, final String key) {
         if (key == null) {
             return null;
         }
@@ -65,20 +67,4 @@ public class ResourceBundleLookup implements StrLookup {
             return null;
         }
     }
-
-    /**
-     * Looks up the value for the key in the format "BundleName:BundleKey".
-     *
-     * For example: "com.domain.messages:MyKey".
-     *
-     * @param event
-     *            The current LogEvent.
-     * @param key
-     *            the key to be looked up, may be null
-     * @return The value associated with the key.
-     */
-    @Override
-    public String lookup(final LogEvent event, final String key) {
-        return lookup(key);
-    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f5f20f7a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
index 575a3dd..b1641f2 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
@@ -27,18 +27,19 @@ import org.apache.logging.log4j.status.StatusLogger;
  * Looks up keys from system properties.
  */
 @Plugin(name = "sys", category = "Lookup")
-public class SystemPropertiesLookup implements StrLookup {
+public class SystemPropertiesLookup extends AbstractLookup {
 
     private static final Logger LOGGER = StatusLogger.getLogger();
     private static final Marker LOOKUP = MarkerManager.getMarker("LOOKUP");
 
     /**
-     * Looks up the value for the key.
+     * Looks up the value for the key using the data in the LogEvent.
+     * @param event The current LogEvent.
      * @param key  the key to be looked up, may be null
-     * @return The value for the key.
+     * @return The value associated with the key.
      */
     @Override
-    public String lookup(final String key) {
+    public String lookup(final LogEvent event, final String key) {
         try {
             return System.getProperty(key);
         } catch (final Exception ex) {
@@ -46,15 +47,4 @@ public class SystemPropertiesLookup implements StrLookup {
             return null;
         }
     }
-
-    /**
-     * Looks up the value for the key using the data in the LogEvent.
-     * @param event The current LogEvent.
-     * @param key  the key to be looked up, may be null
-     * @return The value associated with the key.
-     */
-    @Override
-    public String lookup(final LogEvent event, final String key) {
-        return lookup(key);
-    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f5f20f7a/log4j-web/src/main/java/org/apache/logging/log4j/web/WebLookup.java
----------------------------------------------------------------------
diff --git 
a/log4j-web/src/main/java/org/apache/logging/log4j/web/WebLookup.java 
b/log4j-web/src/main/java/org/apache/logging/log4j/web/WebLookup.java
index cf3c0c7..eb0a26a 100644
--- a/log4j-web/src/main/java/org/apache/logging/log4j/web/WebLookup.java
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/WebLookup.java
@@ -25,11 +25,10 @@ import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.impl.ContextAnchor;
-import org.apache.logging.log4j.core.lookup.StrLookup;
-
+import org.apache.logging.log4j.core.lookup.AbstractLookup;
 
 @Plugin(name = "web", category = "Lookup")
-public class WebLookup implements StrLookup {
+public class WebLookup extends AbstractLookup {
     private static final String ATTR_PREFIX = "attr.";
     private static final String INIT_PARAM_PREFIX = "initParam.";
 
@@ -46,7 +45,7 @@ public class WebLookup implements StrLookup {
     }
 
     @Override
-    public String lookup(final String key) {
+    public String lookup(final LogEvent event, final String key) {
         final ServletContext ctx = getServletContext();
         if (ctx == null) {
             return null;
@@ -113,9 +112,4 @@ public class WebLookup implements StrLookup {
         ctx.log(getClass().getName() + " unable to resolve key '" + key + 
'\'');
         return null;
     }
-
-    @Override
-    public String lookup(final LogEvent event, final String key) {
-        return lookup(key);
-    }
 }

Reply via email to