View Javadoc
1   /*
2    * Copyright 2002-2012 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.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  @SuppressWarnings("serial")
32  public abstract class AbstractExpressionPointcut implements ExpressionPointcut, Serializable {
33  
34  	private String location;
35  
36  	private String expression;
37  
38  
39  	/**
40  	 * Set the location for debugging.
41  	 */
42  	public void setLocation(String location) {
43  		this.location = location;
44  	}
45  
46  	/**
47  	 * Return location information about the pointcut expression
48  	 * if available. This is useful in debugging.
49  	 * @return location information as a human-readable String,
50  	 * or {@code null} if none is available
51  	 */
52  	public String getLocation() {
53  		return this.location;
54  	}
55  
56  	public void setExpression(String expression) {
57  		this.expression = expression;
58  		try {
59  			onSetExpression(expression);
60  		}
61  		catch (IllegalArgumentException ex) {
62  			// Fill in location information if possible.
63  			if (this.location != null) {
64  				throw new IllegalArgumentException("Invalid expression at location [" + this.location + "]: " + ex);
65  			}
66  			else {
67  				throw ex;
68  			}
69  		}
70  	}
71  
72  	/**
73  	 * Called when a new pointcut expression is set.
74  	 * The expression should be parsed at this point if possible.
75  	 * <p>This implementation is empty.
76  	 * @param expression expression to set
77  	 * @throws IllegalArgumentException if the expression is invalid
78  	 * @see #setExpression
79  	 */
80  	protected void onSetExpression(String expression) throws IllegalArgumentException {
81  	}
82  
83  	/**
84  	 * Return this pointcut's expression.
85  	 */
86  	@Override
87  	public String getExpression() {
88  		return this.expression;
89  	}
90  
91  }