01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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
38: AbstractTraceInterceptor {
39:
40: private String prefix = "";
41:
42: private String suffix = "";
43:
44: /**
45: * Set the text that will get appended to the trace data.
46: */
47: public void setPrefix(String 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 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 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 getSuffix() {
69: return suffix;
70: }
71:
72: /**
73: * Create a <code>String</code> name for the given <code>MethodInvocation</code>
74: * that can be used for trace/logging purposes. This name is made up of the
75: * configured prefix, followed by the fully-qualified name of the method being
76: * invoked, followed by the configured suffix.
77: * @see #setPrefix
78: * @see #setSuffix
79: */
80: protected String createInvocationTraceName(
81: MethodInvocation invocation) {
82: StringBuffer sb = new StringBuffer(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: }
|