ceki        2005/01/27 11:25:08

  Modified:    src/java/org/apache/log4j/lbel Token.java TokenStream.java
                        ScanError.java Node.java Operator.java Parser.java
               tests/src/java/org/apache/log4j/lbel TokenStreamTest.java
               tests    build.xml
  Added:       src/java/org/apache/log4j/lbel/comparator
                        LevelComparator.java LoggerComparator.java
                        TimestampComparator.java MessageComparator.java
                        Comparator.java
               src/java/org/apache/log4j/lbel LBELEventEvaluator.java
               tests/src/java/org/apache/log4j/lbel ScanErrorTest.java
                        EventEvaluationTest.java CoreParserTest.java
  Removed:     tests/src/java/org/apache/log4j/lbel EvaluationTest.java
  Log:
  First functional draft of LBEL
  
  Revision  Changes    Path
  1.1                  
logging-log4j/src/java/org/apache/log4j/lbel/comparator/LevelComparator.java
  
  Index: LevelComparator.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed 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.log4j.lbel.comparator;
  
  import org.apache.log4j.lbel.Operator;
  import org.apache.log4j.spi.LoggingEvent;
  
  
  /**
   * Compare the level of an event passed as parameter to the level set in the
   * constructor. 
   * 
   * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
   */
  public class LevelComparator implements Comparator {
  
    Operator operator;
    int rightLevel;
    
    /**
     * This constructor is called by the parser.
     * 
     * @param operator the comparison operator to use
     * @param level the level (in integer form) to compare to 
     */
    public LevelComparator(Operator operator, int level) {
      this.operator = operator;
      this.rightLevel = level;
    }
    
    /**
     * Compare the level event passed as parameter with the level of this 
instance
     * according to the operator of this instance.
     */
    public boolean compare(LoggingEvent event) {
      int leftLevel = event.getLevel().toInt();
      
      switch(operator.getCode()) {
      case Operator.EQUAL: return leftLevel == rightLevel;   
      case Operator.NOT_EQUAL: return leftLevel != rightLevel;   
      case Operator.GREATER: return leftLevel > rightLevel;   
      case Operator.GREATER_OR_EQUAL: return leftLevel >= rightLevel;   
      case Operator.LESS: return leftLevel < rightLevel;   
      case Operator.LESS_OR_EQUAL: return leftLevel <= rightLevel;   
      }
      throw new IllegalStateException("Unreachable state reached, operator 
"+operator);
    }
  }
  
  
  
  1.1                  
logging-log4j/src/java/org/apache/log4j/lbel/comparator/LoggerComparator.java
  
  Index: LoggerComparator.java
  ===================================================================
  /*
   * Created on Jan 27, 2005
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.log4j.lbel.comparator;
  
  import org.apache.log4j.lbel.Operator;
  import org.apache.log4j.lbel.ScanError;
  import org.apache.log4j.spi.LoggingEvent;
  import org.apache.oro.text.regex.MalformedPatternException;
  import org.apache.oro.text.regex.Pattern;
  import org.apache.oro.text.regex.Perl5Compiler;
  import org.apache.oro.text.regex.Perl5Matcher;
  
  
  /**
   * Compare the logger of an event passed as parameter to the logger name and 
   * comparison operator set in the constructor. 
   * 
   * <p>Allowed comparison operators are '=', '!=', '>', '>=', '<', '<=', '~' 
and
   * '!~' where '~' stands for regular expression match.
   * 
   * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
   * @author Scott Deboy
   */
  public class LoggerComparator implements Comparator {
  
    Operator operator;
    String rightSide;
    Pattern rightSidePattern;
    Perl5Matcher matcher;
    
    public LoggerComparator(Operator operator, String rightSide) throws 
ScanError  {
      this.operator = operator;
      this.rightSide = rightSide;
      
      
      if(operator.isRegex()) {
        Perl5Compiler compiler = new Perl5Compiler();
        matcher = new Perl5Matcher();
        try {
          rightSidePattern = compiler.compile(rightSide);
        } catch(MalformedPatternException mfpe) {
          throw new ScanError("Malformed pattern ["+rightSide+"]", mfpe);
        }
      }
      
    }
    
  
    public boolean compare(LoggingEvent event) {
      if(operator.isRegex()) {
        boolean match = matcher.matches(event.getLoggerName(), 
rightSidePattern);
        if(operator.getCode() == Operator.REGEX_MATCH) {
          return match;
        } else {
          return !match;
        }
      }
      
      int compResult = rightSide.compareTo(event.getLoggerName());
      switch(operator.getCode()) {
      case Operator.EQUAL: return compResult == 0;   
      case Operator.NOT_EQUAL: return compResult != 0;      
      case Operator.GREATER: return compResult > 0;   
      case Operator.GREATER_OR_EQUAL: return compResult >= 0;   
      case Operator.LESS: return compResult < 0;   
      case Operator.LESS_OR_EQUAL: return compResult <= 0;    
      }
      
      throw new IllegalStateException("Unreachable state reached, operator 
"+operator);
    }
  
  }
  
  
  
  1.1                  
logging-log4j/src/java/org/apache/log4j/lbel/comparator/TimestampComparator.java
  
  Index: TimestampComparator.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed 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.log4j.lbel.comparator;
  
  import org.apache.log4j.lbel.Operator;
  import org.apache.log4j.spi.LoggingEvent;
  
  
  /**
   * Compare the timestamp of 
   * 
   * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
   */
  public class TimestampComparator implements Comparator {
  
    Operator operator;
    long rightTimestamp;
    
    public TimestampComparator(Operator operator, long rightTimestamp) {
      this.operator = operator;
      this.rightTimestamp = rightTimestamp;
    
    }
    
    public boolean compare(LoggingEvent event) {
      long leftTimestamp = event.getTimeStamp();
      
      switch(operator.getCode()) {
      case Operator.EQUAL: return leftTimestamp == rightTimestamp;   
      case Operator.NOT_EQUAL: return leftTimestamp != rightTimestamp;   
      case Operator.GREATER: return leftTimestamp > rightTimestamp;   
      case Operator.GREATER_OR_EQUAL: return leftTimestamp >= rightTimestamp;   
      case Operator.LESS: return leftTimestamp < rightTimestamp;   
      case Operator.LESS_OR_EQUAL: return leftTimestamp <= rightTimestamp;   
      }
      throw new IllegalStateException("Unreachable state reached, "+operator);
    }
  }
  
  
  
  1.1                  
logging-log4j/src/java/org/apache/log4j/lbel/comparator/MessageComparator.java
  
  Index: MessageComparator.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed 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.
   */
  
  /*
   * Created on Jan 27, 2005
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.log4j.lbel.comparator;
  
  import org.apache.log4j.lbel.Operator;
  import org.apache.log4j.lbel.ScanError;
  import org.apache.log4j.spi.LoggingEvent;
  
  import org.apache.oro.text.regex.MalformedPatternException;
  import org.apache.oro.text.regex.Pattern;
  import org.apache.oro.text.regex.Perl5Compiler;
  import org.apache.oro.text.regex.Perl5Matcher;
  
  
  /**
   * Compare the message of an event passed as parameter to the logger name and
   * comparison operator set in the constructor.
   *
   * <p>Allowed comparison operators are '=', '!=', '>', '>=', '<', '<=', '~' 
and
   * '!~' where '~' stands for regular expression match.
   *
   * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
   * @author Scott Deboy
   */
  public class MessageComparator implements Comparator {
    Operator operator;
    String rightSide;
    Pattern rightSidePattern;
    Perl5Matcher matcher;
  
    public MessageComparator(Operator operator, String rightSide)
      throws ScanError {
      this.operator = operator;
      this.rightSide = rightSide;
  
      if (operator.isRegex()) {
        Perl5Compiler compiler = new Perl5Compiler();
        matcher = new Perl5Matcher();
  
        try {
          rightSidePattern = compiler.compile(rightSide);
        } catch (MalformedPatternException mfpe) {
          throw new ScanError("Malformed pattern [" + rightSide + "]", mfpe);
        }
      }
    }
  
    public boolean compare(LoggingEvent event) {
      if (operator.isRegex()) {
        boolean match =
          matcher.matches(event.getRenderedMessage(), rightSidePattern);
        if (operator.getCode() == Operator.REGEX_MATCH) {
          return match;
        } else {
          return !match;
        }
      }
  
      int compResult = rightSide.compareTo(event.getRenderedMessage());
      switch (operator.getCode()) {
      case Operator.EQUAL:
        return compResult == 0;
      case Operator.NOT_EQUAL:
        return compResult != 0;
      case Operator.GREATER:
        return compResult > 0;
      case Operator.GREATER_OR_EQUAL:
        return compResult >= 0;
      case Operator.LESS:
        return compResult < 0;
      case Operator.LESS_OR_EQUAL:
        return compResult <= 0;
      }
  
      throw new IllegalStateException(
        "Unreachable state reached, operator " + operator);
    }
  }
  
  
  
  1.1                  
logging-log4j/src/java/org/apache/log4j/lbel/comparator/Comparator.java
  
  Index: Comparator.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed 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.log4j.lbel.comparator;
  
  import org.apache.log4j.spi.LoggingEvent;
  
  
  /**
   * A Comparator instance is a node in the syntax tree returned by the parser. 
   * It compares events according to criteria proper to the comparator.
   * 
   * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
   *
   */
  public interface Comparator {
    
    public boolean compare(LoggingEvent event);
  }
  
  
  
  1.2       +46 -3     logging-log4j/src/java/org/apache/log4j/lbel/Token.java
  
  Index: Token.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/lbel/Token.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Token.java        27 Jan 2005 14:40:12 -0000      1.1
  +++ Token.java        27 Jan 2005 19:25:08 -0000      1.2
  @@ -5,6 +5,24 @@
   
        private int type;
        private Object value;
  +  public static final int TRUE = 1;
  +  public static final int FALSE = 2;
  +  public static final int OR = 10;
  +  public static final int AND = 11;
  +  public static final int NOT = 12;
  +  public static final int LITERAL = 20;
  +  public static final int NUMBER = 21;
  +  public static final int OPERATOR = 30;
  +  public static final int LP = 40;
  +  public static final int RP = 41;
  +  public static final int LOGGER = 100;
  +  public static final int MESSAGE = 110;
  +  public static final int LEVEL = 120;
  +  public static final int TIMESTAMP = 130;
  +  public static final int THREAD = 140;
  +  public static final int PROPERTY = 150;
  +  public static final int DATE = 160;
  +  public static final int EOF = 1000;
        
        public Token(int type) {
          this(type, null);
  @@ -15,9 +33,7 @@
                this.value = value;
        }
        
  -     public String toString() {
  -             return "Token("+type+", "+value+")";
  -     }
  +
        
        public int getType() {
                return type;
  @@ -26,4 +42,31 @@
        public Object getValue() {
                return value;
        }
  +  
  +  public String toString() {
  +    String typeStr = null;
  +    switch(type) {
  +
  +    case TRUE: typeStr = "TRUE"; break;
  +    case FALSE: typeStr = "FALSE"; break;
  +    case OR: typeStr = "OR"; break;
  +    case AND: typeStr = "AND"; break;
  +    case NOT: typeStr = "NOT"; break;
  +    case LITERAL: typeStr = "IDENTIFIER"; break;
  +    case NUMBER: typeStr = "NUMBER"; break;
  +    case OPERATOR: typeStr = "OPERATOR"; break;
  +    case LP: typeStr = "LP"; break;
  +    case RP: typeStr = "RP"; break;
  +    case LOGGER: typeStr = "LOGGER"; break;
  +    case MESSAGE: typeStr = "MESSAGE"; break;
  +    case LEVEL: typeStr = "LEVEL"; break;
  +    case TIMESTAMP: typeStr = "TIMESTAMP"; break;
  +    case THREAD: typeStr = "THREAD"; break;
  +    case PROPERTY: typeStr = "PROPERTY"; break;
  +    case DATE: typeStr = "DATE"; break;
  +    case EOF: typeStr = "EOF"; break;
  +    default:  typeStr = "UNKNOWN";
  +    }
  +    return "Token("+typeStr +", " + value+")";
  +  }
   }
  
  
  
  1.2       +32 -39    
logging-log4j/src/java/org/apache/log4j/lbel/TokenStream.java
  
  Index: TokenStream.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/lbel/TokenStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TokenStream.java  27 Jan 2005 14:40:12 -0000      1.1
  +++ TokenStream.java  27 Jan 2005 19:25:08 -0000      1.2
  @@ -25,32 +25,25 @@
   
   
   public class TokenStream  {
  -     public static final int TRUE = 1;
  -     public static final int FALSE = 2;
        
  -     public static final int OR = 10;
  -  public static final int AND = 11;
  -  public static final int NOT = 12;
  -
  -  public static final int IDENTIFIER = 20;
  -  public static final int NUMBER = 21;
  -
  -  public static final int OPERATOR = 30;
  -  
  -  public static final int LP = 40;
  -  public static final int RP = 41;
  -  public static final int EOF = 100;
  -
  -  static Map keywordMap = new HashMap();
  +  // keywordMap contains a map of keywords
  +  // key = keyword string
  +  // value = token corresponding to the keyword
  +  private static Map keywordMap = new HashMap();
     
     static {
  -     keywordMap.put("true", new Token(TRUE));
  -     keywordMap.put("false", new Token(FALSE));
  -     keywordMap.put("not", new Token(NOT));
  -     keywordMap.put("and", new Token(AND));
  -     keywordMap.put("or", new Token(OR));
  -     keywordMap.put("childof", new Token(OPERATOR, "childof"));
  -     
  +     keywordMap.put("true", new Token(Token.TRUE));
  +     keywordMap.put("false", new Token(Token.FALSE));
  +     keywordMap.put("not", new Token(Token.NOT));
  +     keywordMap.put("and", new Token(Token.AND));
  +     keywordMap.put("or", new Token(Token.OR));
  +     keywordMap.put("childof", new Token(Token.OPERATOR, "childof"));
  +    keywordMap.put("logger", new Token(Token.LOGGER, "logger"));
  +    keywordMap.put("message", new Token(Token.MESSAGE, "message"));
  +    keywordMap.put("level", new Token(Token.LEVEL, "level"));
  +    keywordMap.put("thread", new Token(Token.THREAD, "thread"));
  +    keywordMap.put("property", new Token(Token.PROPERTY, "property"));
  +    keywordMap.put("date", new Token(Token.DATE, "date"));
     }
     
     StreamTokenizer tokenizer;
  @@ -86,11 +79,11 @@
                token = tokenizer.nextToken();
                switch(token) {
                case    StreamTokenizer.TT_EOF:
  -                     current = new Token(EOF);
  +                     current = new Token(Token.EOF);
                        break;
                case StreamTokenizer.TT_NUMBER:
                        double nval = tokenizer.nval;
  -                 current = new Token(NUMBER, new Long((long) nval));
  +                 current = new Token(Token.NUMBER, new Long((long) nval));
                    break;
                case StreamTokenizer.TT_WORD:
                        String key = tokenizer.sval;
  @@ -98,56 +91,56 @@
                  if(result != null) {
                        current = result;
                  } else {
  -                     current = new Token(IDENTIFIER, tokenizer.sval);
  +                     current = new Token(Token.LITERAL, tokenizer.sval);
                  }
           break;               
                case '"':
          case '\'':
  -               current = new Token(IDENTIFIER, tokenizer.sval);
  +               current = new Token(Token.LITERAL, tokenizer.sval);
                  break;
                case '>':
                        token2 = tokenizer.nextToken();
                        if(token2 == '=') {
  -                       current = new Token(OPERATOR, ">=");          
  +                       current = new Token(Token.OPERATOR, ">=");            
                        } else {
  -                       current = new Token(OPERATOR, ">");
  +                       current = new Token(Token.OPERATOR, ">");
                          tokenizer.pushBack();
                        }
           break;
                case '<':
                         token2 = tokenizer.nextToken();
                        if(token2 == '=') {
  -                       current = new Token(OPERATOR, "<=");          
  +                       current = new Token(Token.OPERATOR, "<=");            
                        } else {
  -                       current = new Token(OPERATOR, "<");
  +                       current = new Token(Token.OPERATOR, "<");
                          tokenizer.pushBack();
                        }
           break;
                case '=':
  -                       current = new Token(OPERATOR, "=");           
  +                       current = new Token(Token.OPERATOR, "=");             
           break; 
                case '~':
  -                       current = new Token(OPERATOR, "~");           
  +                       current = new Token(Token.OPERATOR, "~");             
           break; 
         case '!':       
                token2 = tokenizer.nextToken();
                          if(token2 == '=') {
  -                         current = new Token(OPERATOR, "!=");                
  +                         current = new Token(Token.OPERATOR, "!=");          
                          } else if (token2 == '~') {
  -                         current = new Token(OPERATOR, "!~");
  +                         current = new Token(Token.OPERATOR, "!~");
                            tokenizer.pushBack();
                          } else {
  -                             throw new ScanError("Unrecogized token 
"+token+". The ! character must be followed by = or ~.");
  +                             throw new ScanError("Unrecogized token 
"+token+". The '!' character must be followed by = or '~'");
                          }
         break;
         case '(':
  -             current = new Token(LP);
  +             current = new Token(Token.LP);
                break;
         case ')':
  -             current = new Token(RP);
  +             current = new Token(Token.RP);
                break;
                default:
  -                     throw new ScanError("Unrecogized token "+token);
  +                     throw new ScanError("Unrecogized token 
["+(char)token+"]");
                }
                
        }
  
  
  
  1.2       +12 -0     
logging-log4j/src/java/org/apache/log4j/lbel/ScanError.java
  
  Index: ScanError.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/lbel/ScanError.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ScanError.java    27 Jan 2005 14:40:12 -0000      1.1
  +++ ScanError.java    27 Jan 2005 19:25:08 -0000      1.2
  @@ -1,7 +1,19 @@
   package org.apache.log4j.lbel;
   
   public class ScanError extends Exception {
  +  
  +  Throwable cause;
  +  
     public ScanError(String msg) {
       super(msg);
     }
  +
  +  public ScanError(String msg, Throwable rootCause) {
  +    super(msg);
  +    this.cause = rootCause;
  +  }
  +
  +  public Throwable getCause() {
  +   return cause;
  +  }
   }
  
  
  
  1.2       +3 -11     logging-log4j/src/java/org/apache/log4j/lbel/Node.java
  
  Index: Node.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/lbel/Node.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Node.java 27 Jan 2005 14:40:12 -0000      1.1
  +++ Node.java 27 Jan 2005 19:25:08 -0000      1.2
  @@ -4,13 +4,13 @@
        
        public static final int FALSE = 1;
        public static final int TRUE = 2;
  +  public static final int COMPARATOR = 3;
   
        public static final int OR = 1000;
        public static final int AND = 1100;
        public static final int NOT = 1200;
        
     Node left;
  -     //Node middle;
        Node right;
   
     final int type;
  @@ -42,16 +42,8 @@
                }
                this.left = leftSide;
        }
  -     //public Node getMiddle() {
  -             //return middle;
  -     //}
  -     //public void setMiddle(Node middle) {
  -             //if(this.middle != null) {
  -               //throw new IllegalStateException("The middle already set. 
(old="+this.middle+", new="+middle+")");
  -             //}
  -             //this.middle = middle;
  -     //}
  -     public Node getRight() {
  +
  +  public Node getRight() {
                return right;
        }
        public void setRight(Node rightSide) {
  
  
  
  1.2       +2 -0      
logging-log4j/src/java/org/apache/log4j/lbel/Operator.java
  
  Index: Operator.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/src/java/org/apache/log4j/lbel/Operator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Operator.java     27 Jan 2005 17:33:56 -0000      1.1
  +++ Operator.java     27 Jan 2005 19:25:08 -0000      1.2
  @@ -41,6 +41,8 @@
     int code;
   
     Operator(int code) {
  +    this.code = code;
  +    
       switch(code) {
       case EQUAL: 
       case NOT_EQUAL: 
  
  
  
  1.2       +85 -44    logging-log4j/src/java/org/apache/log4j/lbel/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/lbel/Parser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Parser.java       27 Jan 2005 14:40:12 -0000      1.1
  +++ Parser.java       27 Jan 2005 19:25:08 -0000      1.2
  @@ -3,6 +3,12 @@
   import java.io.IOException;
   import java.util.Stack;
   
  +import org.apache.log4j.Level;
  +import org.apache.log4j.lbel.comparator.Comparator;
  +import org.apache.log4j.lbel.comparator.LevelComparator;
  +import org.apache.log4j.lbel.comparator.LoggerComparator;
  +import org.apache.log4j.spi.LoggingEvent;
  +
   /**
    * 
   
  @@ -70,7 +76,7 @@
        Node bexpTail() throws IOException, ScanError {
       Token token = ts.getCurrent();
       switch(token.getType()) {
  -    case TokenStream.OR:
  +    case Token.OR:
        ts.next();
        Node or = new Node(Node.OR, "OR");
         
  @@ -104,7 +110,7 @@
        Node btermTail() throws IOException, ScanError {
       Token token = ts.getCurrent();
       switch(token.getType()) {
  -    case TokenStream.AND:
  +    case Token.AND:
        ts.next();
          Node and = new Node(Node.AND, "AND");
         Node bfactor = bfactor();
  @@ -124,7 +130,7 @@
        Node bfactor() throws IOException, ScanError {
       Token token = ts.getCurrent();
       switch(token.getType()) {
  -    case TokenStream.NOT:
  +    case Token.NOT:
        ts.next();
         Node result = new Node(Node.NOT, "NOT");
         Node bsubfactor = bsubfactor();
  @@ -136,59 +142,94 @@
        }
        
        Node bsubfactor() throws IOException, ScanError {
  -
  -             Node result;
       Token token = ts.getCurrent();
  +    Operator operator;
  +    String literal;
       switch(token.getType()) {
  -    case TokenStream.TRUE:
  +    case Token.TRUE:
        ts.next();
  -      result = new Node(Node.TRUE, "TRUE");
  -      break;
  -    case TokenStream.FALSE:
  +      return new Node(Node.TRUE, "TRUE");
  +    case Token.FALSE:
        ts.next();
  -      result = new Node(Node.FALSE, "FALSE");
  -      break;
  -    case   TokenStream.LP:
  +      return new Node(Node.FALSE, "FALSE");
  +    case   Token.LP:
        ts.next();
  -      result = bexp();
  +      Node result = bexp();
         Token token2 = ts.getCurrent();
  -      if(token2.getType() == TokenStream.RP) {
  +      if(token2.getType() == Token.RP) {
                ts.next();
         } else {
                throw new IllegalStateException("Expected right parantheses but 
got" +token);
         }
  -      break;
  -    default: throw new IllegalStateException("Excpected DIGIT but got" 
+token);
  +      return result;
  +    case Token.LOGGER:
  +      ts.next();
  +      operator = getOperator();
  +      ts.next();
  +      literal = getIdentifier();
  +      return new Node(Node.COMPARATOR, new LoggerComparator(operator, 
literal));
  +    case Token.LEVEL:
  +      ts.next();
  +      operator = getOperator();
  +      ts.next();
  +      int levelInt = getLevelInt();
  +      return new Node(Node.COMPARATOR, new LevelComparator(operator, 
levelInt));
  +    default: throw new IllegalStateException("Unexpected token " +token);
       }
  -    return result;
        }
  +  
  +  Operator getOperator() throws ScanError {
  +    Token token = ts.getCurrent();
  +    if(token.getType() == Token.OPERATOR) {
  +      String value = (String) token.getValue();
  +      if("=".equals(value)) {
  +        return new Operator(Operator.EQUAL);
  +      } else if("!=".equals(value)) {
  +        return new Operator(Operator.NOT_EQUAL);
  +      } else if(">".equals(value)) {
  +        return new Operator(Operator.GREATER);
  +      } else if(">=".equals(value)) {
  +        return new Operator(Operator.GREATER_OR_EQUAL);
  +      } else if("<".equals(value)) {
  +        return new Operator(Operator.LESS);
  +      } else if(">=".equals(value)) {
  +        return new Operator(Operator.LESS_OR_EQUAL);
  +      } else if("~".equals(value)) {
  +        return new Operator(Operator.REGEX_MATCH);
  +      } else if("!~".equals(value)) {
  +        return new Operator(Operator.NOT_REGEX_MATCH);
  +      } else if("childof".equals(value)) {
  +        return new Operator(Operator.CHILDOF);
  +      } else {
  +        throw new ScanError("Unknown operator type ["+value+"]");
  +      }
  +    } else {
  +      throw new ScanError("Expected operator token");
  +    }
  +  }
        
  -     public boolean evaluate(Node node) {
  -             int type = node.getType();
  -             boolean left;
  -             switch(type) {
  -             case Node.TRUE:
  -                     return true;
  -             case Node.FALSE:
  -                     return false;
  -             case Node.OR:
  -                     left = evaluate(node.getLeft());
  -               if(left == true) {
  -                     return true;
  -               } else {
  -                     return evaluate(node.getRight());
  -               }
  -             case Node.AND:
  -               left = evaluate(node.getLeft());
  -         if(left == false) {
  -               return false;
  -         } else {
  -               return evaluate(node.getRight());
  -         }
  -    case Node.NOT:
  -     return !evaluate(node.getLeft());
  -             }
  -             return false;
  -     }
  +  String getIdentifier() throws ScanError {
  +    Token token = ts.getCurrent();
  +    if(token.getType() == Token.LITERAL) {
  +      return (String) token.getValue();
  +    } else {
  +      throw new ScanError("Expected identifier token but got "+token);
  +    }
  +  }
  +  
  +  int getLevelInt() throws ScanError {
  +    String levelStr = getIdentifier();
   
  +    if("DEBUG".equalsIgnoreCase(levelStr)) {
  +      return Level.DEBUG_INT;
  +    } else if("INFO".equalsIgnoreCase(levelStr)) {
  +      return Level.INFO_INT;
  +    } else if("WARN".equalsIgnoreCase(levelStr)) {
  +      return Level.WARN_INT;
  +    } else if("ERROR".equalsIgnoreCase(levelStr)) {
  +      return Level.ERROR_INT;
  +    } else {
  +      throw new ScanError("Expected a level stirng got "+levelStr);
  +    }
  +  }
   }
  
  
  
  1.1                  
logging-log4j/src/java/org/apache/log4j/lbel/LBELEventEvaluator.java
  
  Index: LBELEventEvaluator.java
  ===================================================================
  /*
   * Created on Jan 27, 2005
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.log4j.lbel;
  
  import java.io.IOException;
  import java.io.StringReader;
  
  import org.apache.log4j.lbel.comparator.Comparator;
  import org.apache.log4j.spi.LoggingEvent;
  
  
  /**
   * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
   *
   */
  public class LBELEventEvaluator implements EventEvaluator {
  
    private Node top;
    
    LBELEventEvaluator(String expression) throws ScanError {
      StringReader sr = new StringReader(expression);
      TokenStream ts = new TokenStream(sr);
      Parser parser = new Parser(ts);
      try {
        top = parser.parse(); 
      } catch(IOException ioe) {
        throw new ScanError("Unexpeted IOException thrown", ioe);
      }
    }
  
    public boolean evaluate(LoggingEvent event) {
      return evaluate(top, event);
    }
  
    private boolean evaluate(Node node, LoggingEvent event) {
      int type = node.getType();
      boolean left;
      switch(type) {
      case Node.TRUE:
        return true;
      case Node.FALSE:
        return false;
      case Node.COMPARATOR:
        return ((Comparator) node.getValue()).compare(event);
      case Node.OR:
        left = evaluate(node.getLeft(), event);
        if(left == true) {
          return true;
        } else {
          return evaluate(node.getRight(), event);
        }
      case Node.AND:
        left = evaluate(node.getLeft(), event);
        if(left == false) {
          return false;
        } else {
          return evaluate(node.getRight(), event);
        }
      case Node.NOT:
        return !evaluate(node.getLeft(), event);
      }
      return false;
    }
    
  }
  
  
  
  1.2       +193 -161  
logging-log4j/tests/src/java/org/apache/log4j/lbel/TokenStreamTest.java
  
  Index: TokenStreamTest.java
  ===================================================================
  RCS file: 
/home/cvs/logging-log4j/tests/src/java/org/apache/log4j/lbel/TokenStreamTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TokenStreamTest.java      27 Jan 2005 14:40:12 -0000      1.1
  +++ TokenStreamTest.java      27 Jan 2005 19:25:08 -0000      1.2
  @@ -1,170 +1,202 @@
  +/*
  + * Copyright 1999,2004 The Apache Software Foundation.
  + *
  + * Licensed 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.log4j.lbel;
   
  +import junit.framework.TestCase;
  +
   import java.io.IOException;
   import java.io.StringReader;
   
  -import junit.framework.TestCase;
   
   public class TokenStreamTest extends TestCase {
  +  Token t;
  +
  +  public TokenStreamTest(String arg0) {
  +    super(arg0);
  +  }
  +
  +  protected void setUp() throws Exception {
  +    super.setUp();
  +  }
  +
  +  protected void tearDown() throws Exception {
  +    super.tearDown();
  +  }
  +
  +  public void testSingleDigit() throws IOException, ScanError {
  +    StringReader sr = new StringReader("9");
  +    TokenStream ts = new TokenStream(sr);
  +
  +    assertNull(ts.getCurrent());
  +    ts.next();
  +
  +    t = ts.getCurrent();
  +    assertEquals(Token.NUMBER, t.getType());
  +    assertEquals(9, ((Long) t.getValue()).longValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.EOF, t.getType());
  +  }
  +
  +  public void testLongerDigit() throws IOException, ScanError {
  +    StringReader sr = new StringReader(" 980 ");
  +    TokenStream ts = new TokenStream(sr);
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.NUMBER, t.getType());
  +    assertEquals(980, ((Long) t.getValue()).longValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.EOF, t.getType());
  +  }
  +
  +  public void testComparison() throws IOException, ScanError {
  +    StringReader sr = new StringReader(" time >= 17");
  +    TokenStream ts = new TokenStream(sr);
  +    ts.next();
  +    t = ts.getCurrent();
  +
  +    assertEquals(Token.LITERAL, t.getType());
  +    assertEquals("time", t.getValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.OPERATOR, t.getType());
  +    assertEquals(">=", t.getValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.NUMBER, t.getType());
  +    assertEquals(17, ((Long) t.getValue()).longValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.EOF, t.getType());
  +  }
  +
  +  public void testFull() throws IOException, ScanError {
  +    StringReader sr = new StringReader(" time >= 19 NOT \"hello world\" ");
  +    TokenStream ts = new TokenStream(sr);
  +    ts.next();
  +    t = ts.getCurrent();
  +
  +    assertEquals(Token.LITERAL, t.getType());
  +    assertEquals("time", t.getValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.OPERATOR, t.getType());
  +    assertEquals(">=", t.getValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.NUMBER, t.getType());
  +    assertEquals(19, ((Long) t.getValue()).longValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.NOT, t.getType());
   
  -     Token t;
  -     
  -     protected void setUp() throws Exception {
  -             super.setUp();
  -     }
  -
  -     protected void tearDown() throws Exception {
  -             super.tearDown();
  -     }
  -
  -     public TokenStreamTest(String arg0) {
  -             super(arg0);
  -     }
  -
  -     public void testSingleDigit() throws IOException, ScanError {
  -       StringReader sr = new StringReader("9");
  -       TokenStream ts = new TokenStream(sr);
  -
  -       assertNull(ts.getCurrent());
  -    ts.next();
  -       
  -       t = ts.getCurrent();
  -       assertEquals(TokenStream.NUMBER, t.getType());
  -       assertEquals(9, ((Long) t.getValue()).longValue());
  -       
  -       ts.next();
  -       t = ts.getCurrent();
  -       assertEquals(TokenStream.EOF, t.getType());
  -     }
  -
  -     public void testLongerDigit() throws IOException, ScanError {
  -       StringReader sr = new StringReader(" 980 ");
  -       TokenStream ts = new TokenStream(sr);
  -    ts.next();
  -       t = ts.getCurrent();
  -       assertEquals(TokenStream.NUMBER, t.getType());
  -       assertEquals(980, ((Long) t.getValue()).longValue());
  -       
  -       ts.next(); t = ts.getCurrent();
  -       assertEquals(TokenStream.EOF, t.getType());
  -     }
  -     
  -     public void testComparison() throws IOException, ScanError {
  -       StringReader sr = new StringReader(" time >= 17");
  -       TokenStream ts = new TokenStream(sr);
  -    ts.next();
  -       t = ts.getCurrent();
  -       
  -       assertEquals(TokenStream.IDENTIFIER, t.getType());
  -       assertEquals("time", t.getValue());
  -       
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.OPERATOR, t.getType());
  -       assertEquals(">=", t.getValue());
  -
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.NUMBER, t.getType());
  -       assertEquals(17, ((Long) t.getValue()).longValue());
  -                     
  -       ts.next(); t = ts.getCurrent();
  -       assertEquals(TokenStream.EOF, t.getType());
  -     }
  -     
  -     public void testFull() throws IOException, ScanError {
  -       StringReader sr = new StringReader(" time >= 19 NOT \"hello world\" 
");
  -       TokenStream ts = new TokenStream(sr);
  -    ts.next();
  -       t = ts.getCurrent();
  -       
  -       assertEquals(TokenStream.IDENTIFIER, t.getType());
  -       assertEquals("time", t.getValue());
  -       
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.OPERATOR, t.getType());
  -       assertEquals(">=", t.getValue());
  -
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.NUMBER, t.getType());
  -       assertEquals(19, ((Long) t.getValue()).longValue());
  -
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.NOT, t.getType());
  -
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.IDENTIFIER, t.getType());
  -       assertEquals("hello world", t.getValue());
  -
  -                     
  -       ts.next(); t = ts.getCurrent();
  -       assertEquals(TokenStream.EOF, t.getType());
  -     }
  -     
  -     public void testNoSpaceFull() throws IOException, ScanError {
  -       StringReader sr = new StringReader(" time>=19 NOT \"hello world\" ");
  -       TokenStream ts = new TokenStream(sr);
  -    ts.next();
  -       t = ts.getCurrent();
  -       
  -       assertEquals(TokenStream.IDENTIFIER, t.getType());
  -       assertEquals("time", t.getValue());
  -       
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.OPERATOR, t.getType());
  -       assertEquals(">=", t.getValue());
  -
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.NUMBER, t.getType());
  -       assertEquals(19, ((Long) t.getValue()).longValue());
  -
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.NOT, t.getType());
  -
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.IDENTIFIER, t.getType());
  -       assertEquals("hello world", t.getValue());
  -
  -                     
  -       ts.next(); t = ts.getCurrent();
  -       assertEquals(TokenStream.EOF, t.getType());
  -     }
  -     
  -     public void testSingleQuote() throws IOException, ScanError {
  -       StringReader sr = new StringReader(" logger ~ 'hello world' ");
  -       TokenStream ts = new TokenStream(sr);
  -    ts.next();
  -       t = ts.getCurrent();
  -       
  -       assertEquals(TokenStream.IDENTIFIER, t.getType());
  -       assertEquals("logger", t.getValue());
  -       
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.OPERATOR, t.getType());
  -       assertEquals("~", t.getValue());
  -
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.IDENTIFIER, t.getType());
  -       assertEquals("hello world", t.getValue());
  -
  -                     
  -       ts.next(); t = ts.getCurrent();
  -       assertEquals(TokenStream.EOF, t.getType());
  -     }
  -     
  -     public void testTrueOrFalse() throws IOException, ScanError {
  -       StringReader sr = new StringReader(" true OR false");
  -       TokenStream ts = new TokenStream(sr);
  -   
  -       ts.next(); t = ts.getCurrent();
  -       assertEquals(TokenStream.TRUE, t.getType());
  -       
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.OR, t.getType());
  -       
  -       ts.next();  t = ts.getCurrent();
  -       assertEquals(TokenStream.FALSE, t.getType());
  -                     
  -       ts.next(); t = ts.getCurrent();
  -       assertEquals(TokenStream.EOF, t.getType());
  -     }
  -     
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.LITERAL, t.getType());
  +    assertEquals("hello world", t.getValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.EOF, t.getType());
  +  }
  +
  +  public void testNoSpaceFull() throws IOException, ScanError {
  +    StringReader sr = new StringReader(" time>=19 NOT \"hello world\" ");
  +    TokenStream ts = new TokenStream(sr);
  +    ts.next();
  +    t = ts.getCurrent();
  +
  +    assertEquals(Token.LITERAL, t.getType());
  +    assertEquals("time", t.getValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.OPERATOR, t.getType());
  +    assertEquals(">=", t.getValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.NUMBER, t.getType());
  +    assertEquals(19, ((Long) t.getValue()).longValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.NOT, t.getType());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.LITERAL, t.getType());
  +    assertEquals("hello world", t.getValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.EOF, t.getType());
  +  }
  +
  +  public void testSingleQuote() throws IOException, ScanError {
  +    StringReader sr = new StringReader(" logger ~ 'hello world' ");
  +    TokenStream ts = new TokenStream(sr);
  +    ts.next();
  +    t = ts.getCurrent();
  +
  +    assertEquals(Token.LOGGER, t.getType());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.OPERATOR, t.getType());
  +    assertEquals("~", t.getValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.LITERAL, t.getType());
  +    assertEquals("hello world", t.getValue());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.EOF, t.getType());
  +  }
  +
  +  public void testTrueOrFalse() throws IOException, ScanError {
  +    StringReader sr = new StringReader(" true OR false");
  +    TokenStream ts = new TokenStream(sr);
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.TRUE, t.getType());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.OR, t.getType());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.FALSE, t.getType());
  +
  +    ts.next();
  +    t = ts.getCurrent();
  +    assertEquals(Token.EOF, t.getType());
  +  }
   }
  
  
  
  1.1                  
logging-log4j/tests/src/java/org/apache/log4j/lbel/ScanErrorTest.java
  
  Index: ScanErrorTest.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed 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.log4j.lbel;
  
  import junit.framework.TestCase;
  
  
  /**
   * 
   * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
   */
  public class ScanErrorTest extends TestCase {
  
    
    public ScanErrorTest(String arg0) {
      super(arg0);
    }
  
    protected void setUp() throws Exception {
      super.setUp();
    }
  
    protected void tearDown() throws Exception {
      super.tearDown();
    }
  }
  
  
  
  1.1                  
logging-log4j/tests/src/java/org/apache/log4j/lbel/EventEvaluationTest.java
  
  Index: EventEvaluationTest.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed 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.log4j.lbel;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.log4j.Level;
  import org.apache.log4j.spi.LoggingEvent;
  
  
  public class EventEvaluationTest extends TestCase {
        LoggingEvent event;
        EventEvaluator evaluator;
    
    public EventEvaluationTest(String arg0) {
      super(arg0);
    }
  
    protected void setUp() throws Exception {
      super.setUp();
      event = new LoggingEvent();
      event.setLevel(Level.INFO);
      event.setMessage("hello world");
      event.setLoggerName("org.wombat");
      
    }
  
    protected void tearDown() throws Exception {
      super.tearDown();
    }
  
    public void testLevel() throws ScanError {
      evaluator = new LBELEventEvaluator("level = DEBUG");
      assertTrue(!evaluator.evaluate(event));
      
      evaluator = new LBELEventEvaluator("level = INFO");
      assertTrue(evaluator.evaluate(event));
    }
     
    
    public static Test XXsuite() {
      TestSuite suite = new TestSuite();
      //suite.addTest(new ParserTest("testAndOr"));
      suite.addTest(new EventEvaluationTest("testLevel"));
      return suite;
    }
    
  }
  
  
  
  1.1                  
logging-log4j/tests/src/java/org/apache/log4j/lbel/CoreParserTest.java
  
  Index: CoreParserTest.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed 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.log4j.lbel;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import java.io.IOException;
  
  /*
   * Verify that the parser can handle the core language correctly. 
   * 
   * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
   */
  public class CoreParserTest extends TestCase {
    LBELEventEvaluator evaluator;
  
    public CoreParserTest(String arg0) {
      super(arg0);
    }
  
    protected void setUp() throws Exception {
      super.setUp();
    }
  
    protected void tearDown() throws Exception {
      super.tearDown();
    }
  
    public void testTrue() throws ScanError {
      evaluator = new LBELEventEvaluator("true");
      assertTrue(evaluator.evaluate(null));
     }
    
    public void testTrueOrFalse() throws ScanError {
      evaluator = new LBELEventEvaluator("true OR false");
      assertTrue(evaluator.evaluate(null));
    }
    
    public void testNotTrue() throws ScanError {
      evaluator = new LBELEventEvaluator("not true");
      assertTrue(!evaluator.evaluate( null));
    }
    
    public void testAndOr() throws ScanError {
      evaluator = new LBELEventEvaluator("true or false and true");
      assertTrue(evaluator.evaluate( null));
    }
  
    public void testAndOr2() throws ScanError {
      evaluator = new LBELEventEvaluator("false or false and true");
      assertTrue(!evaluator.evaluate(null));
    }
  
    public void testAndOr3() throws ScanError {
      evaluator = new LBELEventEvaluator("false or true  and true");
      assertTrue(evaluator.evaluate( null));
    }
    
    public void testParatheses() throws ScanError {
      evaluator = new LBELEventEvaluator("(true or false)");
      assertTrue(evaluator.evaluate( null));
    }
  
    public void testParatheses2() throws ScanError {
      evaluator = new LBELEventEvaluator("(not (true or false)) and true");
      assertTrue(!evaluator.evaluate( null));
    }
   
    public void testNotPrecedence() throws IOException, ScanError {
      evaluator = new LBELEventEvaluator("not true or false and true");
      assertTrue(!evaluator.evaluate( null));
    }
  
    public void testNotPrecedence2() throws IOException, ScanError {
      evaluator = new LBELEventEvaluator("not true or true and true");
      assertTrue(evaluator.evaluate( null));
    }
  
    public void testNotPrecedence3() throws IOException, ScanError {
      evaluator = new LBELEventEvaluator("not true and true or false");
      assertTrue(!evaluator.evaluate( null));
    }
    
    public void testNotPrecedence4() throws IOException, ScanError {
      evaluator = new LBELEventEvaluator("not true and true or false");
      assertTrue(!evaluator.evaluate( null));
    }
    
    
    public static Test XXsuite() {
      TestSuite suite = new TestSuite();
      //suite.addTest(new ParserTest("testAndOr"));
      suite.addTest(new CoreParserTest("testTrue"));
      return suite;
    }
    
  }
  
  
  
  1.95      +29 -8     logging-log4j/tests/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/build.xml,v
  retrieving revision 1.94
  retrieving revision 1.95
  diff -u -r1.94 -r1.95
  --- build.xml 19 Jan 2005 17:42:43 -0000      1.94
  +++ build.xml 27 Jan 2005 19:25:08 -0000      1.95
  @@ -177,6 +177,7 @@
                                         LevelOptionConverterTest,
                                                     BoundedFIFO, 
                                        Joran,
  +                                      LBEL,
                                        SimpleFilter,
                                         Scheduler, 
                                        ThrowableInformation,
  @@ -221,6 +222,11 @@
   
   
     <!-- ================================================================= -->
  +  <!-- LBEL related tests                                                -->
  +  <!-- ================================================================= -->
  +  <target name="LBEL" depends="TokenStream, CoreParser, EventEvaluation"/>
  +     
  +  <!-- ================================================================= -->
     <!-- ============== Regression and Unit Tests follow ================= --> 
 
     <!-- ================================================================= -->
     <target name="Minimum" depends="check, build, cleanOutputDir">
  @@ -417,14 +423,6 @@
        </junit>
     </target>
        
  -  <target name="ErrorHandler" depends="check, build, cleanOutputDir">
  -    <junit printsummary="yes" fork="yes" haltonfailure="yes">
  -      <classpath refid="tests.classpath"/>
  -      <formatter type="plain" usefile="false" />
  -      <test name="org.apache.log4j.varia.ErrorHandlerTestCase" />
  -    </junit>
  -  </target>
  -  
     <target name="OptionSubstitutionTest" depends="check, build, 
cleanOutputDir">
       <junit printsummary="yes" fork="yes" haltonfailure="yes">
         <classpath refid="tests.classpath"/>
  @@ -598,6 +596,29 @@
       </junit>
     </target>
   
  +  <target name="TokenStream" depends="check, build, cleanOutputDir">
  +    <junit printsummary="yes" fork="yes" haltonfailure="yes">
  +       <classpath refid="tests.classpath"/>
  +       <formatter type="plain" usefile="false" />
  +       <test name="org.apache.log4j.lbel.TokenStreamTest" />
  +     </junit>
  +  </target>  
  +     
  +  <target name="CoreParser" depends="check, build, cleanOutputDir">
  +     <junit printsummary="yes" fork="yes" haltonfailure="yes">
  +       <classpath refid="tests.classpath"/>
  +       <formatter type="plain" usefile="false" />
  +       <test name="org.apache.log4j.lbel.CoreParserTest" />
  +     </junit>
  +  </target>
  +     
  +  <target name="EventEvaluation" depends="check, build, cleanOutputDir">
  +    <junit printsummary="yes" fork="yes" haltonfailure="yes">
  +       <classpath refid="tests.classpath"/>
  +       <formatter type="plain" usefile="false" />
  +       <test name="org.apache.log4j.lbel.EventEvaluationTest" />
  +     </junit>
  +  </target>  
   
     <target name="Scheduler" depends="check, build, cleanOutputDir">
       <junit printsummary="yes" fork="yes" haltonfailure="yes">
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to