sdeboy 2003/10/27 00:22:15 Modified: src/java/org/apache/log4j/chainsaw/rule NotEqualsRule.java ExpressionRule.java LevelInequalityRule.java NotRule.java OrRule.java AndRule.java InequalityRule.java EqualsRule.java LikeRule.java InFixToPostFix.java PartialTextMatchRule.java src/java/org/apache/log4j/chainsaw LoggingEventFieldResolver.java Log: Modified rules to make them accessible outside package, modified field resolver to throw runtime exception if an invalid field was requested. Revision Changes Path 1.2 +2 -5 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/NotEqualsRule.java Index: NotEqualsRule.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/NotEqualsRule.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NotEqualsRule.java 23 Oct 2003 09:18:12 -0000 1.1 +++ NotEqualsRule.java 27 Oct 2003 08:22:15 -0000 1.2 @@ -55,7 +55,7 @@ import java.util.Stack; /** - * A Rule class implementing not equals against two strings (case sensitive). + * A Rule class implementing not equals against two strings. * * @author Scott Deboy <[EMAIL PROTECTED]> */ @@ -69,20 +69,17 @@ this.secondParam = secondParam; } - static Rule getRule(Stack stack) { + public static Rule getRule(Stack stack) { String p1 = stack.pop().toString(); String p2 = stack.pop().toString(); - System.out.println("get not equals op " + p1 + ".." + p2); return new NotEqualsRule(p1, p2); } public boolean evaluate(LoggingEvent event) { String p2 = resolver.getValue(secondParam, event).toString(); - System.out.println("not equals op " + firstParam + ".." + p2); boolean result = ((p2 != null) && !(p2.equals(firstParam))); - System.out.println("result is " + result); return result; } 1.4 +13 -8 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/ExpressionRule.java Index: ExpressionRule.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/ExpressionRule.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ExpressionRule.java 24 Oct 2003 08:04:03 -0000 1.3 +++ ExpressionRule.java 27 Oct 2003 08:22:15 -0000 1.4 @@ -59,8 +59,13 @@ * A Rule class supporting both infix and postfix expressions, accepting any rule which * is supported by the <code>RuleFactory</code>. * - * NOTE: parsing is supported through the use of <code>StringTokenizer</code>, which means - * all tokens in the expression must be separated by spaces. + * NOTE: parsing is supported through the use of <code>StringTokenizer</code>, which + * implies two limitations: + * 1: all tokens in the expression must be separated by spaces, + * 2: operands which contain spaces in the value being evaluated are not supported + * (for example, attempting to perform 'msg == some other msg' will fail, since 'some other msg' + * will be parsed as individual tokens in the expression instead of a single token (this is + * the next planned fix). * * @author Scott Deboy <[EMAIL PROTECTED]> */ @@ -76,7 +81,7 @@ this.rule = rule; } - static Rule getRule(String expression, boolean isPostFix) { + public static Rule getRule(String expression, boolean isPostFix) { if (!isPostFix) { expression = convertor.convert(expression); } @@ -97,7 +102,6 @@ class PostFixExpressionCompiler { Rule compileExpression(String expression) { - System.out.println("compiling expression: " + expression); Stack stack = new Stack(); Enumeration tokenizer = new StringTokenizer(expression); @@ -109,16 +113,17 @@ //if a symbol is found, pop 2 off the stack, evaluate and push the result if (RuleFactory.isRule(nextToken)) { Rule r = (Rule) RuleFactory.getRule(nextToken, stack); - System.out.println("pushing rule " + r); stack.push(r); } else { - System.out.println("pushing token " + nextToken); //variables or constants are pushed onto the stack stack.push(nextToken); } } - - return (Rule)stack.pop(); + if (!(stack.peek() instanceof Rule)) { + throw new RuntimeException("invalid expression: " + expression); + } else { + return (Rule)stack.pop(); + } } } 1.3 +1 -4 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/LevelInequalityRule.java Index: LevelInequalityRule.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/LevelInequalityRule.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- LevelInequalityRule.java 25 Oct 2003 07:52:55 -0000 1.2 +++ LevelInequalityRule.java 27 Oct 2003 08:22:15 -0000 1.3 @@ -97,7 +97,7 @@ this.levelSecondParam = levelSecondParam; } - static Rule getRule(String inequalitySymbol, Stack stack) { + public static Rule getRule(String inequalitySymbol, Stack stack) { String p1 = stack.pop().toString(); String p2 = stack.pop().toString(); @@ -109,7 +109,6 @@ Level level2 = levelFirstParam.toLevel( resolver.getValue(levelSecondParam, event).toString()); - System.out.println("lessthan level op " + levelFirstParam + ".." + level2); boolean result = false; int first = level2.toInt(); @@ -124,8 +123,6 @@ } else if (">=".equals(inequalitySymbol)) { result = first >= second; } - - System.out.println("result is " + result); return result; } 1.2 +1 -4 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/NotRule.java Index: NotRule.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/NotRule.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NotRule.java 23 Oct 2003 09:18:12 -0000 1.1 +++ NotRule.java 27 Oct 2003 08:22:15 -0000 1.2 @@ -65,18 +65,15 @@ this.firstParam = firstParam; } - static Rule getRule(Stack stack) { + public static Rule getRule(Stack stack) { Rule p1 = (Rule) stack.pop(); - System.out.println("get not op " + p1); return new NotRule(p1); } public boolean evaluate(LoggingEvent event) { - System.out.println("not op " + firstParam + ".." + firstParam); boolean result = !(firstParam.evaluate(event)); - System.out.println("result is " + result); return result; } 1.2 +1 -4 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/OrRule.java Index: OrRule.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/OrRule.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- OrRule.java 24 Oct 2003 04:05:23 -0000 1.1 +++ OrRule.java 27 Oct 2003 08:22:15 -0000 1.2 @@ -67,20 +67,17 @@ this.secondParam = secondParam; } - static Rule getRule(Stack stack) { + public static Rule getRule(Stack stack) { Rule p1 = (Rule) stack.pop(); Rule p2 = (Rule) stack.pop(); - System.out.println("get or op " + p1 + ".." + p2); return new OrRule(p1, p2); } public boolean evaluate(LoggingEvent event) { - System.out.println("or op " + firstParam + ".." + secondParam); boolean result = (firstParam.evaluate(event) || secondParam.evaluate(event)); - System.out.println("result is " + result); return result; } 1.2 +1 -4 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/AndRule.java Index: AndRule.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/AndRule.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AndRule.java 23 Oct 2003 09:18:12 -0000 1.1 +++ AndRule.java 27 Oct 2003 08:22:15 -0000 1.2 @@ -67,20 +67,17 @@ this.secondParam = secondParam; } - static Rule getRule(Stack stack) { + public static Rule getRule(Stack stack) { Rule p1 = (Rule) stack.pop(); Rule p2 = (Rule) stack.pop(); - System.out.println("get and op " + p1 + ".." + p2); return new AndRule(p1, p2); } public boolean evaluate(LoggingEvent event) { - System.out.println("and op " + firstParam + ".." + secondParam); boolean result = (firstParam.evaluate(event) && secondParam.evaluate(event)); - System.out.println("result is " + result); return result; } 1.3 +4 -8 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/InequalityRule.java Index: InequalityRule.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/InequalityRule.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- InequalityRule.java 25 Oct 2003 07:52:55 -0000 1.2 +++ InequalityRule.java 27 Oct 2003 08:22:15 -0000 1.3 @@ -56,9 +56,9 @@ /** - * A Rule class implementing less than - expects to be able to convert two values to longs. - * If the field being evaluated can support inequality evaluation, the appropriate rule is returned. - * (For example, if the expression is Level < DEBUG, a LessThanLevelRule is returned). + * A Rule class implementing inequality evaluation - expects to be able to convert two values to longs. + * If a specific inequality evaluation class has been provided for the event field, the appropriate rule is returned. + * (For example, if the expression is Level < DEBUG, a LevelInequalityRule is returned). * * @author Scott Deboy <[EMAIL PROTECTED]> */ @@ -76,7 +76,7 @@ this.secondParam = secondParam; } - static Rule getRule(String inequalitySymbol, Stack stack) { + public static Rule getRule(String inequalitySymbol, Stack stack) { String p1 = stack.pop().toString(); String p2 = stack.pop().toString(); @@ -87,8 +87,6 @@ return LevelInequalityRule.getRule(inequalitySymbol, stack); } else { - System.out.println("get equals op " + p1 + ".." + p2); - return new InequalityRule(inequalitySymbol, p1, p2); } } @@ -122,8 +120,6 @@ } else if (">=".equals(inequalitySymbol)) { result = first >= second; } - - System.out.println("result is " + result); return result; } 1.2 +2 -5 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/EqualsRule.java Index: EqualsRule.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/EqualsRule.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- EqualsRule.java 23 Oct 2003 09:18:12 -0000 1.1 +++ EqualsRule.java 27 Oct 2003 08:22:15 -0000 1.2 @@ -55,7 +55,7 @@ import java.util.Stack; /** - * A Rule class implementing equals against two strings. (Case-sensitive). + * A Rule class which returns the result of performing equals against two strings. * * @author Scott Deboy <[EMAIL PROTECTED]> */ @@ -70,20 +70,17 @@ this.secondParam = secondParam; } - static Rule getRule(Stack stack) { + public static Rule getRule(Stack stack) { String p1 = stack.pop().toString(); String p2 = stack.pop().toString(); - System.out.println("get equals op " + p1 + ".." + p2); return new EqualsRule(p1, p2); } public boolean evaluate(LoggingEvent event) { String p2 = resolver.getValue(secondParam, event).toString(); - System.out.println("equals op " + firstParam + ".." + p2); boolean result = ((p2 != null) && p2.equals(firstParam)); - System.out.println("result is " + result); return result; } 1.2 +1 -4 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/LikeRule.java Index: LikeRule.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/LikeRule.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LikeRule.java 23 Oct 2003 09:18:12 -0000 1.1 +++ LikeRule.java 27 Oct 2003 08:22:15 -0000 1.2 @@ -75,7 +75,7 @@ this.secondParam = secondParam; } - static Rule getRule(Stack stack) { + public static Rule getRule(Stack stack) { String p1 = stack.pop().toString(); String p2 = stack.pop().toString(); Perl5Compiler compiler = new Perl5Compiler(); @@ -91,11 +91,8 @@ public boolean evaluate(LoggingEvent event) { String p2 = resolver.getValue(secondParam, event).toString(); - System.out.println(pattern + " like " + p2); boolean result = ((pattern != null) && matcher.matches(p2, pattern)); - - System.out.println("result: " + result); return result; } 1.3 +0 -5 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/InFixToPostFix.java Index: InFixToPostFix.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/InFixToPostFix.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- InFixToPostFix.java 24 Oct 2003 08:04:03 -0000 1.2 +++ InFixToPostFix.java 27 Oct 2003 08:22:15 -0000 1.3 @@ -134,9 +134,6 @@ int index2 = ((Integer) precedenceMap.get(symbol2)).intValue(); boolean precedesResult = (index1 < index2); - System.out.println( - "SYMBOL1: " + symbol1 + "SYMBOL2: " + symbol2 + " index1: " + index1 - + " index2: " + index2 + " precedesresult: " + precedesResult); return precedesResult; } @@ -149,7 +146,6 @@ while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); - System.out.println("FOUND TOKEN " + token); if ("(".equals(token)) { //recurse @@ -173,7 +169,6 @@ //otherwise, pop top element off stack and add to postfix string //in a loop until lower precedence or empty..then push token if (stack.size() > 0) { - System.out.println("OPERATOR " + token + "..stack: " + stack); String peek = stack.peek().toString(); 1.2 +1 -5 jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/PartialTextMatchRule.java Index: PartialTextMatchRule.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/rule/PartialTextMatchRule.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PartialTextMatchRule.java 23 Oct 2003 09:18:12 -0000 1.1 +++ PartialTextMatchRule.java 27 Oct 2003 08:22:15 -0000 1.2 @@ -69,23 +69,19 @@ this.secondParam = secondParam; } - static Rule getRule(Stack stack) { + public static Rule getRule(Stack stack) { String p1 = stack.pop().toString(); String p2 = stack.pop().toString(); - System.out.println("get part text match op " + p1 + ".." + p2); return new PartialTextMatchRule(p1, p2); } public boolean evaluate(LoggingEvent event) { String p2 = resolver.getValue(secondParam, event).toString(); - System.out.println( - "partial text match op " + firstParam + ".." + secondParam); boolean result = (((p2 != null) && (firstParam != null)) && (p2.toLowerCase().indexOf(firstParam.toLowerCase()) > -1)); - System.out.println("result is " + result); return result; } 1.7 +2 -2 jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoggingEventFieldResolver.java Index: LoggingEventFieldResolver.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoggingEventFieldResolver.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- LoggingEventFieldResolver.java 25 Oct 2003 07:52:55 -0000 1.6 +++ LoggingEventFieldResolver.java 27 Oct 2003 08:22:15 -0000 1.7 @@ -185,7 +185,7 @@ return ((propValue == null) ? "" : propValue); } - //there wasn't a match, so just return the passed-in name - return fieldName; + //there wasn't a match, so throw a runtime exception + throw new RuntimeException("Unsupported field name: " + fieldName); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]