001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.aop.support;
018
019import java.io.Serializable;
020
021/**
022 * Abstract superclass for expression pointcuts,
023 * offering location and expression properties.
024 *
025 * @author Rod Johnson
026 * @author Rob Harrop
027 * @since 2.0
028 * @see #setLocation
029 * @see #setExpression
030 */
031@SuppressWarnings("serial")
032public abstract class AbstractExpressionPointcut implements ExpressionPointcut, Serializable {
033
034        private String location;
035
036        private String expression;
037
038
039        /**
040         * Set the location for debugging.
041         */
042        public void setLocation(String location) {
043                this.location = location;
044        }
045
046        /**
047         * Return location information about the pointcut expression
048         * if available. This is useful in debugging.
049         * @return location information as a human-readable String,
050         * or {@code null} if none is available
051         */
052        public String getLocation() {
053                return this.location;
054        }
055
056        public void setExpression(String expression) {
057                this.expression = expression;
058                try {
059                        onSetExpression(expression);
060                }
061                catch (IllegalArgumentException ex) {
062                        // Fill in location information if possible.
063                        if (this.location != null) {
064                                throw new IllegalArgumentException("Invalid expression at location [" + this.location + "]: " + ex);
065                        }
066                        else {
067                                throw ex;
068                        }
069                }
070        }
071
072        /**
073         * Called when a new pointcut expression is set.
074         * The expression should be parsed at this point if possible.
075         * <p>This implementation is empty.
076         * @param expression expression to set
077         * @throws IllegalArgumentException if the expression is invalid
078         * @see #setExpression
079         */
080
081        }
082
083        /**
084         * Return this pointcut's expression.
085         */
086        @Override
087        public String getExpression() {
088                return this.expression;
089        }
090
091}