1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.access.boolex;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import ch.qos.logback.access.spi.IAccessEvent;
20 import ch.qos.logback.core.CoreConstants;
21 import ch.qos.logback.core.boolex.JaninoEventEvaluatorBase;
22 import ch.qos.logback.core.boolex.Matcher;
23
24 public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<IAccessEvent> {
25
26 public final static List<String> DEFAULT_PARAM_NAME_LIST = new ArrayList<String>();
27 public final static List<Class> DEFAULT_PARAM_TYPE_LIST = new ArrayList<Class>();
28
29 static {
30 DEFAULT_PARAM_NAME_LIST.add("event");
31 DEFAULT_PARAM_TYPE_LIST.add(IAccessEvent.class);
32 }
33
34
35 protected String getDecoratedExpression() {
36 String expression = getExpression();
37 if (!expression.contains("return")) {
38 expression = "return " + expression + ";";
39 addInfo("Adding [return] prefix and a semicolon suffix. Expression becomes [" + expression + "]");
40 addInfo("See also " + CoreConstants.CODES_URL + "#block");
41 }
42 return expression;
43 }
44
45 protected String[] getParameterNames() {
46 List<String> fullNameList = new ArrayList<String>();
47 fullNameList.addAll(DEFAULT_PARAM_NAME_LIST);
48
49 for (int i = 0; i < matcherList.size(); i++) {
50 Matcher m = (Matcher) matcherList.get(i);
51 fullNameList.add(m.getName());
52 }
53
54 return (String[]) fullNameList.toArray(CoreConstants.EMPTY_STRING_ARRAY);
55 }
56
57 protected Class[] getParameterTypes() {
58 List<Class> fullTypeList = new ArrayList<Class>();
59 fullTypeList.addAll(DEFAULT_PARAM_TYPE_LIST);
60 for (int i = 0; i < matcherList.size(); i++) {
61 fullTypeList.add(Matcher.class);
62 }
63 return (Class[]) fullTypeList.toArray(CoreConstants.EMPTY_CLASS_ARRAY);
64 }
65
66 protected Object[] getParameterValues(IAccessEvent accessEvent) {
67 final int matcherListSize = matcherList.size();
68
69 int i = 0;
70 Object[] values = new Object[DEFAULT_PARAM_NAME_LIST.size() + matcherListSize];
71
72 values[i++] = accessEvent;
73
74 for (int j = 0; j < matcherListSize; j++) {
75 values[i++] = matcherList.get(j);
76 }
77
78 return values;
79 }
80
81 }