You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2007/04/12 07:17:13 UTC

svn commit: r527771 [2/2] - in /logging/log4j/trunk/src/java/org/apache/log4j: filter/ helpers/ rule/ spi/

Modified: logging/log4j/trunk/src/java/org/apache/log4j/rule/OrRule.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/rule/OrRule.java?view=diff&rev=527771&r1=527770&r2=527771
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/rule/OrRule.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/rule/OrRule.java Wed Apr 11 22:17:12 2007
@@ -5,9 +5,9 @@
  * 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.
@@ -22,31 +22,59 @@
 import java.util.Stack;
 
 /**
- * A Rule class implementing logical or. 
- * 
- * @author Scott Deboy <sd...@apache.org>
+ * A Rule class implementing logical or.
+ *
+ * @author Scott Deboy (sdeboy@apache.org)
  */
 public class OrRule extends AbstractRule {
-  static final long serialVersionUID = 2088765995061413165L;    
+    /**
+     * Serialization ID.
+     */
+  static final long serialVersionUID = 2088765995061413165L;
+    /**
+     * rule 1.
+     */
   private final Rule rule1;
+    /**
+     * Rule 2.
+     */
   private final Rule rule2;
 
-  private OrRule(Rule firstParam, Rule secondParam) {
+    /**
+     * Create new instance.
+     * @param firstParam first rule
+     * @param secondParam second rule
+     */
+  private OrRule(final Rule firstParam, final Rule secondParam) {
+    super();
     this.rule1 = firstParam;
     this.rule2 = secondParam;
   }
 
-  public static Rule getRule(Rule firstParam, Rule secondParam) {
+    /**
+     * Create new instance.
+     * @param firstParam first rule
+     * @param secondParam second rule
+     * @return new instance
+     */
+  public static Rule getRule(final Rule firstParam, final Rule secondParam) {
       return new OrRule(firstParam, secondParam);
   }
-  
-  public static Rule getRule(Stack stack) {
+
+    /**
+     * Create new instance from top two elements of stack.
+     * @param stack stack
+     * @return new instance
+     */
+  public static Rule getRule(final Stack stack) {
       if (stack.size() < 2) {
-          throw new IllegalArgumentException("Invalid OR rule - expected two rules but received " + stack.size());
-      }  
+          throw new IllegalArgumentException(
+                  "Invalid OR rule - expected two rules but received "
+                          + stack.size());
+      }
       Object o2 = stack.pop();
       Object o1 = stack.pop();
-      if ((o2 instanceof Rule) && (o1 instanceof Rule)) { 
+      if ((o2 instanceof Rule) && (o1 instanceof Rule)) {
           Rule p2 = (Rule) o2;
           Rule p1 = (Rule) o1;
           return new OrRule(p1, p2);
@@ -54,7 +82,8 @@
       throw new IllegalArgumentException("Invalid OR rule: " + o2 + "..." + o1);
   }
 
-  public boolean evaluate(LoggingEvent event) {
+  /** {@inheritDoc} */
+  public boolean evaluate(final LoggingEvent event) {
     return (rule1.evaluate(event) || rule2.evaluate(event));
   }
 }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/rule/PartialTextMatchRule.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/rule/PartialTextMatchRule.java?view=diff&rev=527771&r1=527770&r2=527771
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/rule/PartialTextMatchRule.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/rule/PartialTextMatchRule.java Wed Apr 11 22:17:12 2007
@@ -24,19 +24,38 @@
 
 
 /**
- * A Rule class implementing case-insensitive partial-text matches against two strings.
+ * A Rule class implementing case-insensitive
+ * partial-text matches against two strings.
  *
- * @author Scott Deboy <sd...@apache.org>
+ * @author Scott Deboy (sdeboy@apache.org)
  */
 public class PartialTextMatchRule extends AbstractRule {
+    /**
+     * Serialization ID.
+     */
   static final long serialVersionUID = 6963284773637727558L;
-  private static final LoggingEventFieldResolver resolver =
+    /**
+     * Resolver.
+     */
+  private static final LoggingEventFieldResolver RESOLVER =
     LoggingEventFieldResolver.getInstance();
+    /**
+     * Field.
+     */
   private final String field;
+    /**
+     * Value.
+     */
   private final String value;
 
-  private PartialTextMatchRule(String field, String value) {
-    if (!resolver.isField(field)) {
+    /**
+     * Create new instance.
+     * @param field field
+     * @param value value
+     */
+  private PartialTextMatchRule(final String field, final String value) {
+    super();
+    if (!RESOLVER.isField(field)) {
       throw new IllegalArgumentException(
         "Invalid partial text rule - " + field + " is not a supported field");
     }
@@ -45,11 +64,22 @@
     this.value = value;
   }
 
-  public static Rule getRule(String field, String value) {
+    /**
+     * Create new instance.
+     * @param field field
+     * @param value value
+     * @return new instance
+     */
+  public static Rule getRule(final String field, final String value) {
     return new PartialTextMatchRule(field, value);
   }
 
-  public static Rule getRule(Stack stack) {
+    /**
+     * Create new instance from top two elements of stack.
+     * @param stack stack
+     * @return new instance
+     */
+  public static Rule getRule(final Stack stack) {
     if (stack.size() < 2) {
       throw new IllegalArgumentException(
         "invalid partial text rule - expected two parameters but received "
@@ -62,8 +92,9 @@
     return new PartialTextMatchRule(p1, p2);
   }
 
-  public boolean evaluate(LoggingEvent event) {
-    Object p2 = resolver.getValue(field, event);
+    /** {@inheritDoc} */
+  public boolean evaluate(final LoggingEvent event) {
+    Object p2 = RESOLVER.getValue(field, event);
 
     return ((p2 != null) && (value != null)
     && (p2.toString().toLowerCase().indexOf(value.toLowerCase()) > -1));

Modified: logging/log4j/trunk/src/java/org/apache/log4j/rule/Rule.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/rule/Rule.java?view=diff&rev=527771&r1=527770&r2=527771
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/rule/Rule.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/rule/Rule.java Wed Apr 11 22:17:12 2007
@@ -5,9 +5,9 @@
  * 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.
@@ -29,12 +29,12 @@
  * listeners when the underlying implementation of this Rule has it's
  * criteria changed by using the standard PropertyChangeListener infrastructure.
  *
- * @author Paul Smith <ps...@apache.org>
- * @author Scott Deboy <sd...@apache.org>
+ * @author Paul Smith (psmith@apache.org)
+ * @author Scott Deboy (sdeboy@apache.org)
  */
 public interface Rule {
   /**
-   * Returns true if this implementation of the rule accepts the LoggingEvent, 
+   * Returns true if this implementation of the rule accepts the LoggingEvent,
    * or false if not.
    *
    * <p>What True/False means can be client-specific.
@@ -42,19 +42,19 @@
    * @param e LoggingEvent this instance will evaluate
    * @return true if this Rule instance accepts the event, otherwise false.
    */
-  public boolean evaluate(LoggingEvent e);
+  boolean evaluate(LoggingEvent e);
 
   /**
-   * Adds a PropertyChangeListener to this instance, which is notified when 
-   * underlying Rule information has changed. 
+   * Adds a PropertyChangeListener to this instance, which is notified when
+   * underlying Rule information has changed.
    * (there are no specific property name events).
-   * @param listener
+   * @param listener listener
    */
-  public void addPropertyChangeListener(PropertyChangeListener listener);
+  void addPropertyChangeListener(PropertyChangeListener listener);
 
   /**
    * Removes a known PropertyChangeListener from this Rule.
-   * @param listener
+   * @param listener listener
    */
-  public void removePropertyChangeListener(PropertyChangeListener listener);
+  void removePropertyChangeListener(PropertyChangeListener listener);
 }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/rule/RuleFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/rule/RuleFactory.java?view=diff&rev=527771&r1=527770&r2=527771
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/rule/RuleFactory.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/rule/RuleFactory.java Wed Apr 11 22:17:12 2007
@@ -5,9 +5,9 @@
  * 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.
@@ -25,60 +25,126 @@
 import org.apache.log4j.LogManager;
 
 /**
- * A Factory class which, given a string representation of the rule, and a context stack, will
- * return a Rule ready for evaluation against events.  If an operator is requested that isn't supported, 
- * or if a LIKE rule is requested and the ORO package is not available, an IllegalArgumentException is thrown. 
- * 
- * @author Scott Deboy <sd...@apache.org>
+ * A Factory class which, given a string representation of the rule,
+ * and a context stack, will
+ * return a Rule ready for evaluation against events.
+ * If an operator is requested that isn't supported,
+ * or if a LIKE rule is requested and the ORO package
+ * is not available, an IllegalArgumentException is thrown.
+ *
+ * @author Scott Deboy (sdeboy@apache.org)
  */
-public class RuleFactory {
-  private static final RuleFactory factory_ = new RuleFactory(); 
-  private static final Collection rules = new LinkedList();
+public final class RuleFactory {
+    /**
+     * Singleton instance.
+     */
+  private static final RuleFactory FACTORY = new RuleFactory();
+    /**
+     * Rules.
+     */
+  private static final Collection RULES = new LinkedList();
+    /**
+     * AND operator literal.
+     */
   private static final String AND_RULE = "&&";
+    /**
+     * OR operator literal.
+     */
   private static final String OR_RULE = "||";
+    /**
+     * NOT operator literal.
+     */
   private static final String NOT_RULE = "!";
+    /**
+     * Inequality operator literal.
+     */
   private static final String NOT_EQUALS_RULE = "!=";
+    /**
+     * Equality operator literal.
+     */
   private static final String EQUALS_RULE = "==";
+    /**
+     * Partial match operator literal.
+     */
   private static final String PARTIAL_TEXT_MATCH_RULE = "~=";
+    /**
+     * Like operator literal.
+     */
   private static final String LIKE_RULE = "like";
+    /**
+     * Exists operator literal.
+     */
   private static final String EXISTS_RULE = "exists";
+    /**
+     * Less than operator literal.
+     */
   private static final String LESS_THAN_RULE = "<";
+    /**
+     * Greater than operator literal.
+     */
   private static final String GREATER_THAN_RULE = ">";
+    /**
+     * Less than or equal operator literal.
+     */
   private static final String LESS_THAN_EQUALS_RULE = "<=";
+    /**
+     * Greater than or equal operator literal.
+     */
   private static final String GREATER_THAN_EQUALS_RULE = ">=";
-  
+
   static {
-    rules.add(AND_RULE);
-    rules.add(OR_RULE);
-    rules.add(NOT_RULE);
-    rules.add(NOT_EQUALS_RULE);
-    rules.add(EQUALS_RULE);
-    rules.add(PARTIAL_TEXT_MATCH_RULE);
+    RULES.add(AND_RULE);
+    RULES.add(OR_RULE);
+    RULES.add(NOT_RULE);
+    RULES.add(NOT_EQUALS_RULE);
+    RULES.add(EQUALS_RULE);
+    RULES.add(PARTIAL_TEXT_MATCH_RULE);
     try {
-    	Class.forName("org.apache.log4j.rule.LikeRule");
-    	rules.add(LIKE_RULE);
+        Class.forName("org.apache.log4j.rule.LikeRule");
+        RULES.add(LIKE_RULE);
     } catch (Exception e) {
-    	LogManager.getLogger(RuleFactory.class).info("Like (regular expression) rule not supported");
+        LogManager.getLogger(RuleFactory.class).info(
+                "Like (regular expression) rule not supported");
     }
-    	
-    rules.add(EXISTS_RULE);
-    rules.add(LESS_THAN_RULE);
-    rules.add(GREATER_THAN_RULE);
-    rules.add(LESS_THAN_EQUALS_RULE);
-    rules.add(GREATER_THAN_EQUALS_RULE);
+
+    RULES.add(EXISTS_RULE);
+    RULES.add(LESS_THAN_RULE);
+    RULES.add(GREATER_THAN_RULE);
+    RULES.add(LESS_THAN_EQUALS_RULE);
+    RULES.add(GREATER_THAN_EQUALS_RULE);
   }
 
-  private RuleFactory() {}
-  
+    /**
+     * Create instance.
+     */
+  private RuleFactory() {
+        super();
+    }
+
+    /**
+     * Get instance.
+     * @return rule factory instance.
+     */
   public static RuleFactory getInstance() {
-      return factory_;
+      return FACTORY;
   }
-  
-  public boolean isRule(String symbol) {
-    return ((symbol != null) && (rules.contains(symbol.toLowerCase())));
+
+    /**
+     * Determine if specified string is a known operator.
+     * @param symbol string
+     * @return true if string is a known operator
+     */
+  public boolean isRule(final String symbol) {
+    return ((symbol != null) && (RULES.contains(symbol.toLowerCase())));
   }
 
-  public Rule getRule(String symbol, Stack stack) {
+    /**
+     * Create rule from applying operator to stack.
+     * @param symbol symbol
+     * @param stack stack
+     * @return new instance
+     */
+  public Rule getRule(final String symbol, final Stack stack) {
     if (AND_RULE.equals(symbol)) {
       return AndRule.getRule(stack);
     }
@@ -103,20 +169,25 @@
       return PartialTextMatchRule.getRule(stack);
     }
 
-    //in order to avoid compile-time dependency on LikeRule, call getRule(stack) using reflection 
-    if (rules.contains(LIKE_RULE) && LIKE_RULE.equalsIgnoreCase(symbol)) {
+    //in order to avoid compile-time dependency on LikeRule,
+        // call getRule(stack) using reflection
+    if (RULES.contains(LIKE_RULE) && LIKE_RULE.equalsIgnoreCase(symbol)) {
       String methodName = "getRule";
       try {
         Class likeClass = Class.forName("org.apache.log4j.rule.LikeRule");
         Method method =
           likeClass.getDeclaredMethod(methodName, new Class[]{Stack.class});
 
-        return (Rule)method.invoke(null, new Object[]{stack});
+        return (Rule) method.invoke(null, new Object[]{stack});
+      } catch (ClassNotFoundException cnfe) {
+          throw new IllegalArgumentException("Invalid rule: " + symbol);
+      } catch (NoSuchMethodException nsme) {
+          throw new IllegalArgumentException("Invalid rule: " + symbol);
+      } catch (IllegalAccessException iae) {
+          throw new IllegalArgumentException("Invalid rule: " + symbol);
+      } catch (InvocationTargetException iae) {
+          throw new IllegalArgumentException("Invalid rule: " + symbol);
       }
-      catch (ClassNotFoundException cnfe) {}
-      catch (NoSuchMethodException nsme) {}
-      catch (IllegalAccessException iae) {}
-      catch (InvocationTargetException iae) {}
     }
 
     if (EXISTS_RULE.equalsIgnoreCase(symbol)) {

Modified: logging/log4j/trunk/src/java/org/apache/log4j/rule/TimestampEqualsRule.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/rule/TimestampEqualsRule.java?view=diff&rev=527771&r1=527770&r2=527771
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/rule/TimestampEqualsRule.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/rule/TimestampEqualsRule.java Wed Apr 11 22:17:12 2007
@@ -5,9 +5,9 @@
  * 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.
@@ -27,55 +27,83 @@
 import org.apache.log4j.spi.LoggingEventFieldResolver;
 
 /**
- * A Rule class implementing inequality evaluation for Levels (log4j and util.logging) using the toInt method.
- * 
- * @author Scott Deboy <sd...@apache.org>
+ * A Rule class implementing equality evaluation for timestamps.
+ *
+ * @author Scott Deboy (sdeboy@apache.org)
  */
 public class TimestampEqualsRule extends AbstractRule {
+    /**
+     * Serialization ID.
+     */
   static final long serialVersionUID = 1639079557187790321L;
-  private static final LoggingEventFieldResolver resolver = LoggingEventFieldResolver.getInstance();
-  private static final DateFormat dateFormat = new SimpleDateFormat(Constants.TIMESTAMP_RULE_FORMAT);
+    /**
+     * Resolver.
+     */
+  private static final LoggingEventFieldResolver RESOLVER =
+          LoggingEventFieldResolver.getInstance();
+    /**
+     * Date format.
+     */
+  private static final DateFormat DATE_FORMAT =
+          new SimpleDateFormat(Constants.TIMESTAMP_RULE_FORMAT);
+
+    /**
+     * time stamp.
+     */
   private long timeStamp;
-  
-  private TimestampEqualsRule(String value) {
-  	//expects value to be a timestamp value represented as a long
+
+    /**
+     * Create new instance.
+     * @param value string representation of date.
+     */
+  private TimestampEqualsRule(final String value) {
+    super();
+    //expects value to be a timestamp value represented as a long
     try {
-    	timeStamp = dateFormat.parse(value).getTime();
+        timeStamp = DATE_FORMAT.parse(value).getTime();
     } catch (ParseException pe) {
-    	throw new IllegalArgumentException("Could not parse date: " + value);
+        throw new IllegalArgumentException("Could not parse date: " + value);
     }
-  } 
+  }
 
-  public static Rule getRule(String value) {
+    /**
+     * Create new instance.
+     * @param value string representation of date.
+     * @return new instance
+     */
+  public static Rule getRule(final String value) {
       return new TimestampEqualsRule(value);
   }
-  
-  public boolean evaluate(LoggingEvent event) {
-    long eventTimeStamp = Long.parseLong(resolver.getValue("TIMESTAMP", event).toString()) / 1000 * 1000; 
-	return eventTimeStamp == timeStamp;
+
+    /** {@inheritDoc} */
+  public boolean evaluate(final LoggingEvent event) {
+    long eventTimeStamp = Long.parseLong(
+            RESOLVER.getValue("TIMESTAMP", event).toString()) / 1000 * 1000;
+    return eventTimeStamp == timeStamp;
   }
-  
+
   /**
-    * Deserialize the state of the object
+    * Deserialize the state of the object.
     *
-    * @param in 
+    * @param in object input stream
     *
-    * @throws IOException 
-    * @throws ClassNotFoundException 
+    * @throws IOException if IO error during deserialization
+    * @throws ClassNotFoundException if class not found during
+   *   deserialization
     */
-   private void readObject(java.io.ObjectInputStream in)
+   private void readObject(final java.io.ObjectInputStream in)
      throws IOException, ClassNotFoundException {
-     timeStamp = in.readLong(); 
+     timeStamp = in.readLong();
    }
 
    /**
-    * Serialize the state of the object
+    * Serialize the state of the object.
     *
-    * @param out 
+    * @param out object output stream
     *
-    * @throws IOException 
+    * @throws IOException if IO error during serialization
     */
-   private void writeObject(java.io.ObjectOutputStream out)
+   private void writeObject(final java.io.ObjectOutputStream out)
      throws IOException {
      out.writeLong(timeStamp);
    }

Modified: logging/log4j/trunk/src/java/org/apache/log4j/rule/TimestampInequalityRule.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/rule/TimestampInequalityRule.java?view=diff&rev=527771&r1=527770&r2=527771
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/rule/TimestampInequalityRule.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/rule/TimestampInequalityRule.java Wed Apr 11 22:17:12 2007
@@ -5,9 +5,9 @@
  * 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.
@@ -27,34 +27,65 @@
 import org.apache.log4j.spi.LoggingEventFieldResolver;
 
 /**
- * A Rule class implementing inequality evaluation for Levels (log4j and util.logging) using the toInt method.
- * 
- * @author Scott Deboy <sd...@apache.org>
+ * A Rule class implementing inequality evaluation for timestamps.
+ *
+ * @author Scott Deboy (sdeboy@apache.org)
  */
 public class TimestampInequalityRule extends AbstractRule {
+    /**
+     * Serialization ID.
+     */
   static final long serialVersionUID = -4642641663914789241L;
-  private static final LoggingEventFieldResolver resolver = LoggingEventFieldResolver.getInstance();
-  private static final DateFormat dateFormat = new SimpleDateFormat(Constants.TIMESTAMP_RULE_FORMAT);
+    /**
+     * Resolver.
+     */
+  private static final LoggingEventFieldResolver RESOLVER =
+            LoggingEventFieldResolver.getInstance();
+    /**
+     * Date format.
+     */
+  private static final DateFormat DATE_FORMAT =
+          new SimpleDateFormat(Constants.TIMESTAMP_RULE_FORMAT);
+    /**
+     * Inequality symbol.
+     */
   private transient String inequalitySymbol;
+    /**
+     * Timestamp.
+     */
   private long timeStamp;
-  
-  private TimestampInequalityRule(
-    String inequalitySymbol, String value) {
 
+    /**
+     * Create new instance.
+     * @param inequalitySymbol inequality symbol.
+     * @param value string representation of date.
+     */
+  private TimestampInequalityRule(
+    final String inequalitySymbol, final String value) {
+    super();
     this.inequalitySymbol = inequalitySymbol;
     try {
-    	timeStamp = dateFormat.parse(value).getTime();
+        timeStamp = DATE_FORMAT.parse(value).getTime();
     } catch (ParseException pe) {
-    	throw new IllegalArgumentException("Could not parse date: " + value);
+        throw new IllegalArgumentException("Could not parse date: " + value);
     }
-  } 
+  }
 
-  public static Rule getRule(String inequalitySymbol, String value) {
+    /**
+     * Create new instance.
+     * @param inequalitySymbol inequality symbol
+     * @param value string representation of date
+     * @return new instance
+     */
+  public static Rule getRule(final String inequalitySymbol,
+                             final String value) {
       return new TimestampInequalityRule(inequalitySymbol, value);
   }
-  
-  public boolean evaluate(LoggingEvent event) {
-    long eventTimeStamp = Long.parseLong(resolver.getValue("TIMESTAMP", event).toString()) / 1000 * 1000; 
+
+    /** {@inheritDoc} */
+  public boolean evaluate(final LoggingEvent event) {
+    long eventTimeStamp = Long.parseLong(
+            RESOLVER.getValue("TIMESTAMP", event).toString()) / 1000 * 1000;
     boolean result = false;
     long first = eventTimeStamp;
     long second = timeStamp;
@@ -71,29 +102,29 @@
 
     return result;
   }
-  
+
   /**
-    * Deserialize the state of the object
+    * Deserialize the state of the object.
     *
-    * @param in 
+    * @param in object input stream
     *
-    * @throws IOException 
-    * @throws ClassNotFoundException 
+    * @throws IOException if IO error during deserialization
+    * @throws ClassNotFoundException if class not found
     */
-   private void readObject(java.io.ObjectInputStream in)
+   private void readObject(final java.io.ObjectInputStream in)
      throws IOException, ClassNotFoundException {
-     inequalitySymbol = (String)in.readObject();
-     timeStamp = in.readLong(); 
+     inequalitySymbol = (String) in.readObject();
+     timeStamp = in.readLong();
    }
 
    /**
-    * Serialize the state of the object
+    * Serialize the state of the object.
     *
-    * @param out 
+    * @param out object output stream
     *
-    * @throws IOException 
+    * @throws IOException if IO error during serialization
     */
-   private void writeObject(java.io.ObjectOutputStream out)
+   private void writeObject(final java.io.ObjectOutputStream out)
      throws IOException {
      out.writeObject(inequalitySymbol);
      out.writeLong(timeStamp);

Modified: logging/log4j/trunk/src/java/org/apache/log4j/spi/LoggingEventFieldResolver.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/java/org/apache/log4j/spi/LoggingEventFieldResolver.java?view=diff&rev=527771&r1=527770&r2=527771
==============================================================================
--- logging/log4j/trunk/src/java/org/apache/log4j/spi/LoggingEventFieldResolver.java (original)
+++ logging/log4j/trunk/src/java/org/apache/log4j/spi/LoggingEventFieldResolver.java Wed Apr 11 22:17:12 2007
@@ -5,9 +5,9 @@
  * 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.
@@ -21,115 +21,189 @@
 import java.util.List;
 import java.util.StringTokenizer;
 
-import org.apache.log4j.spi.LocationInfo;
-
 
 
 /**
- * A singleton helper utility which accepts a field name and a LoggingEvent and returns the
+ * A singleton helper utility which accepts a field name
+ * and a LoggingEvent and returns the
  * String value of that field.
  *
  * This class defines a grammar used in creation of an expression-based Rule.
  *
- * The only available method is Object getField(String fieldName, LoggingEvent event).
+ * The only available method is
+ * Object getField(String fieldName, LoggingEvent event).
  *
  * Here is a description of the mapping of field names in the grammar
- * to fields on the logging event.  While the getField method returns an Object, the
- * individual types returned per field are described here:
+ * to fields on the logging event.  While the getField method returns an Object,
+ * the individual types returned per field are described here:
  *
- * Field Name                Field value (String representation                Return type
- * LOGGER                    category name (logger)                            String
- * LEVEL                     level                                             Level
- * CLASS                     locationInformation's class name                  String
- * FILE                      locationInformation's file name                   String
- * LINE                      locationInformation's line number                 String
- * METHOD                    locationInformation's method name                 String
- * MSG                       message                                           Object
- * NDC                       NDC                                               String
- * EXCEPTION                 throwable string representation                   ThrowableInformation
- * TIMESTAMP                 timestamp                                         Long
- * THREAD                    thread                                            String
- * PROP.keyName              entry in the Property hashtable                   String
- *                           mapped to the key [keyName]
+ * Field Name    Field value (String representation        Return type
+ * LOGGER        category name (logger)                    String
+ * LEVEL         level                                     Level
+ * CLASS         locationInformation's class name          String
+ * FILE          locationInformation's file name           String
+ * LINE          locationInformation's line number         String
+ * METHOD        locationInformation's method name         String
+ * MSG           message                                   Object
+ * NDC           NDC                                       String
+ * EXCEPTION     throwable string representation           ThrowableInformation
+ * TIMESTAMP     timestamp                                 Long
+ * THREAD        thread                                    String
+ * PROP.keyName  entry in the Property hashtable           String
+ *               mapped to the key [keyName]
 
  * NOTE:  the values for the 'keyName' portion of the MDC and PROP mappings must
  * be an exact match to the key in the hashTable (case sensitive).
  *
- * If the passed-in field is null or doesn't match an entry in the above-described
- * mapping, an exception is thrown.
+ * If the passed-in field is null or doesn't match an entry
+ * in the above-described mapping, an exception is thrown.
  *
- * @author Scott Deboy <sd...@apache.org>
- * @author Paul Smith <ps...@apache.org>
+ * @author Scott Deboy (sdeboy@apache.org)
+ * @author Paul Smith (psmith@apache.org)
  *
  */
 public final class LoggingEventFieldResolver {
-  public static final List keywordList = new ArrayList();
+    /**
+     * Keyword list.
+     */
+  public static final List KEYWORD_LIST = new ArrayList();
+    /**
+     * LOGGER string literal.
+     */
   public static final String LOGGER_FIELD = "LOGGER";
+    /**
+     * LEVEL string literal.
+     */
   public static final String LEVEL_FIELD = "LEVEL";
+    /**
+     * CLASS string literal.
+     */
   public static final String CLASS_FIELD = "CLASS";
+    /**
+     * FILE string literal.
+     */
   public static final String FILE_FIELD = "FILE";
+    /**
+     * LINE string literal.
+     */
   public static final String LINE_FIELD = "LINE";
+    /**
+     * METHOD string literal.
+     */
   public static final String METHOD_FIELD = "METHOD";
+    /**
+     * MSG string literal.
+     */
   public static final String MSG_FIELD = "MSG";
+    /**
+     * NDC string literal.
+     */
   public static final String NDC_FIELD = "NDC";
+    /**
+     * EXCEPTION string literal.
+     */
   public static final String EXCEPTION_FIELD = "EXCEPTION";
+    /**
+     * TIMESTAMP string literal.
+     */
   public static final String TIMESTAMP_FIELD = "TIMESTAMP";
+    /**
+     * THREAD string literal.
+     */
   public static final String THREAD_FIELD = "THREAD";
+    /**
+     * PROP. string literal.
+     */
   public static final String PROP_FIELD = "PROP.";
+    /**
+     * empty string literal.
+     */
   public static final String EMPTY_STRING = "";
-  private static final LoggingEventFieldResolver resolver =
+    /**
+     * LOGGER string literal.
+     */
+  private static final LoggingEventFieldResolver RESOLVER =
     new LoggingEventFieldResolver();
 
+    /**
+     * Create new instance.
+     */
   private LoggingEventFieldResolver() {
-    keywordList.add(LOGGER_FIELD);
-    keywordList.add(LEVEL_FIELD);
-    keywordList.add(CLASS_FIELD);
-    keywordList.add(FILE_FIELD);
-    keywordList.add(LINE_FIELD);
-    keywordList.add(METHOD_FIELD);
-    keywordList.add(MSG_FIELD);
-    keywordList.add(NDC_FIELD);
-    keywordList.add(EXCEPTION_FIELD);
-    keywordList.add(TIMESTAMP_FIELD);
-    keywordList.add(THREAD_FIELD);
-    keywordList.add(PROP_FIELD);
+    super();
+    KEYWORD_LIST.add(LOGGER_FIELD);
+    KEYWORD_LIST.add(LEVEL_FIELD);
+    KEYWORD_LIST.add(CLASS_FIELD);
+    KEYWORD_LIST.add(FILE_FIELD);
+    KEYWORD_LIST.add(LINE_FIELD);
+    KEYWORD_LIST.add(METHOD_FIELD);
+    KEYWORD_LIST.add(MSG_FIELD);
+    KEYWORD_LIST.add(NDC_FIELD);
+    KEYWORD_LIST.add(EXCEPTION_FIELD);
+    KEYWORD_LIST.add(TIMESTAMP_FIELD);
+    KEYWORD_LIST.add(THREAD_FIELD);
+    KEYWORD_LIST.add(PROP_FIELD);
   }
-  
-  public String applyFields(String replaceText, LoggingEvent event) {
-  	  if (replaceText == null) {
-  	  	return null;
-  	  }
+
+    /**
+     * Apply fields.
+     * @param replaceText replacement text.
+     * @param event logging event.
+     * @return evaluted expression
+     */
+  public String applyFields(final String replaceText,
+                            final LoggingEvent event) {
+      if (replaceText == null) {
+        return null;
+      }
       StringTokenizer tokenizer = new StringTokenizer(replaceText);
       StringBuffer result = new StringBuffer();
       boolean found = false;
-      
+
       while (tokenizer.hasMoreTokens()) {
           String token = tokenizer.nextToken();
           if (isField(token) || token.toUpperCase().startsWith(PROP_FIELD)) {
               result.append(getValue(token, event).toString());
               found = true;
-          } else { 
+          } else {
               result.append(token);
           }
       }
       if (found) {
-      	return result.toString();
+        return result.toString();
       }
       return null;
   }
 
+    /**
+     * Get singleton instance.
+     * @return singleton instance
+     */
   public static LoggingEventFieldResolver getInstance() {
-    return resolver;
+    return RESOLVER;
   }
 
-  public boolean isField(String fieldName) {
+    /**
+     * Determines if specified string is a recognized field.
+     * @param fieldName field name
+     * @return true if recognized field.
+     */
+  public boolean isField(final String fieldName) {
     if (fieldName != null) {
-        return (keywordList.contains(fieldName.toUpperCase()) || fieldName.toUpperCase().startsWith(PROP_FIELD));
+        return (KEYWORD_LIST.contains(
+                fieldName.toUpperCase())
+                || fieldName.toUpperCase().startsWith(PROP_FIELD));
     }
     return false;
   }
 
-  public Object getValue(String fieldName, LoggingEvent event) {
+    /**
+     * Get value of field.
+     * @param fieldName field
+     * @param event event
+     * @return value of field
+     */
+  public Object getValue(final String fieldName,
+                         final LoggingEvent event) {
     String upperField = fieldName.toUpperCase();
     LocationInfo info = null;
     if (event.locationInformationExists()) {
@@ -153,7 +227,12 @@
       String ndcValue = event.getNDC();
       return ((ndcValue == null) ? EMPTY_STRING : ndcValue);
     } else if (EXCEPTION_FIELD.equals(upperField)) {
-      return (event.getThrowableStrRep() == null ? EMPTY_STRING : getExceptionMessage(event.getThrowableStrRep()));
+        String[] throwableRep = event.getThrowableStrRep();
+        if (throwableRep == null) {
+            return EMPTY_STRING;
+        } else {
+            return getExceptionMessage(throwableRep);
+        }
     } else if (TIMESTAMP_FIELD.equals(upperField)) {
       return new Long(event.getTimeStamp());
     } else if (THREAD_FIELD.equals(upperField)) {
@@ -168,11 +247,16 @@
     throw new IllegalArgumentException("Unsupported field name: " + fieldName);
   }
 
-    private String getExceptionMessage(String[] exception) {
+    /**
+     * Get message from throwable representation.
+     * @param exception exception
+     * @return message
+     */
+    private static String getExceptionMessage(final String[] exception) {
         StringBuffer buff = new StringBuffer();
-        for (int i=0;i<exception.length;i++) {
+        for (int i = 0; i < exception.length; i++) {
             buff.append(exception[i]);
         }
-    	return buff.toString();
+        return buff.toString();
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org