KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > support > AbstractExpressionPointcut


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.support;
18
19 import java.io.Serializable JavaDoc;
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 ExpressionPointcut, Serializable JavaDoc {
32
33     private String JavaDoc location;
34
35     private String JavaDoc expression;
36
37
38     /**
39      * Set the location for debugging.
40      */

41     public void setLocation(String JavaDoc 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 JavaDoc getLocation() {
52         return this.location;
53     }
54
55     public void setExpression(String JavaDoc expression) {
56         this.expression = expression;
57         try {
58             onSetExpression(expression);
59         }
60         catch (IllegalArgumentException JavaDoc ex) {
61             // Fill in location information if possible.
62
if (this.location != null) {
63                 throw new IllegalArgumentException JavaDoc("Invalid expression at location [" + this.location + "]: " + ex);
64             }
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 JavaDoc expression) throws IllegalArgumentException JavaDoc {
80     }
81
82     /**
83      * Return this pointcut's expression.
84      */

85     public String JavaDoc getExpression() {
86         return this.expression;
87     }
88
89 }
90
Popular Tags