View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2008, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package ch.qos.logback.access.boolex;
11  
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  import ch.qos.logback.access.spi.AccessEvent;
16  import ch.qos.logback.core.CoreConstants;
17  import ch.qos.logback.core.boolex.JaninoEventEvaluatorBase;
18  import ch.qos.logback.core.boolex.Matcher;
19  
20  public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<AccessEvent> {
21  
22    public final static List<String> DEFAULT_PARAM_NAME_LIST = new ArrayList<String>();
23    public final static List<Class> DEFAULT_PARAM_TYPE_LIST = new ArrayList<Class>();
24    
25    static {
26      DEFAULT_PARAM_NAME_LIST.add("event");
27      DEFAULT_PARAM_TYPE_LIST.add(AccessEvent.class);
28    }
29    
30    
31    public JaninoEventEvaluator() {
32      
33    }
34    
35    protected String getDecoratedExpression() {
36      return getExpression();
37    }
38  
39    protected String[] getParameterNames() {
40      List<String> fullNameList = new ArrayList<String>();
41      fullNameList.addAll(DEFAULT_PARAM_NAME_LIST);
42  
43      for(int i = 0; i < matcherList.size(); i++) {
44        Matcher m = (Matcher) matcherList.get(i);
45        fullNameList.add(m.getName());
46      }
47      
48      return (String[]) fullNameList.toArray(CoreConstants.EMPTY_STRING_ARRAY);
49    }
50  
51    protected Class[] getParameterTypes() {
52      List<Class> fullTypeList = new ArrayList<Class>();
53      fullTypeList.addAll(DEFAULT_PARAM_TYPE_LIST);
54      for(int i = 0; i < matcherList.size(); i++) {
55        fullTypeList.add(Matcher.class);
56      }
57      return (Class[]) fullTypeList.toArray(CoreConstants.EMPTY_CLASS_ARRAY);
58    }
59  
60    protected Object[] getParameterValues(AccessEvent event) {
61      AccessEvent accessEvent = (AccessEvent) event;
62      final int matcherListSize = matcherList.size();
63      
64      int i = 0;
65      Object[] values = new Object[DEFAULT_PARAM_NAME_LIST.size()+matcherListSize];
66  
67      values[i++] = accessEvent;
68      
69      for(int j = 0; j < matcherListSize; j++) {
70        values[i++] = (Matcher) matcherList.get(j);
71      }
72      
73      return values;
74    }
75  
76  }