View Javadoc

1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package net.sf.jour.filter;
22  
23  import net.sf.jour.log.Logger;
24  
25  /**
26   * TODO Add docs
27   * 
28   * Created on 05.12.2004 Contributing Author(s):
29   * 
30   * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital
31   * implementation) Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital
32   * implementation)
33   * 
34   * @author vlads
35   * @version $Revision: 46 $ ($Author: vlads $) $Date: 2006-11-19 16:52:09 -0500
36   *          (Sun, 19 Nov 2006) $
37   */
38  public class PointcutParamsFilter extends MatchStringListFilter {
39  
40  	protected static final Logger log = Logger.getLogger();
41  
42  	boolean matchAny = false;
43  
44  	PointcutParamsFilter nextParam = null;
45  
46  	public PointcutParamsFilter() {
47  
48  	}
49  
50  	public PointcutParamsFilter(String params) {
51  		setParams(params);
52  	}
53  
54  	public void debug() {
55  		log.debug("matchAny " + matchAny);
56  		log.debug("has nextParam " + (nextParam != null));
57  		super.debug();
58  	}
59  
60  	public void setParams(String params) {
61  		params = params.trim();
62  		if (params.equals("..")) {
63  			this.matchAny = true;
64  			return;
65  		}
66  		int idx = params.indexOf(",");
67  		if (idx == -1) {
68  			super.addPatterns(params);
69  			return;
70  		}
71  
72  		String firstParam = params.substring(0, idx);
73  		// (int,..) should work now.
74  		// TODO add params like this: (..,int)
75  
76  		super.addPatterns(firstParam);
77  		this.nextParam = new PointcutParamsFilter(params.substring(idx + 1));
78  	}
79  
80  	public int matchState(Object obj) {
81  
82  		if (debug) {
83  			debug();
84  		}
85  
86  		if (obj instanceof String) {
87  			return super.matchState(obj);
88  		}
89  		if (!(obj instanceof String[])) {
90  			return MATCH_NO;
91  		}
92  		if (matchAny) {
93  			return MATCH_YES;
94  		}
95  
96  		String[] params = (String[]) obj;
97  
98  		if (params.length == 0) {
99  			if (isEmpty()) {
100 				return MATCH_YES;
101 			} else {
102 				return MATCH_NO;
103 			}
104 		}
105 
106 		if (!super.match(params[0])) {
107 			return MATCH_NO;
108 		}
109 
110 		if (this.nextParam == null) {
111 			return MATCH_YES;
112 		}
113 
114 		String[] nextParams = new String[params.length - 1];
115 		for (int i = 1; i < params.length; i++) {
116 			nextParams[i - 1] = params[i];
117 		}
118 
119 		return this.nextParam.matchState(nextParams);
120 	}
121 
122 }