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 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  	    // (int,..) should work now.
72  	    // TODO add params like this: (..,int)
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 }