1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.filter;
22
23 import org.apache.log4j.Logger;
24
25 /***
26 * TODO Add docs
27 *
28 * Created on 05.12.2004
29 * Contributing Author(s):
30 *
31 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
32 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
33 *
34 * @author vlads
35 * @version $Revision: 1.1 $ ($Author: vlads $) $Date: 2004/12/06 02:31:41 $
36 */
37 public class PointcutParamsFilter extends MatchStringListFilter {
38
39 protected static final Logger log = Logger.getLogger(PointcutParamsFilter.class);
40
41 boolean matchAny = false;
42 PointcutParamsFilter nextParam = null;
43
44 public PointcutParamsFilter() {
45
46 }
47
48 public PointcutParamsFilter(String params) {
49 setParams(params);
50 }
51
52 public void debug() {
53 log.debug("matchAny " + matchAny);
54 log.debug("has nextParam " + (nextParam != null));
55 super.debug();
56 }
57
58 public void setParams(String params) {
59 params = params.trim();
60 if (params.equals("..")) {
61 this.matchAny = true;
62 return;
63 }
64 int idx = params.indexOf(",");
65 if (idx == -1) {
66 super.addPatterns(params);
67 return;
68 }
69
70 String firstParam = params.substring(0, idx);
71
72
73
74 super.addPatterns(firstParam);
75 this.nextParam = new PointcutParamsFilter(params.substring(idx + 1));
76 }
77
78 public int matchState(Object obj) {
79
80 if (debug) {
81 debug();
82 }
83
84
85 if (obj instanceof String) {
86 return super.matchState(obj);
87 }
88 if (!(obj instanceof String[])) {
89 return MATCH_NO;
90 }
91 if (matchAny) {
92 return MATCH_YES;
93 }
94
95 String[] params = (String[])obj;
96
97 if (params.length == 0 ) {
98 if (isEmpty()) {
99 return MATCH_YES;
100 } else {
101 return MATCH_NO;
102 }
103 }
104
105 if (!super.match(params[0])) {
106 return MATCH_NO;
107 }
108
109 if (this.nextParam == null) {
110 return MATCH_YES;
111 }
112
113 String[] nextParams = new String[params.length - 1];
114 for (int i = 1; i < params.length; i++) {
115 nextParams[i-1] = params[i];
116 }
117
118 return this.nextParam.matchState(nextParams);
119 }
120
121 }