[logback-dev] svn commit: r796 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/boolex main/java/ch/qos/logback/core/filter test/java/ch/qos/logback/core/util
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Fri Oct 27 06:22:28 CEST 2006
Author: ceki
Date: Fri Oct 27 06:22:28 2006
New Revision: 796
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java
Log:
- JaninoEvaluator stops itself after several errors
- corrected a hard to spot bug in AbstractEvaluatorFilter. It has methods like
public int getOnMatch()
public void setOnMatch(String)
public int getOnMismatch()
public void setOnMismatch(String)
The fact that the getter returned an int and the setter took a String has PropertySetter confused.
I removed the getOn*match methods which were not used anywhere.
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java Fri Oct 27 06:22:28 2006
@@ -1,7 +1,5 @@
package ch.qos.logback.core.boolex;
-
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@@ -10,29 +8,36 @@
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.LifeCycle;
-abstract public class JaninoEventEvaluatorBase extends ContextAwareBase implements
- EventEvaluator, LifeCycle {
+abstract public class JaninoEventEvaluatorBase extends ContextAwareBase
+ implements EventEvaluator, LifeCycle {
static Class EXPRESSION_TYPE = boolean.class;
static Class[] THROWN_EXCEPTIONS = new Class[1];
+ static public final int ERROR_THRESHOLD = 4;
static {
THROWN_EXCEPTIONS[0] = EvaluationException.class;
}
+
+
protected boolean start = false;
private String name;
private String expression;
ExpressionEvaluator ee;
+ private int errorCount = 0;
abstract protected String getDecoratedExpression();
+
abstract protected String[] getParameterNames();
+
abstract protected Class[] getParameterTypes();
+
abstract protected Object[] getParameterValues(Object event);
- protected List<Matcher> matcherList = new ArrayList<Matcher> ();
-
+ protected List<Matcher> matcherList = new ArrayList<Matcher>();
+
public boolean isStarted() {
return start;
}
@@ -43,23 +48,29 @@
public void start() {
try {
- ee = new ExpressionEvaluator(getDecoratedExpression(),
- EXPRESSION_TYPE, getParameterNames(), getParameterTypes(),
- THROWN_EXCEPTIONS, null);
+ ee = new ExpressionEvaluator(getDecoratedExpression(), EXPRESSION_TYPE,
+ getParameterNames(), getParameterTypes(), THROWN_EXCEPTIONS, null);
start = true;
} catch (Exception e) {
- addError("Could not start evaluator with expression [" + expression + "]", e);
+ addError(
+ "Could not start evaluator with expression [" + expression + "]", e);
}
}
- public boolean evaluate(Object event) throws NullPointerException,
- EvaluationException {
+ public boolean evaluate(Object event) throws EvaluationException {
+ if (!start) {
+ throw new IllegalStateException("Evaluator [" + name + "] was called in stopped state");
+ }
try {
Boolean result = (Boolean) ee.evaluate(getParameterValues(event));
return result.booleanValue();
- } catch (InvocationTargetException ite) {
+ } catch (Exception ex) {
+ errorCount++;
+ if (errorCount >= ERROR_THRESHOLD) {
+ start = false;
+ }
throw new EvaluationException("Evaluator [" + name
- + "] caused an exception", ite);
+ + "] caused an exception", ex);
}
}
@@ -81,11 +92,11 @@
public void setExpression(String expression) {
this.expression = expression;
}
-
+
public void addMatcher(Matcher matcher) {
matcherList.add(matcher);
}
-
+
public List getMatcherList() {
return matcherList;
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractEvalutatorFilter.java Fri Oct 27 06:22:28 2006
@@ -5,7 +5,7 @@
* This abstract class is meant to be a base for specific evaluator filters.
* </p>
* <p>
- * The value of the {@link #onMatch} and {@link #onMismatch} attributes is set to
+ * The value of the {@link #on_match} and {@link #onMismatch} attributes is set to
* {@link Filter.NEUTRAL}, so that a badly configured evaluator filter doesn't
* disturb the functionning of the chain.
* </p>
@@ -19,23 +19,22 @@
*
*/
-abstract public class AbstractEvalutatorFilter extends Filter {
+public abstract class AbstractEvalutatorFilter extends Filter {
- int onMatch = NEUTRAL;
- int onMismatch = NEUTRAL;
+ protected int on_match = NEUTRAL;
+ protected int onMismatch = NEUTRAL;
-
- public void setOnMatch(String action) {
+ final public void setOnMatch(String action) {
if ("NEUTRAL".equals(action)) {
- onMatch = NEUTRAL;
+ on_match = NEUTRAL;
} else if ("ACCEPT".equals(action)) {
- onMatch = ACCEPT;
+ on_match = ACCEPT;
} else if ("DENY".equals(action)) {
- onMatch = DENY;
+ on_match = DENY;
}
}
- public void setOnMismatch(String action) {
+ final public void setOnMismatch(String action) {
if ("NEUTRAL".equals(action)) {
onMismatch = NEUTRAL;
} else if ("ACCEPT".equals(action)) {
@@ -44,12 +43,4 @@
onMismatch = DENY;
}
}
-
- public int getOnMatch() {
- return onMatch;
- }
-
- public int getOnMistmatch() {
- return onMismatch;
- }
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java Fri Oct 27 06:22:28 2006
@@ -7,20 +7,6 @@
EventEvaluator evaluator;
- public EvaluatorFilter() {
- }
-
-
- public void setX(String action) {
- if ("NEUTRAL".equals(action)) {
- onMatch = NEUTRAL;
- } else if ("ACCEPT".equals(action)) {
- onMatch = ACCEPT;
- } else if ("DENY".equals(action)) {
- onMatch = DENY;
- }
- }
-
public void start() {
if(evaluator != null) {
super.start();
@@ -46,7 +32,7 @@
}
try {
if (evaluator.evaluate(event)) {
- return onMatch;
+ return on_match;
} else {
return onMismatch;
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PropertySetterTest.java Fri Oct 27 06:22:28 2006
@@ -46,6 +46,20 @@
}
}
+ public void testSetCamelProperty() {
+ House house = new House();
+ PropertySetter setter = new PropertySetter(house);
+
+ setter.setProperty("camelCase", "trot");
+ assertEquals("trot", house.getCamelCase());
+
+ setter.setProperty("camelCase", "gh");
+ assertEquals("gh", house.getCamelCase());
+
+ setter.setProperty("OnMatch", "raven");
+ assertEquals("raven", house.getOnMatch());
+
+ }
public void testSetComponent() {
House house = new House();
Door door = new Door();
@@ -61,6 +75,24 @@
int count;
boolean open;
String name;
+ String camelCase;
+ String onMatch;
+
+ public String getOnMatch() {
+ return onMatch;
+ }
+
+ public void setOnMatch(String onMatch) {
+ this.onMatch = onMatch;
+ }
+
+ public String getCamelCase() {
+ return camelCase;
+ }
+
+ public void setCamelCase(String camelCase) {
+ this.camelCase = camelCase;
+ }
public int getCount() {
return count;
More information about the logback-dev
mailing list