KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > interceptor > AbstractMonitoringInterceptor


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.aop.interceptor;
18
19 import org.aopalliance.intercept.MethodInvocation;
20
21 /**
22  * Base class for monitoring interceptors, such as performance monitors.
23  * Provides <code>prefix</code> and <code>suffix</code> properties
24  * that help to classify/group performance monitoring results.
25  *
26  * <p>Subclasses should call the <code>createInvocationTraceName(MethodInvocation)</code>
27  * method to create a name for the given trace that includes information about the
28  * method invocation under trace along with the prefix and suffix added as appropriate.
29  *
30  * @author Rob Harrop
31  * @author Juergen Hoeller
32  * @since 1.2.7
33  * @see #setPrefix
34  * @see #setSuffix
35  * @see #createInvocationTraceName
36  */

37 public abstract class AbstractMonitoringInterceptor extends AbstractTraceInterceptor {
38
39     private String JavaDoc prefix = "";
40
41     private String JavaDoc suffix = "";
42
43
44     /**
45      * Set the text that will get appended to the trace data.
46      */

47     public void setPrefix(String JavaDoc prefix) {
48         this.prefix = (prefix != null ? prefix : "");
49     }
50
51     /**
52      * Return the text that will get appended to the trace data.
53      */

54     protected String JavaDoc getPrefix() {
55         return prefix;
56     }
57
58     /**
59      * Set the text that will get prepended to the trace data.
60      */

61     public void setSuffix(String JavaDoc suffix) {
62         this.suffix = (suffix != null ? suffix : "");
63     }
64
65     /**
66      * Return the text that will get prepended to the trace data.
67      */

68     protected String JavaDoc getSuffix() {
69         return suffix;
70     }
71
72
73     /**
74      * Create a <code>String</code> name for the given <code>MethodInvocation</code>
75      * that can be used for trace/logging purposes. This name is made up of the
76      * configured prefix, followed by the fully-qualified name of the method being
77      * invoked, followed by the configured suffix.
78      * @see #setPrefix
79      * @see #setSuffix
80      */

81     protected String JavaDoc createInvocationTraceName(MethodInvocation invocation) {
82         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(getPrefix());
83         sb.append(invocation.getMethod().getDeclaringClass().getName());
84         sb.append('.').append(invocation.getMethod().getName());
85         sb.append(getSuffix());
86         return sb.toString();
87     }
88
89 }
90
Popular Tags