KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > filter > ExceptionMessageFilter


1 //
2
// This file is part of the prose package.
3
//
4
// The contents of this file are subject to the Mozilla Public License
5
// Version 1.1 (the "License"); you may not use this file except in
6
// compliance with the License. You may obtain a copy of the License at
7
// http://www.mozilla.org/MPL/
8
//
9
// Software distributed under the License is distributed on an "AS IS" basis,
10
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
// for the specific language governing rights and limitations under the
12
// License.
13
//
14
// The Original Code is prose.
15
//
16
// The Initial Developer of the Original Code is Andrei Popovici. Portions
17
// created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
18
// All Rights Reserved.
19
//
20
// Contributor(s):
21
package ch.ethz.prose.filter;
22 import ch.ethz.jvmai.ExceptionJoinPoint;
23 import ch.ethz.jvmai.ExceptionCatchJoinPoint;
24 import ch.ethz.jvmai.CodeJoinPoint;
25 import ch.ethz.jvmai.JoinPointKinds;
26 import ch.ethz.prose.engine.JoinPointRequest;
27 import java.lang.String JavaDoc;
28 import java.lang.Throwable JavaDoc;
29 import org.apache.regexp.RE;
30 import org.apache.regexp.RESyntaxException;
31
32
33 /**
34  * ExceptionMessageFilter class
35  *
36  * @author Angela Nicoara
37  */

38 class ExceptionMessageFilter extends PointCutter implements JoinPointKinds
39   {
40
41       protected RE re;
42       private String JavaDoc regexp;
43
44       protected ExceptionMessageFilter(String JavaDoc regexp)
45         {
46       acceptMask = MASK_EXCEPTION_THROW_ARGS_JP | MASK_EXCEPTION_CATCH_ARGS_JP;
47       mayFilterStaticallyMask = 0;
48       canFilterStaticallyMask = 0;
49       this.regexp = regexp;
50       if (regexp == null)
51       {
52         re = null;
53       }
54       else
55       {
56         try
57           {
58             re = new RE(regexp);
59           }
60             catch (RESyntaxException e)
61           {
62             throw new IllegalArgumentException JavaDoc("NameExpression: " + regexp + " is not a valid regexp." +
63                                e.toString());
64               }
65       }
66         }
67
68     protected boolean doIsSpecialRequest(JoinPointRequest jpr)
69       {
70     throw new Error JavaDoc("We cannot and may not filter static events");
71       }
72
73
74     protected boolean doIsSpecialEvent(CodeJoinPoint jpe)
75     {
76       String JavaDoc message;
77       //System.out.println("\n ExceptionMessageFilter -> doIsSpecialEvent \n"); //sters
78

79       switch (jpe.getMask() & (MASK_EXCEPTION_THROW_ARGS_JP | MASK_EXCEPTION_CATCH_ARGS_JP))
80       {
81           case MASK_EXCEPTION_THROW_ARGS_JP:
82                 //System.out.println("\n ExceptionMessageFilter -> doIsSpecialEvent -> MASK_EXCEPTION_THROW_ARGS_JP \n"); // angy test
83
message = ((ExceptionJoinPoint)jpe).getException().getMessage();
84                 break;
85           case MASK_EXCEPTION_CATCH_ARGS_JP:
86                 //System.out.println("\n ExceptionMessageFilter -> doIsSpecialEvent -> MASK_EXCEPTION_CATCH_ARGS_JP \n"); //angy test
87
message = ((ExceptionCatchJoinPoint)jpe).getException().getMessage();
88                 break;
89           default:
90                 throw new Error JavaDoc("ExceptionMessageFilter.doIsSpecialEvent: unrequested request");
91       }
92       
93       if (re == null || message == null)
94             return regexp == message ;
95       else
96             return re.match(message);
97     }
98
99
100     public String JavaDoc toString()
101     {
102       return ("Exceptions.message(\"" + regexp + "\")");
103     }
104
105   }
106
Popular Tags