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.support;
18:
19: import java.io.Serializable;
20:
21: /**
22: * Abstract superclass for expression pointcuts,
23: * offering location and expression properties.
24: *
25: * @author Rod Johnson
26: * @author Rob Harrop
27: * @since 2.0
28: * @see #setLocation
29: * @see #setExpression
30: */
31: public abstract class AbstractExpressionPointcut implements
32: ExpressionPointcut, Serializable {
33:
34: private String location;
35:
36: private String expression;
37:
38: /**
39: * Set the location for debugging.
40: */
41: public void setLocation(String location) {
42: this .location = location;
43: }
44:
45: /**
46: * Return location information about the pointcut expression
47: * if available. This is useful in debugging.
48: * @return location information as a human-readable String,
49: * or <code>null</code> if none is available
50: */
51: public String getLocation() {
52: return this .location;
53: }
54:
55: public void setExpression(String expression) {
56: this .expression = expression;
57: try {
58: onSetExpression(expression);
59: } catch (IllegalArgumentException ex) {
60: // Fill in location information if possible.
61: if (this .location != null) {
62: throw new IllegalArgumentException(
63: "Invalid expression at location ["
64: + this .location + "]: " + ex);
65: } else {
66: throw ex;
67: }
68: }
69: }
70:
71: /**
72: * Called when a new pointcut expression is set.
73: * The expression should be parsed at this point if possible.
74: * <p>This implementation is empty.
75: * @param expression expression to set
76: * @throws IllegalArgumentException if the expression is invalid
77: * @see #setExpression
78: */
79: protected void onSetExpression(String expression)
80: throws IllegalArgumentException {
81: }
82:
83: /**
84: * Return this pointcut's expression.
85: */
86: public String getExpression() {
87: return this.expression;
88: }
89:
90: }
|