Merge branch 'cleanup-master' into master
* cleanup-master: (36 commits)
Update Apache license headers for affected sources
Add @Override annotations to main sources
Update main source and target JDK compatibility
Update Apache license headers for affected sources
Ignore performance-sensitive tests by default
Introduce 'spring-build-junit' subproject
Replace EasyMock with Mockito in test sources
Add @Override annotations to test sources
Update test source and target JDK compatibility
Update -Xlint compiler warning output
Fix various compiler warnings in spring-context
Fix "unnecessary @SuppressWarnings" warnings
Fix [rawtypes] compiler warnings
Fix [dep-ann] warnings with @Deprecated
Fix [cast] compiler warnings
Fix [serial] compiler warnings
Fix [varargs] compiler warnings
Fix warnings due to unused import statements
Replace <code> with {@code} throughout Javadoc
Fix various Javadoc warnings
...
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -10,7 +10,7 @@ integration-repo
|
||||
ivy-cache
|
||||
jxl.log
|
||||
jmx.log
|
||||
spring-jdbc/derby.log
|
||||
derby.log
|
||||
spring-test/test-output/
|
||||
.gradle
|
||||
build
|
||||
@@ -19,8 +19,10 @@ build
|
||||
argfile*
|
||||
pom.xml
|
||||
|
||||
# IDEA metadata and output dirs
|
||||
# IDEA artifacts and output dirs
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
out
|
||||
test-output
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
@@ -47,17 +47,13 @@ future pull requests as well, simply so the Spring Framework team knows
|
||||
immediately that this process is complete.
|
||||
|
||||
|
||||
## Create your branch from `master`
|
||||
## Create your branch from `3.2.x`
|
||||
|
||||
At any given time, Spring Framework's `master` branch represents the version
|
||||
currently under development. For example, if 3.1.1 was the latest Spring
|
||||
Framework release, `master` represents 3.2.0 development, and the `3.1.x`
|
||||
branch represents 3.1.2 development.
|
||||
|
||||
Create your topic branch to be submitted as a pull request from `master`. The
|
||||
Spring team will consider your pull request for backporting to maintenance
|
||||
versions (e.g. 3.1.2) on a case-by-case basis; you don't need to worry about
|
||||
submitting anything for backporting.
|
||||
If your pull request addresses a bug or improvement, please create your branch
|
||||
Spring Framework's `3.2.x` branch. `master` is reserved for work on new features
|
||||
for the next major version of the framework. Rest assured that if your pull
|
||||
request is accepted and merged into `3.2.x`, these changes will also eventually
|
||||
be merged into `master`.
|
||||
|
||||
|
||||
## Use short branch names
|
||||
|
||||
102
build.gradle
102
build.gradle
@@ -16,6 +16,14 @@ configure(allprojects) {
|
||||
ext.slf4jVersion = "1.6.1"
|
||||
ext.gradleScriptDir = "${rootProject.projectDir}/gradle"
|
||||
|
||||
if (rootProject.hasProperty("VERSION_QUALIFIER")) {
|
||||
def qualifier = rootProject.getProperty("VERSION_QUALIFIER")
|
||||
if (qualifier.startsWith("SPR-")) { // topic branch, e.g. SPR-1234
|
||||
// replace 3.2.0.BUILD-SNAPSHOT for 3.2.0.SPR-1234-SNAPSHOT
|
||||
version = version.replace('BUILD', qualifier)
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: "propdeps"
|
||||
apply plugin: "java"
|
||||
apply plugin: "propdeps-eclipse"
|
||||
@@ -24,10 +32,35 @@ configure(allprojects) {
|
||||
|
||||
group = "org.springframework"
|
||||
|
||||
sourceCompatibility=1.5
|
||||
targetCompatibility=1.5
|
||||
compileJava {
|
||||
sourceCompatibility=1.6
|
||||
targetCompatibility=1.6
|
||||
}
|
||||
compileTestJava {
|
||||
sourceCompatibility=1.7
|
||||
targetCompatibility=1.7
|
||||
}
|
||||
|
||||
[compileJava, compileTestJava]*.options*.compilerArgs = ["-Xlint:none"]
|
||||
[compileJava, compileTestJava]*.options*.compilerArgs = [
|
||||
"-Xlint:serial",
|
||||
"-Xlint:varargs",
|
||||
"-Xlint:cast",
|
||||
"-Xlint:classfile",
|
||||
"-Xlint:dep-ann",
|
||||
"-Xlint:divzero",
|
||||
"-Xlint:empty",
|
||||
"-Xlint:finally",
|
||||
"-Xlint:overrides",
|
||||
"-Xlint:path",
|
||||
"-Xlint:processing",
|
||||
"-Xlint:static",
|
||||
"-Xlint:try",
|
||||
"-Xlint:-options", // intentionally disabled
|
||||
"-Xlint:-fallthrough", // intentionally disabled
|
||||
"-Xlint:-rawtypes", // TODO enable and fix warnings
|
||||
"-Xlint:-deprecation", // TODO enable and fix warnings
|
||||
"-Xlint:-unchecked" // TODO enable and fix warnings
|
||||
]
|
||||
|
||||
sourceSets.test.resources.srcDirs = ["src/test/resources", "src/test/java"]
|
||||
|
||||
@@ -41,7 +74,7 @@ configure(allprojects) {
|
||||
dependencies {
|
||||
testCompile("junit:junit:${junitVersion}")
|
||||
testCompile("org.hamcrest:hamcrest-all:1.3")
|
||||
testCompile("org.easymock:easymock:${easymockVersion}")
|
||||
testCompile("org.mockito:mockito-core:1.9.5")
|
||||
}
|
||||
|
||||
ext.javadocLinks = [
|
||||
@@ -67,7 +100,17 @@ configure(allprojects) {
|
||||
] as String[]
|
||||
}
|
||||
|
||||
configure(subprojects) { subproject ->
|
||||
configure(allprojects.findAll{it.name in ["spring", "spring-jms", "spring-orm",
|
||||
"spring-orm-hibernate4", "spring-oxm", "spring-struts", "spring-test",
|
||||
"spring-test-mvc", "spring-tx", "spring-web", "spring-webmvc",
|
||||
"spring-webmvc-portlet", "spring-webmvc-tiles3"]}) {
|
||||
dependencies {
|
||||
testCompile("org.easymock:easymock:${easymockVersion}")
|
||||
testCompile "org.easymock:easymockclassextension:${easymockVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
configure(subprojects - project(":spring-build-junit")) { subproject ->
|
||||
apply plugin: "merge"
|
||||
apply from: "${gradleScriptDir}/publish-maven.gradle"
|
||||
|
||||
@@ -116,6 +159,34 @@ configure(subprojects) { subproject ->
|
||||
}
|
||||
}
|
||||
|
||||
configure(allprojects - project(":spring-build-junit")) {
|
||||
dependencies {
|
||||
testCompile(project(":spring-build-junit"))
|
||||
}
|
||||
|
||||
eclipse.classpath.file.whenMerged { classpath ->
|
||||
classpath.entries.find{it.path == "/spring-build-junit"}.exported = false
|
||||
}
|
||||
|
||||
test.systemProperties.put("testGroups", properties.get("testGroups"))
|
||||
}
|
||||
|
||||
project("spring-build-junit") {
|
||||
description = "Build-time JUnit dependencies and utilities"
|
||||
|
||||
// NOTE: This is an internal project and is not published.
|
||||
|
||||
dependencies {
|
||||
compile("commons-logging:commons-logging:1.1.1")
|
||||
compile("junit:junit:${junitVersion}")
|
||||
compile("org.hamcrest:hamcrest-all:1.3")
|
||||
compile("org.easymock:easymock:${easymockVersion}")
|
||||
}
|
||||
|
||||
// Don't actually generate any artifacts
|
||||
configurations.archives.artifacts.clear()
|
||||
}
|
||||
|
||||
|
||||
project("spring-core") {
|
||||
description = "Spring Core"
|
||||
@@ -297,7 +368,6 @@ project("spring-tx") {
|
||||
optional("javax.resource:connector-api:1.5")
|
||||
optional("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1")
|
||||
optional("javax.ejb:ejb-api:3.0")
|
||||
testCompile "org.easymock:easymockclassextension:${easymockVersion}"
|
||||
testCompile("javax.persistence:persistence-api:1.0")
|
||||
testCompile("org.aspectj:aspectjweaver:${aspectjVersion}")
|
||||
}
|
||||
@@ -306,6 +376,14 @@ project("spring-tx") {
|
||||
project("spring-oxm") {
|
||||
description = "Spring Object/XML Marshalling"
|
||||
apply from: "oxm.gradle"
|
||||
|
||||
compileTestJava {
|
||||
// necessary to avoid java.lang.VerifyError on jibx compilation
|
||||
// see http://jira.codehaus.org/browse/JIBX-465
|
||||
sourceCompatibility=1.6
|
||||
targetCompatibility=1.6
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(project(":spring-beans"))
|
||||
compile(project(":spring-core"))
|
||||
@@ -335,10 +413,11 @@ project("spring-jms") {
|
||||
compile(project(":spring-tx"))
|
||||
optional(project(":spring-oxm"))
|
||||
compile("aopalliance:aopalliance:1.0")
|
||||
optional("org.codehaus.jackson:jackson-mapper-asl:1.4.2")
|
||||
provided("org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1")
|
||||
optional("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1")
|
||||
optional("javax.resource:connector-api:1.5")
|
||||
optional("org.codehaus.jackson:jackson-mapper-asl:1.4.2")
|
||||
optional("com.fasterxml.jackson.core:jackson-databind:2.0.1")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,6 +509,14 @@ project("spring-web") {
|
||||
|
||||
project("spring-orm") {
|
||||
description = "Spring Object/Relational Mapping"
|
||||
|
||||
compileTestJava {
|
||||
// necessary to avoid java.lang.VerifyError on toplink compilation
|
||||
// TODO: remove this block when we remove toplink
|
||||
sourceCompatibility=1.6
|
||||
targetCompatibility=1.6
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile("aopalliance:aopalliance:1.0")
|
||||
optional("org.hibernate:hibernate-core:3.3.2.GA")
|
||||
@@ -628,7 +715,6 @@ project("spring-test-mvc") {
|
||||
testCompile("javax.activation:activation:1.1")
|
||||
testCompile("javax.mail:mail:1.4")
|
||||
testCompile("javax.xml.bind:jaxb-api:2.2.6")
|
||||
testCompile("org.easymock:easymockclassextension:${easymockVersion}")
|
||||
testCompile("org.apache.tiles:tiles-request-api:1.0.1")
|
||||
testCompile("org.apache.tiles:tiles-api:3.0.1")
|
||||
testCompile("org.apache.tiles:tiles-core:3.0.1") {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
/**
|
||||
* This class is used only as a "null" argument for Javadoc when comparing
|
||||
* two API files. Javadoc has to have a package, .java or .class file as an
|
||||
* two API files. Javadoc has to have a package, .java or .class file as an
|
||||
* argument, even though JDiff doesn't use it.
|
||||
*/
|
||||
public class Null {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
The following has been tested against Intellij IDEA 11.0.1
|
||||
The following has been tested against Intellij IDEA 12.0
|
||||
|
||||
## Steps
|
||||
|
||||
_Within your locally cloned spring-framework working directory:_
|
||||
|
||||
1. Generate IDEA metadata with `./gradlew cleanIdea idea`
|
||||
1. Generate IDEA metadata with `./gradlew :spring-oxm:compileTestJava cleanIdea idea`
|
||||
2. Import into IDEA as usual
|
||||
3. Set the Project JDK as appropriate
|
||||
4. Add git support
|
||||
@@ -12,21 +12,21 @@ _Within your locally cloned spring-framework working directory:_
|
||||
|
||||
## Known issues
|
||||
|
||||
1. MockServletContext and friends will fail to compile in spring-web. To fix this, uncheck the 'export' setting for all servlet-api and tomcat-servlet-api jars. The problem is that spring-web needs Servlet 2.5, but it's picking up Servlet 3.0 from projects that it depends on.
|
||||
2. spring-context will fail to build because there's a duplicate instance of GroovyMessenger in spring-context/src/test/java/org/springframework/scripting/groovy/Messenger.groovy. The solution to this is not known. It's not a problem on Eclipse, because Eclipse doesn't automatically compile .groovy files like IDEA (apparently) does.
|
||||
|
||||
There are no other known problems at this time. Please add to this list, and if you're ambitious, consider playing with the Gradle IDEA generation DSL to fix these problems automatically, e.g.:
|
||||
|
||||
* http://gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaProject.html
|
||||
* http://gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
|
||||
* http://gradle.org/docs/current/groovydoc/org/gradle/plugins/ide/idea/model/IdeaModule.html
|
||||
1. `spring-aspects` does not compile out of the box due to references to aspect types unknown to IDEA.
|
||||
See http://youtrack.jetbrains.com/issue/IDEA-64446 for details. In the meantime, you may want to
|
||||
exclude `spring-aspects` from the overall project to avoid compilation errors.
|
||||
2. While all JUnit tests pass from the command line with Gradle, many will fail when run from IDEA.
|
||||
Resolving this is a work in progress. If attempting to run all JUnit tests from within IDEA, you will
|
||||
likely need to set the following VM options to avoid out of memory errors:
|
||||
-XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m
|
||||
|
||||
## Tips
|
||||
|
||||
In any case, please do not check in your own generated .iml, .ipr, or .iws files. You'll notice these files are already intentionally in .gitignore. The same policy goes for eclipse metadata.
|
||||
In any case, please do not check in your own generated .iml, .ipr, or .iws files.
|
||||
You'll notice these files are already intentionally in .gitignore. The same policy goes for eclipse metadata.
|
||||
|
||||
## FAQ
|
||||
|
||||
Q. What about IDEA's own [Gradle support](http://confluence.jetbrains.net/display/IDEADEV/Gradle+integration)?
|
||||
|
||||
A. Unknown. Please report back if you try it and it goes well for you.
|
||||
A. Keep an eye on http://youtrack.jetbrains.com/issue/IDEA-53476
|
||||
|
||||
@@ -22,3 +22,4 @@ include "spring-web"
|
||||
include "spring-webmvc"
|
||||
include "spring-webmvc-portlet"
|
||||
include "spring-webmvc-tiles3"
|
||||
include "spring-build-junit"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,14 +18,14 @@ package org.springframework.aop;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Base interface holding AOP <b>advice</b> (action to take at a joinpoint)
|
||||
* and a filter determining the applicability of the advice (such as
|
||||
* and a filter determining the applicability of the advice (such as
|
||||
* a pointcut). <i>This interface is not for use by Spring users, but to
|
||||
* allow for commonality in support for different types of advice.</i>
|
||||
*
|
||||
* <p>Spring AOP is based around <b>around advice</b> delivered via method
|
||||
* <b>interception</b>, compliant with the AOP Alliance interception API.
|
||||
* <b>interception</b>, compliant with the AOP Alliance interception API.
|
||||
* The Advisor interface allows support for different types of advice,
|
||||
* such as <b>before</b> and <b>after</b> advice, which need not be
|
||||
* implemented using interception.
|
||||
@@ -50,7 +50,7 @@ public interface Advisor {
|
||||
* (for example, creating a mixin) or shared with all instances of
|
||||
* the advised class obtained from the same Spring bean factory.
|
||||
* <p><b>Note that this method is not currently used by the framework.</b>
|
||||
* Typical Advisor implementations always return <code>true</code>.
|
||||
* Typical Advisor implementations always return {@code true}.
|
||||
* Use singleton/prototype bean definitions or appropriate programmatic
|
||||
* proxy creation to ensure that Advisors have the correct lifecycle model.
|
||||
* @return whether this advice is associated with a particular target instance
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,7 +33,7 @@ public interface AfterReturningAdvice extends AfterAdvice {
|
||||
* @param returnValue the value returned by the method, if any
|
||||
* @param method method being invoked
|
||||
* @param args arguments to the method
|
||||
* @param target target of the method invocation. May be <code>null</code>.
|
||||
* @param target target of the method invocation. May be {@code null}.
|
||||
* @throws Throwable if this object wishes to abort the call.
|
||||
* Any exception thrown will be returned to the caller if it's
|
||||
* allowed by the method signature. Otherwise the exception
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,7 @@ import org.springframework.core.NestedRuntimeException;
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class AopInvocationException extends NestedRuntimeException {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.aop;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Subinterface of AOP Alliance Advice that allows additional interfaces
|
||||
* to be implemented by an Advice, and available via a proxy using that
|
||||
* interceptor. This is a fundamental AOP concept called <b>introduction</b>.
|
||||
@@ -37,7 +37,7 @@ import org.aopalliance.aop.Advice;
|
||||
* @see IntroductionAdvisor
|
||||
*/
|
||||
public interface DynamicIntroductionAdvice extends Advice {
|
||||
|
||||
|
||||
/**
|
||||
* Does this introduction advice implement the given interface?
|
||||
* @param intf the interface to check
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ package org.springframework.aop;
|
||||
* @see IntroductionInterceptor
|
||||
*/
|
||||
public interface IntroductionAdvisor extends Advisor, IntroductionInfo {
|
||||
|
||||
|
||||
/**
|
||||
* Return the filter determining which target classes this introduction
|
||||
* should apply to.
|
||||
@@ -39,7 +39,7 @@ public interface IntroductionAdvisor extends Advisor, IntroductionInfo {
|
||||
* @return the class filter
|
||||
*/
|
||||
ClassFilter getClassFilter();
|
||||
|
||||
|
||||
/**
|
||||
* Can the advised interfaces be implemented by the introduction advice?
|
||||
* Invoked before adding an IntroductionAdvisor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,10 +33,10 @@ public interface IntroductionAwareMethodMatcher extends MethodMatcher {
|
||||
* instead of the 2-arg {@link #matches(java.lang.reflect.Method, Class)} method
|
||||
* if the caller supports the extended IntroductionAwareMethodMatcher interface.
|
||||
* @param method the candidate method
|
||||
* @param targetClass the target class (may be <code>null</code>, in which case
|
||||
* @param targetClass the target class (may be {@code null}, in which case
|
||||
* the candidate class must be taken to be the method's declaring class)
|
||||
* @param hasIntroductions <code>true</code> if the object on whose behalf we are
|
||||
* asking is the subject on one or more introductions; <code>false</code> otherwise
|
||||
* @param hasIntroductions {@code true} if the object on whose behalf we are
|
||||
* asking is the subject on one or more introductions; {@code false} otherwise
|
||||
* @return whether or not this method matches statically
|
||||
*/
|
||||
boolean matches(Method method, Class targetClass, boolean hasIntroductions);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,7 @@ package org.springframework.aop;
|
||||
* @since 1.1.1
|
||||
*/
|
||||
public interface IntroductionInfo {
|
||||
|
||||
|
||||
/**
|
||||
* Return the additional interfaces introduced by this Advisor or Advice.
|
||||
* @return the introduced interfaces
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -28,12 +28,12 @@ import java.lang.reflect.Method;
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public interface MethodBeforeAdvice extends BeforeAdvice {
|
||||
|
||||
|
||||
/**
|
||||
* Callback before a given method is invoked.
|
||||
* @param method method being invoked
|
||||
* @param args arguments to the method
|
||||
* @param target target of the method invocation. May be <code>null</code>.
|
||||
* @param target target of the method invocation. May be {@code null}.
|
||||
* @throws Throwable if this object wishes to abort the call.
|
||||
* Any exception thrown will be returned to the caller if it's
|
||||
* allowed by the method signature. Otherwise the exception
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,15 +26,15 @@ import java.lang.reflect.Method;
|
||||
* also makes arguments for a particular call available, and any effects of running
|
||||
* previous advice applying to the joinpoint.
|
||||
*
|
||||
* <p>If an implementation returns <code>false</code> from its {@link #isRuntime()}
|
||||
* <p>If an implementation returns {@code false} from its {@link #isRuntime()}
|
||||
* method, evaluation can be performed statically, and the result will be the same
|
||||
* for all invocations of this method, whatever their arguments. This means that
|
||||
* if the {@link #isRuntime()} method returns <code>false</code>, the 3-arg
|
||||
* if the {@link #isRuntime()} method returns {@code false}, the 3-arg
|
||||
* {@link #matches(java.lang.reflect.Method, Class, Object[])} method will never be invoked.
|
||||
*
|
||||
* <p>If an implementation returns <code>true</code> from its 2-arg
|
||||
* <p>If an implementation returns {@code true} from its 2-arg
|
||||
* {@link #matches(java.lang.reflect.Method, Class)} method and its {@link #isRuntime()} method
|
||||
* returns <code>true</code>, the 3-arg {@link #matches(java.lang.reflect.Method, Class, Object[])}
|
||||
* returns {@code true}, the 3-arg {@link #matches(java.lang.reflect.Method, Class, Object[])}
|
||||
* method will be invoked <i>immediately before each potential execution of the related advice</i>,
|
||||
* to decide whether the advice should run. All previous advice, such as earlier interceptors
|
||||
* in an interceptor chain, will have run, so any state changes they have produced in
|
||||
@@ -49,11 +49,11 @@ public interface MethodMatcher {
|
||||
|
||||
/**
|
||||
* Perform static checking whether the given method matches. If this
|
||||
* returns <code>false</code> or if the {@link #isRuntime()} method
|
||||
* returns <code>false</code>, no runtime check (i.e. no.
|
||||
* returns {@code false} or if the {@link #isRuntime()} method
|
||||
* returns {@code false}, no runtime check (i.e. no.
|
||||
* {@link #matches(java.lang.reflect.Method, Class, Object[])} call) will be made.
|
||||
* @param method the candidate method
|
||||
* @param targetClass the target class (may be <code>null</code>, in which case
|
||||
* @param targetClass the target class (may be {@code null}, in which case
|
||||
* the candidate class must be taken to be the method's declaring class)
|
||||
* @return whether or not this method matches statically
|
||||
*/
|
||||
@@ -62,7 +62,7 @@ public interface MethodMatcher {
|
||||
/**
|
||||
* Is this MethodMatcher dynamic, that is, must a final call be made on the
|
||||
* {@link #matches(java.lang.reflect.Method, Class, Object[])} method at
|
||||
* runtime even if the 2-arg matches method returns <code>true</code>?
|
||||
* runtime even if the 2-arg matches method returns {@code true}?
|
||||
* <p>Can be invoked when an AOP proxy is created, and need not be invoked
|
||||
* again before each method invocation,
|
||||
* @return whether or not a runtime match via the 3-arg
|
||||
@@ -75,12 +75,12 @@ public interface MethodMatcher {
|
||||
* Check whether there a runtime (dynamic) match for this method,
|
||||
* which must have matched statically.
|
||||
* <p>This method is invoked only if the 2-arg matches method returns
|
||||
* <code>true</code> for the given method and target class, and if the
|
||||
* {@link #isRuntime()} method returns <code>true</code>. Invoked
|
||||
* {@code true} for the given method and target class, and if the
|
||||
* {@link #isRuntime()} method returns {@code true}. Invoked
|
||||
* immediately before potential running of the advice, after any
|
||||
* advice earlier in the advice chain has run.
|
||||
* @param method the candidate method
|
||||
* @param targetClass the target class (may be <code>null</code>, in which case
|
||||
* @param targetClass the target class (may be {@code null}, in which case
|
||||
* the candidate class must be taken to be the method's declaring class)
|
||||
* @param args arguments to the method
|
||||
* @return whether there's a runtime match
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,13 +34,13 @@ public interface Pointcut {
|
||||
|
||||
/**
|
||||
* Return the ClassFilter for this pointcut.
|
||||
* @return the ClassFilter (never <code>null</code>)
|
||||
* @return the ClassFilter (never {@code null})
|
||||
*/
|
||||
ClassFilter getClassFilter();
|
||||
|
||||
/**
|
||||
* Return the MethodMatcher for this pointcut.
|
||||
* @return the MethodMatcher (never <code>null</code>)
|
||||
* @return the MethodMatcher (never {@code null})
|
||||
*/
|
||||
MethodMatcher getMethodMatcher();
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,22 +40,22 @@ public interface ProxyMethodInvocation extends MethodInvocation {
|
||||
Object getProxy();
|
||||
|
||||
/**
|
||||
* Create a clone of this object. If cloning is done before <code>proceed()</code>
|
||||
* is invoked on this object, <code>proceed()</code> can be invoked once per clone
|
||||
* Create a clone of this object. If cloning is done before {@code proceed()}
|
||||
* is invoked on this object, {@code proceed()} can be invoked once per clone
|
||||
* to invoke the joinpoint (and the rest of the advice chain) more than once.
|
||||
* @return an invocable clone of this invocation.
|
||||
* <code>proceed()</code> can be called once per clone.
|
||||
* {@code proceed()} can be called once per clone.
|
||||
*/
|
||||
MethodInvocation invocableClone();
|
||||
|
||||
/**
|
||||
* Create a clone of this object. If cloning is done before <code>proceed()</code>
|
||||
* is invoked on this object, <code>proceed()</code> can be invoked once per clone
|
||||
* Create a clone of this object. If cloning is done before {@code proceed()}
|
||||
* is invoked on this object, {@code proceed()} can be invoked once per clone
|
||||
* to invoke the joinpoint (and the rest of the advice chain) more than once.
|
||||
* @param arguments the arguments that the cloned invocation is supposed to use,
|
||||
* overriding the original arguments
|
||||
* @return an invocable clone of this invocation.
|
||||
* <code>proceed()</code> can be called once per clone.
|
||||
* {@code proceed()} can be called once per clone.
|
||||
*/
|
||||
MethodInvocation invocableClone(Object[] arguments);
|
||||
|
||||
@@ -71,14 +71,14 @@ public interface ProxyMethodInvocation extends MethodInvocation {
|
||||
* <p>Such attributes are not used within the AOP framework itself. They are
|
||||
* just kept as part of the invocation object, for use in special interceptors.
|
||||
* @param key the name of the attribute
|
||||
* @param value the value of the attribute, or <code>null</code> to reset it
|
||||
* @param value the value of the attribute, or {@code null} to reset it
|
||||
*/
|
||||
void setUserAttribute(String key, Object value);
|
||||
|
||||
/**
|
||||
* Return the value of the specified user attribute.
|
||||
* @param key the name of the attribute
|
||||
* @return the value of the attribute, or <code>null</code> if not set
|
||||
* @return the value of the attribute, or {@code null} if not set
|
||||
* @see #setUserAttribute
|
||||
*/
|
||||
Object getUserAttribute(String key);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ public interface TargetClassAware {
|
||||
/**
|
||||
* Return the target class behind the implementing object
|
||||
* (typically a proxy configuration or an actual proxy).
|
||||
* @return the target Class, or <code>null</code> if not known
|
||||
* @return the target Class, or {@code null} if not known
|
||||
*/
|
||||
Class<?> getTargetClass();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*<
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,16 +17,16 @@
|
||||
package org.springframework.aop;
|
||||
|
||||
/**
|
||||
* A <code>TargetSource</code> is used to obtain the current "target" of
|
||||
* A {@code TargetSource} is used to obtain the current "target" of
|
||||
* an AOP invocation, which will be invoked via reflection if no around
|
||||
* advice chooses to end the interceptor chain itself.
|
||||
*
|
||||
* <p>If a <code>TargetSource</code> is "static", it will always return
|
||||
* <p>If a {@code TargetSource} is "static", it will always return
|
||||
* the same target, allowing optimizations in the AOP framework. Dynamic
|
||||
* target sources can support pooling, hot swapping, etc.
|
||||
*
|
||||
* <p>Application developers don't usually need to work with
|
||||
* <code>TargetSources</code> directly: this is an AOP framework interface.
|
||||
* {@code TargetSources} directly: this is an AOP framework interface.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@@ -34,11 +34,12 @@ public interface TargetSource extends TargetClassAware {
|
||||
|
||||
/**
|
||||
* Return the type of targets returned by this {@link TargetSource}.
|
||||
* <p>Can return <code>null</code>, although certain usages of a
|
||||
* <code>TargetSource</code> might just work with a predetermined
|
||||
* <p>Can return {@code null}, although certain usages of a
|
||||
* {@code TargetSource} might just work with a predetermined
|
||||
* target class.
|
||||
* @return the type of targets returned by this {@link TargetSource}
|
||||
*/
|
||||
@Override
|
||||
Class<?> getTargetClass();
|
||||
|
||||
/**
|
||||
@@ -46,7 +47,7 @@ public interface TargetSource extends TargetClassAware {
|
||||
* <p>In that case, there will be no need to invoke
|
||||
* {@link #releaseTarget(Object)}, and the AOP framework can cache
|
||||
* the return value of {@link #getTarget()}.
|
||||
* @return <code>true</code> if the target is immutable
|
||||
* @return {@code true} if the target is immutable
|
||||
* @see #getTarget
|
||||
*/
|
||||
boolean isStatic();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,24 +23,26 @@ import java.io.Serializable;
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class TrueClassFilter implements ClassFilter, Serializable {
|
||||
|
||||
|
||||
public static final TrueClassFilter INSTANCE = new TrueClassFilter();
|
||||
|
||||
|
||||
/**
|
||||
* Enforce Singleton pattern.
|
||||
*/
|
||||
private TrueClassFilter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Class clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Required to support serialization. Replaces with canonical
|
||||
* instance on deserialization, protecting Singleton pattern.
|
||||
* Alternative to overriding <code>equals()</code>.
|
||||
* Alternative to overriding {@code equals()}.
|
||||
*/
|
||||
private Object readResolve() {
|
||||
return INSTANCE;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,38 +24,42 @@ import java.lang.reflect.Method;
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class TrueMethodMatcher implements MethodMatcher, Serializable {
|
||||
|
||||
|
||||
public static final TrueMethodMatcher INSTANCE = new TrueMethodMatcher();
|
||||
|
||||
|
||||
/**
|
||||
* Enforce Singleton pattern.
|
||||
*/
|
||||
private TrueMethodMatcher() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRuntime() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, Class targetClass) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, Class targetClass, Object[] args) {
|
||||
// Should never be invoked as isRuntime returns false.
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Required to support serialization. Replaces with canonical
|
||||
* instance on deserialization, protecting Singleton pattern.
|
||||
* Alternative to overriding <code>equals()</code>.
|
||||
* Alternative to overriding {@code equals()}.
|
||||
*/
|
||||
private Object readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MethodMatcher.TRUE";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,28 +23,31 @@ import java.io.Serializable;
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class TruePointcut implements Pointcut, Serializable {
|
||||
|
||||
|
||||
public static final TruePointcut INSTANCE = new TruePointcut();
|
||||
|
||||
|
||||
/**
|
||||
* Enforce Singleton pattern.
|
||||
*/
|
||||
private TruePointcut() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassFilter getClassFilter() {
|
||||
return ClassFilter.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodMatcher getMethodMatcher() {
|
||||
return MethodMatcher.TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Required to support serialization. Replaces with canonical
|
||||
* instance on deserialization, protecting Singleton pattern.
|
||||
* Alternative to overriding <code>equals()</code>.
|
||||
* Alternative to overriding {@code equals()}.
|
||||
*/
|
||||
private Object readResolve() {
|
||||
return INSTANCE;
|
||||
|
||||
@@ -203,6 +203,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
return this.aspectInstanceFactory.getAspectClassLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.aspectInstanceFactory.getOrder();
|
||||
}
|
||||
@@ -211,7 +212,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
public void setAspectName(String name) {
|
||||
this.aspectName = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getAspectName() {
|
||||
return this.aspectName;
|
||||
}
|
||||
@@ -223,6 +225,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
this.declarationOrder = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDeclarationOrder() {
|
||||
return this.declarationOrder;
|
||||
}
|
||||
@@ -268,7 +271,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
throw new UnsupportedOperationException("Only afterReturning advice can be used to bind a return value");
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* We need to hold the returning name at this level for argument binding calculations,
|
||||
* this method allows the afterReturning advice subclass to set the name.
|
||||
*/
|
||||
@@ -302,7 +305,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
throw new UnsupportedOperationException("Only afterThrowing advice can be used to bind a thrown exception");
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* We need to hold the throwing name at this level for argument binding calculations,
|
||||
* this method allows the afterThrowing advice subclass to set the name.
|
||||
*/
|
||||
@@ -347,8 +350,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
* on subsequent advice invocations can be as fast as possible.
|
||||
* <p>If the first argument is of type JoinPoint or ProceedingJoinPoint then we
|
||||
* pass a JoinPoint in that position (ProceedingJoinPoint for around advice).
|
||||
* <p>If the first argument is of type <code>JoinPoint.StaticPart</code>
|
||||
* then we pass a <code>JoinPoint.StaticPart</code> in that position.
|
||||
* <p>If the first argument is of type {@code JoinPoint.StaticPart}
|
||||
* then we pass a {@code JoinPoint.StaticPart} in that position.
|
||||
* <p>Remaining arguments have to be bound by pointcut evaluation at
|
||||
* a given join point. We will get back a map from argument name to
|
||||
* value. We need to calculate which advice parameter needs to be bound
|
||||
@@ -365,11 +368,11 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
Class[] parameterTypes = this.aspectJAdviceMethod.getParameterTypes();
|
||||
if (maybeBindJoinPoint(parameterTypes[0]) || maybeBindProceedingJoinPoint(parameterTypes[0])) {
|
||||
numUnboundArgs--;
|
||||
}
|
||||
}
|
||||
else if (maybeBindJoinPointStaticPart(parameterTypes[0])) {
|
||||
numUnboundArgs--;
|
||||
}
|
||||
|
||||
|
||||
if (numUnboundArgs > 0) {
|
||||
// need to bind arguments by name as returned from the pointcut match
|
||||
bindArgumentsByName(numUnboundArgs);
|
||||
@@ -398,7 +401,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean supportsProceedingJoinPoint() {
|
||||
@@ -409,7 +412,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
if (candidateParameterType.equals(JoinPoint.StaticPart.class)) {
|
||||
this.joinPointStaticPartArgumentIndex = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
@@ -422,7 +425,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
if (this.argumentNames != null) {
|
||||
// We have been able to determine the arg names.
|
||||
bindExplicitArguments(numArgumentsExpectingToBind);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Advice method [" + this.aspectJAdviceMethod.getName() + "] " +
|
||||
"requires " + numArgumentsExpectingToBind + " arguments to be bound by name, but " +
|
||||
@@ -471,9 +474,9 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
// specified, and find the discovered argument types.
|
||||
if (this.returningName != null) {
|
||||
if (!this.argumentBindings.containsKey(this.returningName)) {
|
||||
throw new IllegalStateException("Returning argument name '"
|
||||
throw new IllegalStateException("Returning argument name '"
|
||||
+ this.returningName + "' was not bound in advice arguments");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Integer index = this.argumentBindings.get(this.returningName);
|
||||
this.discoveredReturningType = this.aspectJAdviceMethod.getParameterTypes()[index];
|
||||
@@ -482,9 +485,9 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
}
|
||||
if (this.throwingName != null) {
|
||||
if (!this.argumentBindings.containsKey(this.throwingName)) {
|
||||
throw new IllegalStateException("Throwing argument name '"
|
||||
throw new IllegalStateException("Throwing argument name '"
|
||||
+ this.throwingName + "' was not bound in advice arguments");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Integer index = this.argumentBindings.get(this.throwingName);
|
||||
this.discoveredThrowingType = this.aspectJAdviceMethod.getParameterTypes()[index];
|
||||
@@ -525,7 +528,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
pointcutParameterTypes[index] = methodParameterTypes[i];
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
this.pointcut.setParameterNames(pointcutParameterNames);
|
||||
this.pointcut.setParameterTypes(pointcutParameterTypes);
|
||||
}
|
||||
@@ -549,7 +552,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
if (this.joinPointArgumentIndex != -1) {
|
||||
adviceInvocationArgs[this.joinPointArgumentIndex] = jp;
|
||||
numBound++;
|
||||
}
|
||||
}
|
||||
else if (this.joinPointStaticPartArgumentIndex != -1) {
|
||||
adviceInvocationArgs[this.joinPointStaticPartArgumentIndex] = jp.getStaticPart();
|
||||
numBound++;
|
||||
@@ -582,8 +585,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
|
||||
if (numBound != this.adviceInvocationArgumentCount) {
|
||||
throw new IllegalStateException("Required to bind " + this.adviceInvocationArgumentCount
|
||||
+ " arguments, but only bound " + numBound + " (JoinPointMatch " +
|
||||
(jpMatch == null ? "was NOT" : "WAS") +
|
||||
+ " arguments, but only bound " + numBound + " (JoinPointMatch " +
|
||||
(jpMatch == null ? "was NOT" : "WAS") +
|
||||
" bound in invocation)");
|
||||
}
|
||||
|
||||
@@ -678,6 +681,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
this.adviceMethod = adviceMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, Class targetClass) {
|
||||
return !this.adviceMethod.equals(method);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,13 +34,13 @@ public interface AspectInstanceFactory extends Ordered {
|
||||
|
||||
/**
|
||||
* Create an instance of this factory's aspect.
|
||||
* @return the aspect instance (never <code>null</code>)
|
||||
* @return the aspect instance (never {@code null})
|
||||
*/
|
||||
Object getAspectInstance();
|
||||
|
||||
/**
|
||||
* Expose the aspect class loader that this factory uses.
|
||||
* @return the aspect class loader (never <code>null</code>)
|
||||
* @return the aspect class loader (never {@code null})
|
||||
*/
|
||||
ClassLoader getAspectClassLoader();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,82 +36,82 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* {@link ParameterNameDiscoverer} implementation that tries to deduce parameter names
|
||||
* for an advice method from the pointcut expression, returning, and throwing clauses.
|
||||
* If an unambiguous interpretation is not available, it returns <code>null</code>.
|
||||
* If an unambiguous interpretation is not available, it returns {@code null}.
|
||||
*
|
||||
* <p>This class interprets arguments in the following way:
|
||||
* <ol>
|
||||
* <li>If the first parameter of the method is of type {@link JoinPoint}
|
||||
* or {@link ProceedingJoinPoint}, it is assumed to be for passing
|
||||
* <code>thisJoinPoint</code> to the advice, and the parameter name will
|
||||
* be assigned the value <code>"thisJoinPoint"</code>.</li>
|
||||
* {@code thisJoinPoint} to the advice, and the parameter name will
|
||||
* be assigned the value {@code "thisJoinPoint"}.</li>
|
||||
* <li>If the first parameter of the method is of type
|
||||
* <code>JoinPoint.StaticPart</code>, it is assumed to be for passing
|
||||
* <code>"thisJoinPointStaticPart"</code> to the advice, and the parameter name
|
||||
* will be assigned the value <code>"thisJoinPointStaticPart"</code>.</li>
|
||||
* {@code JoinPoint.StaticPart}, it is assumed to be for passing
|
||||
* {@code "thisJoinPointStaticPart"} to the advice, and the parameter name
|
||||
* will be assigned the value {@code "thisJoinPointStaticPart"}.</li>
|
||||
* <li>If a {@link #setThrowingName(String) throwingName} has been set, and
|
||||
* there are no unbound arguments of type <code>Throwable+</code>, then an
|
||||
* there are no unbound arguments of type {@code Throwable+}, then an
|
||||
* {@link IllegalArgumentException} is raised. If there is more than one
|
||||
* unbound argument of type <code>Throwable+</code>, then an
|
||||
* unbound argument of type {@code Throwable+}, then an
|
||||
* {@link AmbiguousBindingException} is raised. If there is exactly one
|
||||
* unbound argument of type <code>Throwable+</code>, then the corresponding
|
||||
* unbound argument of type {@code Throwable+}, then the corresponding
|
||||
* parameter name is assigned the value <throwingName>.</li>
|
||||
* <li>If there remain unbound arguments, then the pointcut expression is
|
||||
* examined. Let <code>a</code> be the number of annotation-based pointcut
|
||||
* examined. Let {@code a} be the number of annotation-based pointcut
|
||||
* expressions (@annotation, @this, @target, @args,
|
||||
* @within, @withincode) that are used in binding form. Usage in
|
||||
* binding form has itself to be deduced: if the expression inside the
|
||||
* pointcut is a single string literal that meets Java variable name
|
||||
* conventions it is assumed to be a variable name. If <code>a</code> is
|
||||
* zero we proceed to the next stage. If <code>a</code> > 1 then an
|
||||
* <code>AmbiguousBindingException</code> is raised. If <code>a</code> == 1,
|
||||
* and there are no unbound arguments of type <code>Annotation+</code>,
|
||||
* then an <code>IllegalArgumentException</code> is raised. if there is
|
||||
* conventions it is assumed to be a variable name. If {@code a} is
|
||||
* zero we proceed to the next stage. If {@code a} > 1 then an
|
||||
* {@code AmbiguousBindingException} is raised. If {@code a} == 1,
|
||||
* and there are no unbound arguments of type {@code Annotation+},
|
||||
* then an {@code IllegalArgumentException} is raised. if there is
|
||||
* exactly one such argument, then the corresponding parameter name is
|
||||
* assigned the value from the pointcut expression.</li>
|
||||
* <li>If a returningName has been set, and there are no unbound arguments
|
||||
* then an <code>IllegalArgumentException</code> is raised. If there is
|
||||
* then an {@code IllegalArgumentException} is raised. If there is
|
||||
* more than one unbound argument then an
|
||||
* <code>AmbiguousBindingException</code> is raised. If there is exactly
|
||||
* {@code AmbiguousBindingException} is raised. If there is exactly
|
||||
* one unbound argument then the corresponding parameter name is assigned
|
||||
* the value <returningName>.</li>
|
||||
* <li>If there remain unbound arguments, then the pointcut expression is
|
||||
* examined once more for <code>this</code>, <code>target</code>, and
|
||||
* <code>args</code> pointcut expressions used in the binding form (binding
|
||||
* examined once more for {@code this}, {@code target}, and
|
||||
* {@code args} pointcut expressions used in the binding form (binding
|
||||
* forms are deduced as described for the annotation based pointcuts). If
|
||||
* there remains more than one unbound argument of a primitive type (which
|
||||
* can only be bound in <code>args</code>) then an
|
||||
* <code>AmbiguousBindingException</code> is raised. If there is exactly
|
||||
* one argument of a primitive type, then if exactly one <code>args</code>
|
||||
* can only be bound in {@code args}) then an
|
||||
* {@code AmbiguousBindingException} is raised. If there is exactly
|
||||
* one argument of a primitive type, then if exactly one {@code args}
|
||||
* bound variable was found, we assign the corresponding parameter name
|
||||
* the variable name. If there were no <code>args</code> bound variables
|
||||
* found an <code>IllegalStateException</code> is raised. If there are
|
||||
* multiple <code>args</code> bound variables, an
|
||||
* <code>AmbiguousBindingException</code> is raised. At this point, if
|
||||
* the variable name. If there were no {@code args} bound variables
|
||||
* found an {@code IllegalStateException} is raised. If there are
|
||||
* multiple {@code args} bound variables, an
|
||||
* {@code AmbiguousBindingException} is raised. At this point, if
|
||||
* there remains more than one unbound argument we raise an
|
||||
* <code>AmbiguousBindingException</code>. If there are no unbound arguments
|
||||
* {@code AmbiguousBindingException}. If there are no unbound arguments
|
||||
* remaining, we are done. If there is exactly one unbound argument
|
||||
* remaining, and only one candidate variable name unbound from
|
||||
* <code>this</code>, <code>target</code>, or <code>args</code>, it is
|
||||
* {@code this}, {@code target}, or {@code args}, it is
|
||||
* assigned as the corresponding parameter name. If there are multiple
|
||||
* possibilities, an <code>AmbiguousBindingException</code> is raised.</li>
|
||||
* possibilities, an {@code AmbiguousBindingException} is raised.</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p>The behavior on raising an <code>IllegalArgumentException</code> or
|
||||
* <code>AmbiguousBindingException</code> is configurable to allow this discoverer
|
||||
* <p>The behavior on raising an {@code IllegalArgumentException} or
|
||||
* {@code AmbiguousBindingException} is configurable to allow this discoverer
|
||||
* to be used as part of a chain-of-responsibility. By default the condition will
|
||||
* be logged and the <code>getParameterNames(..)</code> method will simply return
|
||||
* <code>null</code>. If the {@link #setRaiseExceptions(boolean) raiseExceptions}
|
||||
* property is set to <code>true</code>, the conditions will be thrown as
|
||||
* <code>IllegalArgumentException</code> and <code>AmbiguousBindingException</code>,
|
||||
* be logged and the {@code getParameterNames(..)} method will simply return
|
||||
* {@code null}. If the {@link #setRaiseExceptions(boolean) raiseExceptions}
|
||||
* property is set to {@code true}, the conditions will be thrown as
|
||||
* {@code IllegalArgumentException} and {@code AmbiguousBindingException},
|
||||
* respectively.
|
||||
*
|
||||
* <p>Was that perfectly clear? ;)
|
||||
*
|
||||
* <p>Short version: If an unambiguous binding can be deduced, then it is.
|
||||
* If the advice requirements cannot possibly be satisfied, then <code>null</code>
|
||||
* If the advice requirements cannot possibly be satisfied, then {@code null}
|
||||
* is returned. By setting the {@link #setRaiseExceptions(boolean) raiseExceptions}
|
||||
* property to <code>true</code>, descriptive exceptions will be thrown instead of
|
||||
* returning <code>null</code> in the case that the parameter names cannot be discovered.
|
||||
* property to {@code true}, descriptive exceptions will be thrown instead of
|
||||
* returning {@code null} in the case that the parameter names cannot be discovered.
|
||||
*
|
||||
* @author Adrian Colyer
|
||||
* @since 2.0
|
||||
@@ -191,14 +191,14 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
/**
|
||||
* Indicate whether {@link IllegalArgumentException} and {@link AmbiguousBindingException}
|
||||
* must be thrown as appropriate in the case of failing to deduce advice parameter names.
|
||||
* @param raiseExceptions <code>true</code> if exceptions are to be thrown
|
||||
* @param raiseExceptions {@code true} if exceptions are to be thrown
|
||||
*/
|
||||
public void setRaiseExceptions(boolean raiseExceptions) {
|
||||
this.raiseExceptions = raiseExceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* If <code>afterReturning</code> advice binds the return value, the
|
||||
* If {@code afterReturning} advice binds the return value, the
|
||||
* returning variable name must be specified.
|
||||
* @param returningName the name of the returning variable
|
||||
*/
|
||||
@@ -207,7 +207,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
}
|
||||
|
||||
/**
|
||||
* If <code>afterThrowing</code> advice binds the thrown value, the
|
||||
* If {@code afterThrowing} advice binds the thrown value, the
|
||||
* throwing variable name must be specified.
|
||||
* @param throwingName the name of the throwing variable
|
||||
*/
|
||||
@@ -222,6 +222,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
* @param method the target {@link Method}
|
||||
* @return the parameter names
|
||||
*/
|
||||
@Override
|
||||
public String[] getParameterNames(Method method) {
|
||||
this.argumentTypes = method.getParameterTypes();
|
||||
this.numberOfRemainingUnboundArguments = this.argumentTypes.length;
|
||||
@@ -305,10 +306,11 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
|
||||
/**
|
||||
* An advice method can never be a constructor in Spring.
|
||||
* @return <code>null</code>
|
||||
* @return {@code null}
|
||||
* @throws UnsupportedOperationException if
|
||||
* {@link #setRaiseExceptions(boolean) raiseExceptions} has been set to <code>true</code>
|
||||
* {@link #setRaiseExceptions(boolean) raiseExceptions} has been set to {@code true}
|
||||
*/
|
||||
@Override
|
||||
public String[] getParameterNames(Constructor ctor) {
|
||||
if (this.raiseExceptions) {
|
||||
throw new UnsupportedOperationException("An advice method can never be a constructor");
|
||||
@@ -493,7 +495,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an args pointcut body (could be <code>args</code> or <code>at_args</code>),
|
||||
* Given an args pointcut body (could be {@code args} or {@code at_args}),
|
||||
* add any candidate variable names to the given list.
|
||||
*/
|
||||
private void maybeExtractVariableNamesFromArgs(String argsSpec, List<String> varNames) {
|
||||
@@ -700,7 +702,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
// 1 primitive arg, and one candidate...
|
||||
for (int i = 0; i < this.argumentTypes.length; i++) {
|
||||
if (isUnbound(i) && this.argumentTypes[i].isPrimitive()) {
|
||||
bindParameterName(i, (String) varNames.get(0));
|
||||
bindParameterName(i, varNames.get(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -726,7 +728,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
}
|
||||
|
||||
/*
|
||||
* Return <code>true</code> if the given argument type is a subclass
|
||||
* Return {@code true} if the given argument type is a subclass
|
||||
* of the given supertype.
|
||||
*/
|
||||
private boolean isSubtypeOf(Class supertype, int argumentNumber) {
|
||||
@@ -755,7 +757,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
|
||||
/*
|
||||
* Find the argument index with the given type, and bind the given
|
||||
* <code>varName</code> in that position.
|
||||
* {@code varName} in that position.
|
||||
*/
|
||||
private void findAndBind(Class argumentType, String varName) {
|
||||
for (int i = 0; i < this.argumentTypes.length; i++) {
|
||||
@@ -790,6 +792,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
* Thrown in response to an ambiguous binding being detected when
|
||||
* trying to resolve a method's parameter names.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static class AmbiguousBindingException extends RuntimeException {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,8 @@ public class AspectJAfterAdvice extends AbstractAspectJAdvice implements MethodI
|
||||
|
||||
super(aspectJBeforeAdviceMethod, pointcut, aif);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
try {
|
||||
return mi.proceed();
|
||||
@@ -46,10 +47,12 @@ public class AspectJAfterAdvice extends AbstractAspectJAdvice implements MethodI
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBeforeAdvice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAfterAdvice() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,10 +40,12 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice implement
|
||||
super(aspectJBeforeAdviceMethod, pointcut, aif);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBeforeAdvice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAfterAdvice() {
|
||||
return true;
|
||||
}
|
||||
@@ -53,6 +55,7 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice implement
|
||||
setReturningNameNoCheck(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
|
||||
if (shouldInvokeOnReturnValueOf(method, returnValue)) {
|
||||
invokeAdviceMethod(getJoinPointMatch(), returnValue, null);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,10 +37,12 @@ public class AspectJAfterThrowingAdvice extends AbstractAspectJAdvice implements
|
||||
super(aspectJBeforeAdviceMethod, pointcut, aif);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBeforeAdvice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAfterAdvice() {
|
||||
return true;
|
||||
}
|
||||
@@ -50,6 +52,7 @@ public class AspectJAfterThrowingAdvice extends AbstractAspectJAdvice implements
|
||||
setThrowingNameNoCheck(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
try {
|
||||
return mi.proceed();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ import org.springframework.aop.BeforeAdvice;
|
||||
public abstract class AspectJAopUtils {
|
||||
|
||||
/**
|
||||
* Return <code>true</code> if the advisor is a form of before advice.
|
||||
* Return {@code true} if the advisor is a form of before advice.
|
||||
*/
|
||||
public static boolean isBeforeAdvice(Advisor anAdvisor) {
|
||||
AspectJPrecedenceInformation precedenceInfo = getAspectJPrecedenceInformationFor(anAdvisor);
|
||||
@@ -43,7 +43,7 @@ public abstract class AspectJAopUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true</code> if the advisor is a form of after advice.
|
||||
* Return {@code true} if the advisor is a form of after advice.
|
||||
*/
|
||||
public static boolean isAfterAdvice(Advisor anAdvisor) {
|
||||
AspectJPrecedenceInformation precedenceInfo = getAspectJPrecedenceInformationFor(anAdvisor);
|
||||
@@ -56,7 +56,7 @@ public abstract class AspectJAopUtils {
|
||||
/**
|
||||
* Return the AspectJPrecedenceInformation provided by this advisor or its advice.
|
||||
* If neither the advisor nor the advice have precedence information, this method
|
||||
* will return <code>null</code>.
|
||||
* will return {@code null}.
|
||||
*/
|
||||
public static AspectJPrecedenceInformation getAspectJPrecedenceInformationFor(Advisor anAdvisor) {
|
||||
if (anAdvisor instanceof AspectJPrecedenceInformation) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,10 +41,12 @@ public class AspectJAroundAdvice extends AbstractAspectJAdvice implements Method
|
||||
super(aspectJAroundAdviceMethod, pointcut, aif);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBeforeAdvice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAfterAdvice() {
|
||||
return false;
|
||||
}
|
||||
@@ -55,6 +57,7 @@ public class AspectJAroundAdvice extends AbstractAspectJAdvice implements Method
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
if (!(mi instanceof ProxyMethodInvocation)) {
|
||||
throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,6 +76,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Dave Syer
|
||||
* @since 2.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
implements ClassFilter, IntroductionAwareMethodMatcher, BeanFactoryAware {
|
||||
|
||||
@@ -154,16 +155,19 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
this.pointcutParameterTypes = types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ClassFilter getClassFilter() {
|
||||
checkReadyToMatch();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodMatcher getMethodMatcher() {
|
||||
checkReadyToMatch();
|
||||
return this;
|
||||
@@ -223,9 +227,9 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
|
||||
/**
|
||||
* If a pointcut expression has been specified in XML, the user cannot
|
||||
* write <code>and</code> as "&&" (though && will work).
|
||||
* We also allow <code>and</code> between two pointcut sub-expressions.
|
||||
* <p>This method converts back to <code>&&</code> for the AspectJ pointcut parser.
|
||||
* write {@code and} as "&&" (though && will work).
|
||||
* We also allow {@code and} between two pointcut sub-expressions.
|
||||
* <p>This method converts back to {@code &&} for the AspectJ pointcut parser.
|
||||
*/
|
||||
private String replaceBooleanOperators(String pcExpr) {
|
||||
String result = StringUtils.replace(pcExpr, " and ", " && ");
|
||||
@@ -243,6 +247,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
return this.pointcutExpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Class targetClass) {
|
||||
checkReadyToMatch();
|
||||
try {
|
||||
@@ -259,13 +264,14 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (BCException ex) {
|
||||
logger.debug("PointcutExpression matching rejected target class", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, Class targetClass, boolean beanHasIntroductions) {
|
||||
checkReadyToMatch();
|
||||
Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
|
||||
@@ -286,15 +292,18 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, Class targetClass) {
|
||||
return matches(method, targetClass, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRuntime() {
|
||||
checkReadyToMatch();
|
||||
return this.pointcutExpression.mayNeedDynamicTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, Class targetClass, Object[] args) {
|
||||
checkReadyToMatch();
|
||||
ShadowMatch shadowMatch = getShadowMatch(AopUtils.getMostSpecificMethod(method, targetClass), method);
|
||||
@@ -494,10 +503,10 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
|
||||
|
||||
/**
|
||||
* Handler for the Spring-specific <code>bean()</code> pointcut designator
|
||||
* Handler for the Spring-specific {@code bean()} pointcut designator
|
||||
* extension to AspectJ.
|
||||
* <p>This handler must be added to each pointcut object that needs to
|
||||
* handle the <code>bean()</code> PCD. Matching context is obtained
|
||||
* handle the {@code bean()} PCD. Matching context is obtained
|
||||
* automatically by examining a thread local variable and therefore a matching
|
||||
* context need not be set on the pointcut.
|
||||
*/
|
||||
@@ -505,10 +514,12 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
|
||||
private static final String BEAN_DESIGNATOR_NAME = "bean";
|
||||
|
||||
@Override
|
||||
public String getDesignatorName() {
|
||||
return BEAN_DESIGNATOR_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextBasedMatcher parse(String expression) {
|
||||
return new BeanNameContextMatcher(expression);
|
||||
}
|
||||
@@ -530,22 +541,27 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
this.expressionPattern = new NamePattern(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldMatchJoinPointsInType(Class someClass) {
|
||||
return (contextMatch(someClass) == FuzzyBoolean.YES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldMatchJoinPointsInType(Class someClass, MatchingContext context) {
|
||||
return (contextMatch(someClass) == FuzzyBoolean.YES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesDynamically(MatchingContext context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyBoolean matchesStatically(MatchingContext context) {
|
||||
return contextMatch(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayNeedDynamicTest() {
|
||||
return false;
|
||||
}
|
||||
@@ -554,7 +570,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
String advisedBeanName = getCurrentProxiedBeanName();
|
||||
if (advisedBeanName == null) { // no proxy creation in progress
|
||||
// abstain; can't return YES, since that will make pointcut with negation fail
|
||||
return FuzzyBoolean.MAYBE;
|
||||
return FuzzyBoolean.MAYBE;
|
||||
}
|
||||
if (BeanFactoryUtils.isGeneratedBeanName(advisedBeanName)) {
|
||||
return FuzzyBoolean.NO;
|
||||
@@ -610,18 +626,22 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
this.other = other;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alwaysMatches() {
|
||||
return primary.alwaysMatches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean maybeMatches() {
|
||||
return primary.maybeMatches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean neverMatches() {
|
||||
return primary.neverMatches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JoinPointMatch matchesJoinPoint(Object thisObject,
|
||||
Object targetObject, Object[] args) {
|
||||
try {
|
||||
@@ -631,6 +651,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMatchingContext(MatchingContext aMatchContext) {
|
||||
primary.setMatchingContext(aMatchContext);
|
||||
other.setMatchingContext(aMatchContext);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,15 +21,17 @@ import org.springframework.aop.support.AbstractGenericPointcutAdvisor;
|
||||
|
||||
/**
|
||||
* Spring AOP Advisor that can be used for any AspectJ pointcut expression.
|
||||
*
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @since 2.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdvisor {
|
||||
|
||||
private final AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
||||
|
||||
|
||||
@Override
|
||||
public Pointcut getPointcut() {
|
||||
return this.pointcut;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,14 +35,17 @@ public class AspectJMethodBeforeAdvice extends AbstractAspectJAdvice implements
|
||||
super(aspectJBeforeAdviceMethod, pointcut, aif);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before(Method method, Object[] args, Object target) throws Throwable {
|
||||
invokeAdviceMethod(getJoinPointMatch(), null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBeforeAdvice() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAfterAdvice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,18 +56,22 @@ public class AspectJPointcutAdvisor implements PointcutAdvisor, Ordered {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isPerInstance() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Advice getAdvice() {
|
||||
return this.advice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pointcut getPointcut() {
|
||||
return this.pointcut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
if (this.order != null) {
|
||||
return this.order;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,14 +30,14 @@ import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class AspectJProxyUtils {
|
||||
|
||||
|
||||
/**
|
||||
* Add special advisors if necessary to work with a proxy chain that contains AspectJ advisors.
|
||||
* This will expose the current Spring AOP invocation (necessary for some AspectJ pointcut matching)
|
||||
* and make available the current AspectJ JoinPoint. The call will have no effect if there are no
|
||||
* AspectJ advisors in the advisor chain.
|
||||
* @param advisors Advisors available
|
||||
* @return <code>true</code> if any special {@link Advisor Advisors} were added, otherwise <code>false</code>.
|
||||
* @return {@code true} if any special {@link Advisor Advisors} were added, otherwise {@code false}.
|
||||
*/
|
||||
public static boolean makeAdvisorChainAspectJCapableIfNecessary(List<Advisor> advisors) {
|
||||
// Don't add advisors to an empty list; may indicate that proxying is just not required
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,13 +27,13 @@ import org.aspectj.bridge.IMessageHandler;
|
||||
* Implementation of AspectJ's {@link IMessageHandler} interface that
|
||||
* routes AspectJ weaving messages through the same logging system as the
|
||||
* regular Spring messages.
|
||||
*
|
||||
*
|
||||
* <p>Pass the option...
|
||||
*
|
||||
* <p><code class="code">-XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler</code>
|
||||
*
|
||||
* <p>to the weaver; for example, specifying the following in a
|
||||
* "<code>META-INF/aop.xml</code> file:
|
||||
* "{@code META-INF/aop.xml} file:
|
||||
*
|
||||
* <p><code class="code"><weaver options="..."/></code>
|
||||
*
|
||||
@@ -44,10 +44,11 @@ import org.aspectj.bridge.IMessageHandler;
|
||||
public class AspectJWeaverMessageHandler implements IMessageHandler {
|
||||
|
||||
private static final String AJ_ID = "[AspectJ] ";
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog("AspectJ Weaver");
|
||||
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog("AspectJ Weaver");
|
||||
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(IMessage message) throws AbortException {
|
||||
Kind messageKind = message.getKind();
|
||||
|
||||
@@ -56,52 +57,55 @@ public class AspectJWeaverMessageHandler implements IMessageHandler {
|
||||
LOGGER.debug(makeMessageFor(message));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (LOGGER.isInfoEnabled()) {
|
||||
if ((messageKind == IMessage.INFO) || (messageKind == IMessage.WEAVEINFO)) {
|
||||
LOGGER.info(makeMessageFor(message));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (LOGGER.isWarnEnabled()) {
|
||||
if (messageKind == IMessage.WARNING) {
|
||||
LOGGER.warn(makeMessageFor(message));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (LOGGER.isErrorEnabled()) {
|
||||
if (messageKind == IMessage.ERROR) {
|
||||
LOGGER.error(makeMessageFor(message));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (LOGGER.isFatalEnabled()) {
|
||||
if (messageKind == IMessage.ABORT) {
|
||||
LOGGER.fatal(makeMessageFor(message));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private String makeMessageFor(IMessage aMessage) {
|
||||
return AJ_ID + aMessage.getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIgnoring(Kind messageKind) {
|
||||
// We want to see everything, and allow configuration of log levels dynamically.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dontIgnore(Kind messageKind) {
|
||||
// We weren't ignoring anything anyway...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignore(Kind kind) {
|
||||
// We weren't ignoring anything anyway...
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,7 +48,7 @@ public class DeclareParentsAdvisor implements IntroductionAdvisor {
|
||||
* @param defaultImpl the default implementation class
|
||||
*/
|
||||
public DeclareParentsAdvisor(Class interfaceType, String typePattern, Class defaultImpl) {
|
||||
this(interfaceType, typePattern, defaultImpl,
|
||||
this(interfaceType, typePattern, defaultImpl,
|
||||
new DelegatePerTargetObjectIntroductionInterceptor(defaultImpl, interfaceType));
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class DeclareParentsAdvisor implements IntroductionAdvisor {
|
||||
* @param delegateRef the delegate implementation object
|
||||
*/
|
||||
public DeclareParentsAdvisor(Class interfaceType, String typePattern, Object delegateRef) {
|
||||
this(interfaceType, typePattern, delegateRef.getClass(),
|
||||
this(interfaceType, typePattern, delegateRef.getClass(),
|
||||
new DelegatingIntroductionInterceptor(delegateRef));
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ public class DeclareParentsAdvisor implements IntroductionAdvisor {
|
||||
|
||||
// Excludes methods implemented.
|
||||
ClassFilter exclusion = new ClassFilter() {
|
||||
@Override
|
||||
public boolean matches(Class clazz) {
|
||||
return !(introducedInterface.isAssignableFrom(clazz));
|
||||
}
|
||||
@@ -87,22 +88,27 @@ public class DeclareParentsAdvisor implements IntroductionAdvisor {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ClassFilter getClassFilter() {
|
||||
return this.typePatternClassFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateInterfaces() throws IllegalArgumentException {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPerInstance() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Advice getAdvice() {
|
||||
return this.advice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getInterfaces() {
|
||||
return new Class[] {this.introducedInterface};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,11 +34,11 @@ import org.springframework.util.Assert;
|
||||
* Implementation of AspectJ ProceedingJoinPoint interface
|
||||
* wrapping an AOP Alliance MethodInvocation.
|
||||
*
|
||||
* <p><b>Note</b>: the <code>getThis()</code> method returns the current Spring AOP proxy.
|
||||
* The <code>getTarget()</code> method returns the current Spring AOP target (which may be
|
||||
* <code>null</code> if there is no target), and is a plain POJO without any advice.
|
||||
* <p><b>Note</b>: the {@code getThis()} method returns the current Spring AOP proxy.
|
||||
* The {@code getTarget()} method returns the current Spring AOP target (which may be
|
||||
* {@code null} if there is no target), and is a plain POJO without any advice.
|
||||
* <b>If you want to call the object and have the advice take effect, use
|
||||
* <code>getThis()</code>.</b> A common example is casting the object to an
|
||||
* {@code getThis()}.</b> A common example is casting the object to an
|
||||
* introduced interface in the implementation of an introduction.
|
||||
*
|
||||
* <p>Of course there is no such distinction between target and proxy in AspectJ.
|
||||
@@ -50,7 +50,7 @@ import org.springframework.util.Assert;
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, JoinPoint.StaticPart {
|
||||
|
||||
|
||||
private final ProxyMethodInvocation methodInvocation;
|
||||
|
||||
private Object[] defensiveCopyOfArgs;
|
||||
@@ -72,14 +72,17 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
this.methodInvocation = methodInvocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set$AroundClosure(AroundClosure aroundClosure) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object proceed() throws Throwable {
|
||||
return this.methodInvocation.invocableClone().proceed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object proceed(Object[] arguments) throws Throwable {
|
||||
Assert.notNull(arguments, "Argument array passed to proceed cannot be null");
|
||||
if (arguments.length != this.methodInvocation.getArguments().length) {
|
||||
@@ -92,19 +95,22 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Spring AOP proxy. Cannot be <code>null</code>.
|
||||
* Returns the Spring AOP proxy. Cannot be {@code null}.
|
||||
*/
|
||||
@Override
|
||||
public Object getThis() {
|
||||
return this.methodInvocation.getProxy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Spring AOP target. May be <code>null</code> if there is no target.
|
||||
* Returns the Spring AOP target. May be {@code null} if there is no target.
|
||||
*/
|
||||
@Override
|
||||
public Object getTarget() {
|
||||
return this.methodInvocation.getThis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getArgs() {
|
||||
if (this.defensiveCopyOfArgs == null) {
|
||||
Object[] argsSource = this.methodInvocation.getArguments();
|
||||
@@ -114,6 +120,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
return this.defensiveCopyOfArgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Signature getSignature() {
|
||||
if (this.signature == null) {
|
||||
this.signature = new MethodSignatureImpl();
|
||||
@@ -121,6 +128,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
return signature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceLocation getSourceLocation() {
|
||||
if (this.sourceLocation == null) {
|
||||
this.sourceLocation = new SourceLocationImpl();
|
||||
@@ -128,23 +136,28 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
return this.sourceLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKind() {
|
||||
return ProceedingJoinPoint.METHOD_EXECUTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
// TODO: It's just an adapter but returning 0 might still have side effects...
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JoinPoint.StaticPart getStaticPart() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toShortString() {
|
||||
return "execution(" + getSignature().toShortString() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLongString() {
|
||||
return "execution(" + getSignature().toLongString() + ")";
|
||||
}
|
||||
@@ -161,34 +174,42 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
|
||||
private volatile String[] parameterNames;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return methodInvocation.getMethod().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModifiers() {
|
||||
return methodInvocation.getMethod().getModifiers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getDeclaringType() {
|
||||
return methodInvocation.getMethod().getDeclaringClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeclaringTypeName() {
|
||||
return methodInvocation.getMethod().getDeclaringClass().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getReturnType() {
|
||||
return methodInvocation.getMethod().getReturnType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method getMethod() {
|
||||
return methodInvocation.getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getParameterTypes() {
|
||||
return methodInvocation.getMethod().getParameterTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getParameterNames() {
|
||||
if (this.parameterNames == null) {
|
||||
this.parameterNames = (new LocalVariableTableParameterNameDiscoverer()).getParameterNames(getMethod());
|
||||
@@ -196,14 +217,17 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
return this.parameterNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getExceptionTypes() {
|
||||
return methodInvocation.getMethod().getExceptionTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toShortString() {
|
||||
return toString(false, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toLongString() {
|
||||
return toString(true, true, true, true);
|
||||
}
|
||||
@@ -267,6 +291,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
*/
|
||||
private class SourceLocationImpl implements SourceLocation {
|
||||
|
||||
@Override
|
||||
public Class getWithinType() {
|
||||
if (methodInvocation.getThis() == null) {
|
||||
throw new UnsupportedOperationException("No source location joinpoint available: target is null");
|
||||
@@ -274,14 +299,17 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
return methodInvocation.getThis().getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLine() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumn() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,12 +39,12 @@ import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* This class encapsulates some AspectJ internal knowledge that should be
|
||||
* pushed back into the AspectJ project in a future release.
|
||||
* pushed back into the AspectJ project in a future release.
|
||||
*
|
||||
* <p>It relies on implementation specific knowledge in AspectJ to break
|
||||
* encapsulation and do something AspectJ was not designed to do: query
|
||||
* the types of runtime tests that will be performed. The code here should
|
||||
* migrate to <code>ShadowMatch.getVariablesInvolvedInRuntimeTest()</code>
|
||||
* migrate to {@code ShadowMatch.getVariablesInvolvedInRuntimeTest()}
|
||||
* or some similar operation.
|
||||
*
|
||||
* <p>See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=151593"/>.
|
||||
@@ -106,38 +106,47 @@ class RuntimeTestWalker {
|
||||
protected static final int AT_TARGET_VAR = 4;
|
||||
protected static final int AT_ANNOTATION_VAR = 8;
|
||||
|
||||
@Override
|
||||
public void visit(And e) {
|
||||
e.getLeft().accept(this);
|
||||
e.getRight().accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Or e) {
|
||||
e.getLeft().accept(this);
|
||||
e.getRight().accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Not e) {
|
||||
e.getBody().accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Instanceof i) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Call call) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FieldGetCall fieldGetCall) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(HasAnnotation hasAnnotation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MatchingContextBasedTest matchingContextTest) {
|
||||
}
|
||||
|
||||
|
||||
protected int getVarType(ReflectionVar v) {
|
||||
try {
|
||||
Field varTypeField = ReflectionVar.class.getDeclaredField("varType");
|
||||
@@ -169,7 +178,7 @@ class RuntimeTestWalker {
|
||||
this.matches = defaultMatches;
|
||||
this.matchVarType = matchVarType;
|
||||
}
|
||||
|
||||
|
||||
public boolean instanceOfMatches(Test test) {
|
||||
test.accept(this);
|
||||
return matches;
|
||||
@@ -236,7 +245,7 @@ class RuntimeTestWalker {
|
||||
aTest.accept(this);
|
||||
return this.testsSubtypeSensitiveVars;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(Instanceof i) {
|
||||
ReflectionVar v = (ReflectionVar) i.getVar();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,13 +42,14 @@ public class SimpleAspectInstanceFactory implements AspectInstanceFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the specified aspect class (never <code>null</code>).
|
||||
* Return the specified aspect class (never {@code null}).
|
||||
*/
|
||||
public final Class getAspectClass() {
|
||||
return this.aspectClass;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Object getAspectInstance() {
|
||||
try {
|
||||
return this.aspectClass.newInstance();
|
||||
@@ -61,6 +62,7 @@ public class SimpleAspectInstanceFactory implements AspectInstanceFactory {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getAspectClassLoader() {
|
||||
return this.aspectClass.getClassLoader();
|
||||
}
|
||||
@@ -73,6 +75,7 @@ public class SimpleAspectInstanceFactory implements AspectInstanceFactory {
|
||||
* @see org.springframework.core.Ordered
|
||||
* @see #getOrderForAspectClass
|
||||
*/
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return getOrderForAspectClass(this.aspectClass);
|
||||
}
|
||||
@@ -81,7 +84,7 @@ public class SimpleAspectInstanceFactory implements AspectInstanceFactory {
|
||||
* Determine a fallback order for the case that the aspect instance
|
||||
* does not express an instance-specific order through implementing
|
||||
* the {@link org.springframework.core.Ordered} interface.
|
||||
* <p>The default implementation simply returns <code>Ordered.LOWEST_PRECEDENCE</code>.
|
||||
* <p>The default implementation simply returns {@code Ordered.LOWEST_PRECEDENCE}.
|
||||
* @param aspectClass the aspect class
|
||||
*/
|
||||
protected int getOrderForAspectClass(Class<?> aspectClass) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
|
||||
* @see SimpleAspectInstanceFactory
|
||||
*/
|
||||
public class SingletonAspectInstanceFactory implements AspectInstanceFactory {
|
||||
|
||||
|
||||
private final Object aspectInstance;
|
||||
|
||||
|
||||
@@ -44,10 +44,12 @@ public class SingletonAspectInstanceFactory implements AspectInstanceFactory {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Object getAspectInstance() {
|
||||
return this.aspectInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getAspectClassLoader() {
|
||||
return this.aspectInstance.getClass().getClassLoader();
|
||||
}
|
||||
@@ -60,6 +62,7 @@ public class SingletonAspectInstanceFactory implements AspectInstanceFactory {
|
||||
* @see org.springframework.core.Ordered
|
||||
* @see #getOrderForAspectClass
|
||||
*/
|
||||
@Override
|
||||
public int getOrder() {
|
||||
if (this.aspectInstance instanceof Ordered) {
|
||||
return ((Ordered) this.aspectInstance).getOrder();
|
||||
@@ -71,7 +74,7 @@ public class SingletonAspectInstanceFactory implements AspectInstanceFactory {
|
||||
* Determine a fallback order for the case that the aspect instance
|
||||
* does not express an instance-specific order through implementing
|
||||
* the {@link org.springframework.core.Ordered} interface.
|
||||
* <p>The default implementation simply returns <code>Ordered.LOWEST_PRECEDENCE</code>.
|
||||
* <p>The default implementation simply returns {@code Ordered.LOWEST_PRECEDENCE}.
|
||||
* @param aspectClass the aspect class
|
||||
*/
|
||||
protected int getOrderForAspectClass(Class<?> aspectClass) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,11 +47,11 @@ public class TypePatternClassFilter implements ClassFilter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fully configured {@link TypePatternClassFilter} using the
|
||||
* Create a fully configured {@link TypePatternClassFilter} using the
|
||||
* given type pattern.
|
||||
* @param typePattern the type pattern that AspectJ weaver should parse
|
||||
* @throws IllegalArgumentException if the supplied <code>typePattern</code> is <code>null</code>
|
||||
* or is recognized as invalid
|
||||
* @throws IllegalArgumentException if the supplied {@code typePattern} is {@code null}
|
||||
* or is recognized as invalid
|
||||
*/
|
||||
public TypePatternClassFilter(String typePattern) {
|
||||
setTypePattern(typePattern);
|
||||
@@ -68,12 +68,12 @@ public class TypePatternClassFilter implements ClassFilter {
|
||||
* <code class="code">
|
||||
* org.springframework.beans.ITestBean+
|
||||
* </code>
|
||||
* This will match the <code>ITestBean</code> interface and any class
|
||||
* This will match the {@code ITestBean} interface and any class
|
||||
* that implements it.
|
||||
* <p>These conventions are established by AspectJ, not Spring AOP.
|
||||
* @param typePattern the type pattern that AspectJ weaver should parse
|
||||
* @throws IllegalArgumentException if the supplied <code>typePattern</code> is <code>null</code>
|
||||
* or is recognized as invalid
|
||||
* @throws IllegalArgumentException if the supplied {@code typePattern} is {@code null}
|
||||
* or is recognized as invalid
|
||||
*/
|
||||
public void setTypePattern(String typePattern) {
|
||||
Assert.notNull(typePattern);
|
||||
@@ -93,6 +93,7 @@ public class TypePatternClassFilter implements ClassFilter {
|
||||
* @return whether the advice should apply to this candidate target class
|
||||
* @throws IllegalStateException if no {@link #setTypePattern(String)} has been set
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(Class clazz) {
|
||||
if (this.aspectJTypePatternMatcher == null) {
|
||||
throw new IllegalStateException("No 'typePattern' has been set via ctor/setter.");
|
||||
@@ -102,9 +103,9 @@ public class TypePatternClassFilter implements ClassFilter {
|
||||
|
||||
/**
|
||||
* If a type pattern has been specified in XML, the user cannot
|
||||
* write <code>and</code> as "&&" (though && will work).
|
||||
* We also allow <code>and</code> between two sub-expressions.
|
||||
* <p>This method converts back to <code>&&</code> for the AspectJ pointcut parser.
|
||||
* write {@code and} as "&&" (though && will work).
|
||||
* We also allow {@code and} between two sub-expressions.
|
||||
* <p>This method converts back to {@code &&} for the AspectJ pointcut parser.
|
||||
*/
|
||||
private String replaceBooleanOperators(String pcExpr) {
|
||||
pcExpr = StringUtils.replace(pcExpr," and "," && ");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -58,7 +58,7 @@ import org.springframework.util.StringUtils;
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFactory {
|
||||
|
||||
|
||||
protected static final ParameterNameDiscoverer ASPECTJ_ANNOTATION_PARAMETER_NAME_DISCOVERER =
|
||||
new AspectJAnnotationParameterNameDiscoverer();
|
||||
|
||||
@@ -111,6 +111,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
* is that aspects written in the code-style (AspectJ language) also have the annotation present
|
||||
* when compiled by ajc with the -1.5 flag, yet they cannot be consumed by Spring AOP.
|
||||
*/
|
||||
@Override
|
||||
public boolean isAspect(Class<?> clazz) {
|
||||
return (hasAspectAnnotation(clazz) && !compiledByAjc(clazz));
|
||||
}
|
||||
@@ -121,7 +122,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
|
||||
/**
|
||||
* We need to detect this as "code-style" AspectJ aspects should not be
|
||||
* interpreted by Spring AOP.
|
||||
* interpreted by Spring AOP.
|
||||
*/
|
||||
private boolean compiledByAjc(Class<?> clazz) {
|
||||
// The AJTypeSystem goes to great lengths to provide a uniform appearance between code-style and
|
||||
@@ -135,6 +136,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Class<?> aspectClass) throws AopConfigException {
|
||||
// If the parent has the annotation and isn't abstract it's an error
|
||||
if (aspectClass.getSuperclass().getAnnotation(Aspect.class) != null &&
|
||||
@@ -154,11 +156,11 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
if (ajType.getPerClause().getKind() == PerClauseKind.PERCFLOWBELOW) {
|
||||
throw new AopConfigException(aspectClass.getName() + " uses percflowbelow instantiation model: " +
|
||||
"This is not supported in Spring AOP.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The pointcut and advice annotations both have an "argNames" member which contains a
|
||||
* The pointcut and advice annotations both have an "argNames" member which contains a
|
||||
* comma-separated list of the argument names. We use this (if non-empty) to build the
|
||||
* formal parameters for the pointcut.
|
||||
*/
|
||||
@@ -169,13 +171,13 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
if (pointcutParameterNames != null) {
|
||||
pointcutParameterTypes = extractPointcutParameterTypes(pointcutParameterNames,annotatedMethod);
|
||||
}
|
||||
|
||||
|
||||
AspectJExpressionPointcut ajexp =
|
||||
new AspectJExpressionPointcut(declarationScope,pointcutParameterNames,pointcutParameterTypes);
|
||||
ajexp.setLocation(annotatedMethod.toString());
|
||||
return ajexp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the pointcut parameters needed by aspectj based on the given argument names
|
||||
* and the argument types that are available from the adviceMethod. Needs to take into
|
||||
@@ -309,6 +311,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
*/
|
||||
private static class AspectJAnnotationParameterNameDiscoverer implements ParameterNameDiscoverer {
|
||||
|
||||
@Override
|
||||
public String[] getParameterNames(Method method) {
|
||||
if (method.getParameterTypes().length == 0) {
|
||||
return new String[0];
|
||||
@@ -326,10 +329,11 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
return names;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getParameterNames(Constructor ctor) {
|
||||
throw new UnsupportedOperationException("Spring AOP cannot handle constructor advice");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,6 +45,7 @@ import org.springframework.util.Assert;
|
||||
* @since 2.0
|
||||
* @see org.springframework.aop.aspectj.annotation.AspectJAdvisorFactory
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class AnnotationAwareAspectJAutoProxyCreator extends AspectJAwareAdvisorAutoProxyCreator {
|
||||
|
||||
private List<Pattern> includePatterns;
|
||||
@@ -103,7 +104,7 @@ public class AnnotationAwareAspectJAutoProxyCreator extends AspectJAwareAdvisorA
|
||||
/**
|
||||
* Check whether the given aspect bean is eligible for auto-proxying.
|
||||
* <p>If no <aop:include> elements were used then "includePatterns" will be
|
||||
* <code>null</code> and all beans are included. If "includePatterns" is non-null,
|
||||
* {@code null} and all beans are included. If "includePatterns" is non-null,
|
||||
* then one of the patterns must match.
|
||||
*/
|
||||
protected boolean isEligibleAspectBean(String beanName) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,7 @@ public interface AspectJAdvisorFactory {
|
||||
/**
|
||||
* Determine whether or not the given class is an aspect, as reported
|
||||
* by AspectJ's {@link org.aspectj.lang.reflect.AjTypeSystem}.
|
||||
* <p>Will simply return <code>false</code> if the supposed aspect is
|
||||
* <p>Will simply return {@code false} if the supposed aspect is
|
||||
* invalid (such as an extension of a concrete aspect class).
|
||||
* Will return true for some aspects that Spring AOP cannot process,
|
||||
* such as those with unsupported instantiation models.
|
||||
@@ -75,7 +75,7 @@ public interface AspectJAdvisorFactory {
|
||||
* @param aif the aspect instance factory
|
||||
* @param declarationOrderInAspect the declaration order within the aspect
|
||||
* @param aspectName the name of the aspect
|
||||
* @return <code>null</code> if the method is not an AspectJ advice method
|
||||
* @return {@code null} if the method is not an AspectJ advice method
|
||||
* or if it is a pointcut that will be used by other advice but will not
|
||||
* create a Spring advice in its own right
|
||||
*/
|
||||
@@ -89,7 +89,7 @@ public interface AspectJAdvisorFactory {
|
||||
* @param aif the aspect instance factory
|
||||
* @param declarationOrderInAspect the declaration order within the aspect
|
||||
* @param aspectName the name of the aspect
|
||||
* @return <code>null</code> if the method is not an AspectJ advice method
|
||||
* @return {@code null} if the method is not an AspectJ advice method
|
||||
* or if it is a pointcut that will be used by other advice but will not
|
||||
* create a Spring advice in its own right
|
||||
* @see org.springframework.aop.aspectj.AspectJAroundAdvice
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @see #getProxy(ClassLoader)
|
||||
* @see org.springframework.aop.framework.ProxyFactory
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class AspectJProxyFactory extends ProxyCreatorSupport {
|
||||
|
||||
/** Cache for singleton aspect instances */
|
||||
@@ -72,7 +73,7 @@ public class AspectJProxyFactory extends ProxyCreatorSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new <code>AspectJProxyFactory</code>.
|
||||
* Create a new {@code AspectJProxyFactory}.
|
||||
* No target, only interfaces. Must add interceptors.
|
||||
*/
|
||||
public AspectJProxyFactory(Class[] interfaces) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,8 +55,8 @@ public class AspectMetadata {
|
||||
private final Pointcut perClausePointcut;
|
||||
|
||||
/**
|
||||
* The name of this aspect as defined to Spring (the bean name) -
|
||||
* allows us to determine if two pieces of advice come from the
|
||||
* The name of this aspect as defined to Spring (the bean name) -
|
||||
* allows us to determine if two pieces of advice come from the
|
||||
* same aspect and hence their relative precedence.
|
||||
*/
|
||||
private String aspectName;
|
||||
@@ -109,7 +109,7 @@ public class AspectMetadata {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract contents from String of form <code>pertarget(contents)</code>.
|
||||
* Extract contents from String of form {@code pertarget(contents)}.
|
||||
*/
|
||||
private String findPerClause(Class<?> aspectClass) {
|
||||
// TODO when AspectJ provides this, we can remove this hack. Hence we don't
|
||||
@@ -144,7 +144,7 @@ public class AspectMetadata {
|
||||
|
||||
/**
|
||||
* Return a Spring pointcut expression for a singleton aspect.
|
||||
* (e.g. <code>Pointcut.TRUE</code> if it's a singleton).
|
||||
* (e.g. {@code Pointcut.TRUE} if it's a singleton).
|
||||
*/
|
||||
public Pointcut getPerClausePointcut() {
|
||||
return this.perClausePointcut;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ import org.springframework.util.ClassUtils;
|
||||
* backed by a Spring {@link org.springframework.beans.factory.BeanFactory}.
|
||||
*
|
||||
* <p>Note that this may instantiate multiple times if using a prototype,
|
||||
* which probably won't give the semantics you expect.
|
||||
* which probably won't give the semantics you expect.
|
||||
* Use a {@link LazySingletonAspectInstanceFactoryDecorator}
|
||||
* to wrap this to ensure only one new aspect comes back.
|
||||
*
|
||||
@@ -56,7 +56,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
|
||||
public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name) {
|
||||
this(beanFactory, name, beanFactory.getType(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a BeanFactoryAspectInstanceFactory, providing a type that AspectJ should
|
||||
* introspect to create AJType metadata. Use if the BeanFactory may consider the type
|
||||
@@ -72,10 +72,12 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getAspectInstance() {
|
||||
return this.beanFactory.getBean(this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getAspectClassLoader() {
|
||||
if (this.beanFactory instanceof ConfigurableBeanFactory) {
|
||||
return ((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader();
|
||||
@@ -85,6 +87,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AspectMetadata getAspectMetadata() {
|
||||
return this.aspectMetadata;
|
||||
}
|
||||
@@ -99,6 +102,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
|
||||
* @see org.springframework.core.Ordered
|
||||
* @see org.springframework.core.annotation.Order
|
||||
*/
|
||||
@Override
|
||||
public int getOrder() {
|
||||
Class<?> type = this.beanFactory.getType(this.name);
|
||||
if (type != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,23 +41,23 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
implements InstantiationModelAwarePointcutAdvisor, AspectJPrecedenceInformation {
|
||||
|
||||
private final AspectJExpressionPointcut declaredPointcut;
|
||||
|
||||
|
||||
private Pointcut pointcut;
|
||||
|
||||
|
||||
private final MetadataAwareAspectInstanceFactory aspectInstanceFactory;
|
||||
|
||||
|
||||
private final Method method;
|
||||
|
||||
|
||||
private final boolean lazy;
|
||||
|
||||
|
||||
private final AspectJAdvisorFactory atAspectJAdvisorFactory;
|
||||
|
||||
|
||||
private Advice instantiatedAdvice;
|
||||
|
||||
private int declarationOrder;
|
||||
|
||||
|
||||
private String aspectName;
|
||||
|
||||
|
||||
private Boolean isBeforeAdvice;
|
||||
|
||||
private Boolean isAfterAdvice;
|
||||
@@ -72,12 +72,12 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
this.aspectInstanceFactory = aif;
|
||||
this.declarationOrder = declarationOrderInAspect;
|
||||
this.aspectName = aspectName;
|
||||
|
||||
|
||||
if (aif.getAspectMetadata().isLazilyInstantiated()) {
|
||||
// Static part of the pointcut is a lazy type.
|
||||
Pointcut preInstantiationPointcut =
|
||||
Pointcuts.union(aif.getAspectMetadata().getPerClausePointcut(), this.declaredPointcut);
|
||||
|
||||
|
||||
// Make it dynamic: must mutate from pre-instantiation to post-instantiation state.
|
||||
// If it's not a dynamic pointcut, it may be optimized out
|
||||
// by the Spring AOP infrastructure after the first evaluation.
|
||||
@@ -97,19 +97,21 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
* The pointcut for Spring AOP to use. Actual behaviour of the pointcut will change
|
||||
* depending on the state of the advice.
|
||||
*/
|
||||
@Override
|
||||
public Pointcut getPointcut() {
|
||||
return this.pointcut;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is only of interest for Spring AOP: AspectJ instantiation semantics
|
||||
* are much richer. In AspectJ terminology, all a return of <code>true</code>
|
||||
* are much richer. In AspectJ terminology, all a return of {@code true}
|
||||
* means here is that the aspect is not a SINGLETON.
|
||||
*/
|
||||
@Override
|
||||
public boolean isPerInstance() {
|
||||
return (getAspectMetadata().getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the AspectJ AspectMetadata for this advisor.
|
||||
*/
|
||||
@@ -120,17 +122,20 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
/**
|
||||
* Lazily instantiate advice if necessary.
|
||||
*/
|
||||
@Override
|
||||
public synchronized Advice getAdvice() {
|
||||
if (this.instantiatedAdvice == null) {
|
||||
this.instantiatedAdvice = instantiateAdvice(this.declaredPointcut);
|
||||
}
|
||||
return this.instantiatedAdvice;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isLazy() {
|
||||
return this.lazy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isAdviceInstantiated() {
|
||||
return (this.instantiatedAdvice != null);
|
||||
}
|
||||
@@ -140,7 +145,7 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
return this.atAspectJAdvisorFactory.getAdvice(
|
||||
this.method, pcut, this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
|
||||
}
|
||||
|
||||
|
||||
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory() {
|
||||
return this.aspectInstanceFactory;
|
||||
}
|
||||
@@ -149,18 +154,22 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
return this.declaredPointcut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.aspectInstanceFactory.getOrder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAspectName() {
|
||||
return this.aspectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDeclarationOrder() {
|
||||
return this.declarationOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBeforeAdvice() {
|
||||
if (this.isBeforeAdvice == null) {
|
||||
determineAdviceType();
|
||||
@@ -168,6 +177,7 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
return this.isBeforeAdvice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAfterAdvice() {
|
||||
if (this.isAfterAdvice == null) {
|
||||
determineAdviceType();
|
||||
@@ -245,6 +255,7 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||
this.preInstantiationPointcut.getMethodMatcher().matches(method, targetClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, Class targetClass, Object[] args) {
|
||||
// This can match only on declared pointcut.
|
||||
return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,6 +42,7 @@ public class LazySingletonAspectInstanceFactoryDecorator implements MetadataAwar
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized Object getAspectInstance() {
|
||||
if (this.materialized == null) {
|
||||
synchronized (this) {
|
||||
@@ -57,14 +58,17 @@ public class LazySingletonAspectInstanceFactoryDecorator implements MetadataAwar
|
||||
return (this.materialized != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getAspectClassLoader() {
|
||||
return this.maaif.getAspectClassLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AspectMetadata getAspectMetadata() {
|
||||
return this.maaif.getAspectMetadata();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.maaif.getOrder();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.aop.framework.AopConfigException;
|
||||
* @author Rod Johnson
|
||||
* @since 2.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class NotAnAtAspectException extends AopConfigException {
|
||||
|
||||
private Class<?> nonAspectClass;
|
||||
|
||||
@@ -75,6 +75,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
new InstanceComparator<Annotation>(
|
||||
Around.class, Before.class, After.class, AfterReturning.class, AfterThrowing.class),
|
||||
new Converter<Method, Annotation>() {
|
||||
@Override
|
||||
public Annotation convert(Method method) {
|
||||
AspectJAnnotation<?> annotation = AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method);
|
||||
return annotation == null ? null : annotation.getAnnotation();
|
||||
@@ -82,6 +83,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
}));
|
||||
comparator.addComparator(new ConvertingComparator<Method, String>(
|
||||
new Converter<Method, String>() {
|
||||
@Override
|
||||
public String convert(Method method) {
|
||||
return method.getName();
|
||||
}
|
||||
@@ -90,6 +92,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Advisor> getAdvisors(MetadataAwareAspectInstanceFactory maaif) {
|
||||
final Class<?> aspectClass = maaif.getAspectMetadata().getAspectClass();
|
||||
final String aspectName = maaif.getAspectMetadata().getAspectName();
|
||||
@@ -128,6 +131,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
private List<Method> getAdvisorMethods(Class<?> aspectClass) {
|
||||
final List<Method> methods = new LinkedList<Method>();
|
||||
ReflectionUtils.doWithMethods(aspectClass, new ReflectionUtils.MethodCallback() {
|
||||
@Override
|
||||
public void doWith(Method method) throws IllegalArgumentException {
|
||||
// Exclude pointcuts
|
||||
if (AnnotationUtils.getAnnotation(method, Pointcut.class) == null) {
|
||||
@@ -144,7 +148,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
* for the given introduction field.
|
||||
* <p>Resulting Advisors will need to be evaluated for targets.
|
||||
* @param introductionField the field to introspect
|
||||
* @return <code>null</code> if not an Advisor
|
||||
* @return {@code null} if not an Advisor
|
||||
*/
|
||||
private Advisor getDeclareParentsAdvisor(Field introductionField) {
|
||||
DeclareParents declareParents = introductionField.getAnnotation(DeclareParents.class);
|
||||
@@ -164,6 +168,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aif,
|
||||
int declarationOrderInAspect, String aspectName) {
|
||||
|
||||
@@ -191,6 +196,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut ajexp,
|
||||
MetadataAwareAspectInstanceFactory aif, int declarationOrderInAspect, String aspectName) {
|
||||
|
||||
@@ -203,7 +209,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
return null;
|
||||
}
|
||||
|
||||
// If we get here, we know we have an AspectJ method.
|
||||
// If we get here, we know we have an AspectJ method.
|
||||
// Check that it's an AspectJ-annotated class
|
||||
if (!isAspect(candidateAspectClass)) {
|
||||
throw new AopConfigException("Advice must be declared inside an aspect type: " +
|
||||
@@ -272,6 +278,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
|
||||
public SyntheticInstantiationAdvisor(final MetadataAwareAspectInstanceFactory aif) {
|
||||
super(aif.getAspectMetadata().getPerClausePointcut(), new MethodBeforeAdvice() {
|
||||
@Override
|
||||
public void before(Method method, Object[] args, Object target) {
|
||||
// Simply instantiate the aspect
|
||||
aif.getAspectInstance();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,6 +45,7 @@ public class SimpleMetadataAwareAspectInstanceFactory extends SimpleAspectInstan
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final AspectMetadata getAspectMetadata() {
|
||||
return this.metadata;
|
||||
}
|
||||
@@ -53,7 +54,7 @@ public class SimpleMetadataAwareAspectInstanceFactory extends SimpleAspectInstan
|
||||
* Determine a fallback order for the case that the aspect instance
|
||||
* does not express an instance-specific order through implementing
|
||||
* the {@link org.springframework.core.Ordered} interface.
|
||||
* <p>The default implementation simply returns <code>Ordered.LOWEST_PRECEDENCE</code>.
|
||||
* <p>The default implementation simply returns {@code Ordered.LOWEST_PRECEDENCE}.
|
||||
* @param aspectClass the aspect class
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,6 +47,7 @@ public class SingletonMetadataAwareAspectInstanceFactory extends SingletonAspect
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final AspectMetadata getAspectMetadata() {
|
||||
return this.metadata;
|
||||
}
|
||||
@@ -54,7 +55,7 @@ public class SingletonMetadataAwareAspectInstanceFactory extends SingletonAspect
|
||||
/**
|
||||
* Check whether the aspect class carries an
|
||||
* {@link org.springframework.core.annotation.Order} annotation,
|
||||
* falling back to <code>Ordered.LOWEST_PRECEDENCE</code>.
|
||||
* falling back to {@code Ordered.LOWEST_PRECEDENCE}.
|
||||
* @see org.springframework.core.annotation.Order
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
*
|
||||
* Classes enabling AspectJ 5 @Annotated classes to be used in Spring AOP.
|
||||
*
|
||||
*
|
||||
* <p>Normally to be used through an AspectJAutoProxyCreator rather than directly.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,6 +43,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Ramnivas Laddad
|
||||
* @since 2.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProxyCreator {
|
||||
|
||||
private static final Comparator DEFAULT_PRECEDENCE_COMPARATOR = new AspectJPrecedenceComparator();
|
||||
@@ -72,22 +73,22 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
|
||||
for (Advisor element : advisors) {
|
||||
partiallyComparableAdvisors.add(
|
||||
new PartiallyComparableAdvisorHolder(element, DEFAULT_PRECEDENCE_COMPARATOR));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// sort it
|
||||
List<PartiallyComparableAdvisorHolder> sorted =
|
||||
(List<PartiallyComparableAdvisorHolder>) PartialOrder.sort(partiallyComparableAdvisors);
|
||||
PartialOrder.sort(partiallyComparableAdvisors);
|
||||
if (sorted == null) {
|
||||
// TODO: work harder to give a better error message here.
|
||||
throw new IllegalArgumentException("Advice precedence circularity error");
|
||||
}
|
||||
|
||||
|
||||
// extract results again
|
||||
List<Advisor> result = new LinkedList<Advisor>();
|
||||
for (PartiallyComparableAdvisorHolder pcAdvisor : sorted) {
|
||||
result.add(pcAdvisor.getAdvisor());
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -130,11 +131,13 @@ public class AspectJAwareAdvisorAutoProxyCreator extends AbstractAdvisorAutoProx
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object obj) {
|
||||
Advisor otherAdvisor = ((PartiallyComparableAdvisorHolder) obj).advisor;
|
||||
return this.comparator.compare(this.advisor, otherAdvisor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fallbackCompareTo(Object obj) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,15 +27,15 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* Orders AspectJ advice/advisors by precedence (<i>not</i> invocation order).
|
||||
*
|
||||
* <p>Given two pieces of advice, <code>a</code> and <code>b</code>:
|
||||
* <p>Given two pieces of advice, {@code a} and {@code b}:
|
||||
* <ul>
|
||||
* <li>if <code>a</code> and <code>b</code> are defined in different
|
||||
* <li>if {@code a} and {@code b} are defined in different
|
||||
* aspects, then the advice in the aspect with the lowest order
|
||||
* value has the highest precedence</li>
|
||||
* <li>if <code>a</code> and <code>b</code> are defined in the same
|
||||
* aspect, then if one of <code>a</code> or <code>b</code> is a form of
|
||||
* <li>if {@code a} and {@code b} are defined in the same
|
||||
* aspect, then if one of {@code a} or {@code b} is a form of
|
||||
* after advice, then the advice declared last in the aspect has the
|
||||
* highest precedence. If neither <code>a</code> nor <code>b</code> is a
|
||||
* highest precedence. If neither {@code a} nor {@code b} is a
|
||||
* form of after advice, then the advice declared first in the aspect has
|
||||
* the highest precedence.</li>
|
||||
* </ul>
|
||||
@@ -76,6 +76,7 @@ class AspectJPrecedenceComparator implements Comparator {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
if (!(o1 instanceof Advisor && o2 instanceof Advisor)) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -106,14 +107,14 @@ class AspectJPrecedenceComparator implements Comparator {
|
||||
boolean oneOrOtherIsAfterAdvice =
|
||||
(AspectJAopUtils.isAfterAdvice(advisor1) || AspectJAopUtils.isAfterAdvice(advisor2));
|
||||
int adviceDeclarationOrderDelta = getAspectDeclarationOrder(advisor1) - getAspectDeclarationOrder(advisor2);
|
||||
|
||||
|
||||
if (oneOrOtherIsAfterAdvice) {
|
||||
// the advice declared last has higher precedence
|
||||
if (adviceDeclarationOrderDelta < 0) {
|
||||
// advice1 was declared before advice2
|
||||
// so advice1 has lower precedence
|
||||
return LOWER_PRECEDENCE;
|
||||
}
|
||||
}
|
||||
else if (adviceDeclarationOrderDelta == 0) {
|
||||
return SAME_PRECEDENCE;
|
||||
}
|
||||
@@ -153,7 +154,7 @@ class AspectJPrecedenceComparator implements Comparator {
|
||||
}
|
||||
|
||||
private int getAspectDeclarationOrder(Advisor anAdvisor) {
|
||||
AspectJPrecedenceInformation precedenceInfo =
|
||||
AspectJPrecedenceInformation precedenceInfo =
|
||||
AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor);
|
||||
if (precedenceInfo != null) {
|
||||
return precedenceInfo.getDeclarationOrder();
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
|
||||
/**
|
||||
*
|
||||
* AspectJ integration package. Includes Spring AOP advice implementations for AspectJ 5
|
||||
* annotation-style methods, and an AspectJExpressionPointcut: a Spring AOP Pointcut
|
||||
* implementation that allows use of the AspectJ pointcut expression language with the Spring AOP
|
||||
* runtime framework.
|
||||
*
|
||||
* <p>Note that use of this package does <i>not</i> require the use of the <code>ajc</code> compiler
|
||||
*
|
||||
* <p>Note that use of this package does <i>not</i> require the use of the {@code ajc} compiler
|
||||
* or AspectJ load-time weaver. It is intended to enable the use of a valuable subset of AspectJ
|
||||
* functionality, with consistent semantics, with the proxy-based Spring AOP framework.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,7 @@ import org.springframework.util.StringUtils;
|
||||
* to the resulting bean.
|
||||
*
|
||||
* <p>This base class controls the creation of the {@link ProxyFactoryBean} bean definition
|
||||
* and wraps the original as an inner-bean definition for the <code>target</code> property
|
||||
* and wraps the original as an inner-bean definition for the {@code target} property
|
||||
* of {@link ProxyFactoryBean}.
|
||||
*
|
||||
* <p>Chaining is correctly handled, ensuring that only one {@link ProxyFactoryBean} definition
|
||||
@@ -48,7 +48,7 @@ import org.springframework.util.StringUtils;
|
||||
* already created the {@link org.springframework.aop.framework.ProxyFactoryBean} then the
|
||||
* interceptor is simply added to the existing definition.
|
||||
*
|
||||
* <p>Subclasses have only to create the <code>BeanDefinition</code> to the interceptor that
|
||||
* <p>Subclasses have only to create the {@code BeanDefinition} to the interceptor that
|
||||
* they wish to add.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
@@ -58,9 +58,10 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implements BeanDefinitionDecorator {
|
||||
|
||||
@Override
|
||||
public final BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definitionHolder, ParserContext parserContext) {
|
||||
BeanDefinitionRegistry registry = parserContext.getRegistry();
|
||||
|
||||
|
||||
// get the root bean name - will be the name of the generated proxy factory bean
|
||||
String existingBeanName = definitionHolder.getBeanName();
|
||||
BeanDefinition targetDefinition = definitionHolder.getBeanDefinition();
|
||||
@@ -118,7 +119,7 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses should implement this method to return the <code>BeanDefinition</code>
|
||||
* Subclasses should implement this method to return the {@code BeanDefinition}
|
||||
* for the interceptor they wish to apply to the bean being decorated.
|
||||
*/
|
||||
protected abstract BeanDefinition createInterceptorDefinition(Node node);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,7 @@ import org.springframework.beans.factory.parsing.ParseState;
|
||||
|
||||
/**
|
||||
* {@link ParseState} entry representing an advice element.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,7 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* {@link org.springframework.beans.factory.parsing.ComponentDefinition}
|
||||
* that bridges the gap between the advisor bean definition configured
|
||||
* by the <code><aop:advisor></code> tag and the component definition
|
||||
* by the {@code <aop:advisor>} tag and the component definition
|
||||
* infrastructure.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
@@ -91,6 +91,7 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.advisorBeanName;
|
||||
}
|
||||
@@ -110,6 +111,7 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
||||
return this.beanReferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSource() {
|
||||
return this.advisorDefinition.getSource();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,7 @@ import org.springframework.beans.factory.parsing.ParseState;
|
||||
|
||||
/**
|
||||
* {@link ParseState} entry representing an advisor.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,10 +31,10 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* Utility class for handling registration of AOP auto-proxy creators.
|
||||
*
|
||||
* <p>Only a single auto-proxy creator can be registered yet multiple concrete
|
||||
* implementations are available. Therefore this class wraps a simple escalation
|
||||
* <p>Only a single auto-proxy creator can be registered yet multiple concrete
|
||||
* implementations are available. Therefore this class wraps a simple escalation
|
||||
* protocol, allowing classes to request a particular auto-proxy creator and know
|
||||
* that class, <code>or a subclass thereof</code>, will eventually be resident
|
||||
* that class, {@code or a subclass thereof}, will eventually be resident
|
||||
* in the application context.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,21 +21,21 @@ import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
|
||||
/**
|
||||
* <code>NamespaceHandler</code> for the <code>aop</code> namespace.
|
||||
* {@code NamespaceHandler} for the {@code aop} namespace.
|
||||
*
|
||||
* <p>Provides a {@link org.springframework.beans.factory.xml.BeanDefinitionParser} for the
|
||||
* <code><aop:config></code> tag. A <code>config</code> tag can include nested
|
||||
* <code>pointcut</code>, <code>advisor</code> and <code>aspect</code> tags.
|
||||
* {@code <aop:config>} tag. A {@code config} tag can include nested
|
||||
* {@code pointcut}, {@code advisor} and {@code aspect} tags.
|
||||
*
|
||||
* <p>The <code>pointcut</code> tag allows for creation of named
|
||||
* <p>The {@code pointcut} tag allows for creation of named
|
||||
* {@link AspectJExpressionPointcut} beans using a simple syntax:
|
||||
* <pre class="code">
|
||||
* <aop:pointcut id="getNameCalls" expression="execution(* *..ITestBean.getName(..))"/>
|
||||
* </pre>
|
||||
*
|
||||
* <p>Using the <code>advisor</code> tag you can configure an {@link org.springframework.aop.Advisor}
|
||||
* <p>Using the {@code advisor} tag you can configure an {@link org.springframework.aop.Advisor}
|
||||
* and have it applied to all relevant beans in you {@link org.springframework.beans.factory.BeanFactory}
|
||||
* automatically. The <code>advisor</code> tag supports both in-line and referenced
|
||||
* automatically. The {@code advisor} tag supports both in-line and referenced
|
||||
* {@link org.springframework.aop.Pointcut Pointcuts}:
|
||||
*
|
||||
* <pre class="code">
|
||||
@@ -56,9 +56,10 @@ public class AopNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
/**
|
||||
* Register the {@link BeanDefinitionParser BeanDefinitionParsers} for the
|
||||
* '<code>config</code>', '<code>spring-configured</code>', '<code>aspectj-autoproxy</code>'
|
||||
* and '<code>scoped-proxy</code>' tags.
|
||||
* '{@code config}', '{@code spring-configured}', '{@code aspectj-autoproxy}'
|
||||
* and '{@code scoped-proxy}' tags.
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
// In 2.0 XSD as well as in 2.1 XSD.
|
||||
registerBeanDefinitionParser("config", new ConfigBeanDefinitionParser());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,7 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
|
||||
/**
|
||||
* Utility class for handling registration of auto-proxy creators used internally
|
||||
* by the '<code>aop</code>' namespace tags.
|
||||
* by the '{@code aop}' namespace tags.
|
||||
*
|
||||
* <p>Only a single auto-proxy creator can be registered and multiple tags may wish
|
||||
* to register different concrete implementations. As such this class delegates to
|
||||
@@ -42,12 +42,12 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
public abstract class AopNamespaceUtils {
|
||||
|
||||
/**
|
||||
* The <code>proxy-target-class</code> attribute as found on AOP-related XML tags.
|
||||
* The {@code proxy-target-class} attribute as found on AOP-related XML tags.
|
||||
*/
|
||||
public static final String PROXY_TARGET_CLASS_ATTRIBUTE = "proxy-target-class";
|
||||
|
||||
/**
|
||||
* The <code>expose-proxy</code> attribute as found on AOP-related XML tags.
|
||||
* The {@code expose-proxy} attribute as found on AOP-related XML tags.
|
||||
*/
|
||||
private static final String EXPOSE_PROXY_ATTRIBUTE = "expose-proxy";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
|
||||
/**
|
||||
* {@link BeanDefinitionParser} for the <code>aspectj-autoproxy</code> tag,
|
||||
* {@link BeanDefinitionParser} for the {@code aspectj-autoproxy} tag,
|
||||
* enabling the automatic application of @AspectJ-style aspects found in
|
||||
* the {@link org.springframework.beans.factory.BeanFactory}.
|
||||
*
|
||||
@@ -37,6 +37,7 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
*/
|
||||
class AspectJAutoProxyBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
AopNamespaceUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(parserContext, element);
|
||||
extendBeanDefinition(element, parserContext);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,7 +49,7 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
/**
|
||||
* {@link BeanDefinitionParser} for the <code><aop:config></code> tag.
|
||||
* {@link BeanDefinitionParser} for the {@code <aop:config>} tag.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
@@ -93,8 +93,9 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
private static final int ASPECT_INSTANCE_FACTORY_INDEX = 2;
|
||||
|
||||
private ParseState parseState = new ParseState();
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
CompositeComponentDefinition compositeDef =
|
||||
new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
|
||||
@@ -122,8 +123,8 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* Configures the auto proxy creator needed to support the {@link BeanDefinition BeanDefinitions}
|
||||
* created by the '<code><aop:config/></code>' tag. Will force class proxying if the
|
||||
* '<code>proxy-target-class</code>' attribute is set to '<code>true</code>'.
|
||||
* created by the '{@code <aop:config/>}' tag. Will force class proxying if the
|
||||
* '{@code proxy-target-class}' attribute is set to '{@code true}'.
|
||||
* @see AopNamespaceUtils
|
||||
*/
|
||||
private void configureAutoProxyCreator(ParserContext parserContext, Element element) {
|
||||
@@ -131,7 +132,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the supplied <code><advisor></code> element and registers the resulting
|
||||
* Parses the supplied {@code <advisor>} element and registers the resulting
|
||||
* {@link org.springframework.aop.Advisor} and any resulting {@link org.springframework.aop.Pointcut}
|
||||
* with the supplied {@link BeanDefinitionRegistry}.
|
||||
*/
|
||||
@@ -168,7 +169,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* Create a {@link RootBeanDefinition} for the advisor described in the supplied. Does <strong>not</strong>
|
||||
* parse any associated '<code>pointcut</code>' or '<code>pointcut-ref</code>' attributes.
|
||||
* parse any associated '{@code pointcut}' or '{@code pointcut-ref}' attributes.
|
||||
*/
|
||||
private AbstractBeanDefinition createAdvisorBeanDefinition(Element advisorElement, ParserContext parserContext) {
|
||||
RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class);
|
||||
@@ -257,9 +258,9 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true</code> if the supplied node describes an advice type. May be one of:
|
||||
* '<code>before</code>', '<code>after</code>', '<code>after-returning</code>',
|
||||
* '<code>after-throwing</code>' or '<code>around</code>'.
|
||||
* Return {@code true} if the supplied node describes an advice type. May be one of:
|
||||
* '{@code before}', '{@code after}', '{@code after-returning}',
|
||||
* '{@code after-throwing}' or '{@code around}'.
|
||||
*/
|
||||
private boolean isAdviceNode(Node aNode, ParserContext parserContext) {
|
||||
if (!(aNode instanceof Element)) {
|
||||
@@ -273,7 +274,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a '<code>declare-parents</code>' element and register the appropriate
|
||||
* Parse a '{@code declare-parents}' element and register the appropriate
|
||||
* DeclareParentsAdvisor with the BeanDefinitionRegistry encapsulated in the
|
||||
* supplied ParserContext.
|
||||
*/
|
||||
@@ -281,10 +282,10 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DeclareParentsAdvisor.class);
|
||||
builder.addConstructorArgValue(declareParentsElement.getAttribute(IMPLEMENT_INTERFACE));
|
||||
builder.addConstructorArgValue(declareParentsElement.getAttribute(TYPE_PATTERN));
|
||||
|
||||
|
||||
String defaultImpl = declareParentsElement.getAttribute(DEFAULT_IMPL);
|
||||
String delegateRef = declareParentsElement.getAttribute(DELEGATE_REF);
|
||||
|
||||
|
||||
if (StringUtils.hasText(defaultImpl) && !StringUtils.hasText(delegateRef)) {
|
||||
builder.addConstructorArgValue(defaultImpl);
|
||||
}
|
||||
@@ -304,8 +305,8 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses one of '<code>before</code>', '<code>after</code>', '<code>after-returning</code>',
|
||||
* '<code>after-throwing</code>' or '<code>around</code>' and registers the resulting
|
||||
* Parses one of '{@code before}', '{@code after}', '{@code after-returning}',
|
||||
* '{@code after-throwing}' or '{@code around}' and registers the resulting
|
||||
* BeanDefinition with the supplied BeanDefinitionRegistry.
|
||||
* @return the generated advice RootBeanDefinition
|
||||
*/
|
||||
@@ -427,7 +428,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the supplied <code><pointcut></code> and registers the resulting
|
||||
* Parses the supplied {@code <pointcut>} and registers the resulting
|
||||
* Pointcut with the BeanDefinitionRegistry.
|
||||
*/
|
||||
private AbstractBeanDefinition parsePointcut(Element pointcutElement, ParserContext parserContext) {
|
||||
@@ -435,7 +436,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
String expression = pointcutElement.getAttribute(EXPRESSION);
|
||||
|
||||
AbstractBeanDefinition pointcutDefinition = null;
|
||||
|
||||
|
||||
try {
|
||||
this.parseState.push(new PointcutEntry(id));
|
||||
pointcutDefinition = createPointcutDefinition(expression);
|
||||
@@ -460,8 +461,8 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the <code>pointcut</code> or <code>pointcut-ref</code> attributes of the supplied
|
||||
* {@link Element} and add a <code>pointcut</code> property as appropriate. Generates a
|
||||
* Parses the {@code pointcut} or {@code pointcut-ref} attributes of the supplied
|
||||
* {@link Element} and add a {@code pointcut} property as appropriate. Generates a
|
||||
* {@link org.springframework.beans.factory.config.BeanDefinition} for the pointcut if necessary
|
||||
* and returns its bean name, otherwise returns the bean name of the referred pointcut.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -57,6 +57,7 @@ public class MethodLocatingFactoryBean implements FactoryBean<Method>, BeanFacto
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
if (!StringUtils.hasText(this.targetBeanName)) {
|
||||
throw new IllegalArgumentException("Property 'targetBeanName' is required");
|
||||
@@ -78,14 +79,17 @@ public class MethodLocatingFactoryBean implements FactoryBean<Method>, BeanFacto
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Method getObject() throws Exception {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Method> getObjectType() {
|
||||
return Method.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,6 +46,7 @@ public class PointcutComponentDefinition extends AbstractComponentDefinition {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.pointcutBeanName;
|
||||
}
|
||||
@@ -60,6 +61,7 @@ public class PointcutComponentDefinition extends AbstractComponentDefinition {
|
||||
return new BeanDefinition[] {this.pointcutDefinition};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getSource() {
|
||||
return this.pointcutDefinition.getSource();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,7 @@ import org.springframework.beans.factory.parsing.ParseState;
|
||||
|
||||
/**
|
||||
* {@link ParseState} entry representing a pointcut.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
|
||||
/**
|
||||
* {@link BeanDefinitionDecorator} responsible for parsing the
|
||||
* <code><aop:scoped-proxy/></code> tag.
|
||||
* {@code <aop:scoped-proxy/>} tag.
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
@@ -39,6 +39,7 @@ class ScopedProxyBeanDefinitionDecorator implements BeanDefinitionDecorator {
|
||||
private static final String PROXY_TARGET_CLASS = "proxy-target-class";
|
||||
|
||||
|
||||
@Override
|
||||
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
|
||||
boolean proxyTargetClass = true;
|
||||
if (node instanceof Element) {
|
||||
@@ -47,7 +48,7 @@ class ScopedProxyBeanDefinitionDecorator implements BeanDefinitionDecorator {
|
||||
proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Register the original bean definition as it will be referenced by the scoped proxy
|
||||
// and is relevant for tooling (validation, navigation).
|
||||
BeanDefinitionHolder holder =
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,6 +47,7 @@ public class SimpleBeanFactoryAwareAspectInstanceFactory implements AspectInstan
|
||||
this.aspectBeanName = aspectBeanName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
if (!StringUtils.hasText(this.aspectBeanName)) {
|
||||
@@ -59,10 +60,12 @@ public class SimpleBeanFactoryAwareAspectInstanceFactory implements AspectInstan
|
||||
* Look up the aspect bean from the {@link BeanFactory} and returns it.
|
||||
* @see #setAspectBeanName
|
||||
*/
|
||||
@Override
|
||||
public Object getAspectInstance() {
|
||||
return this.beanFactory.getBean(this.aspectBeanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getAspectClassLoader() {
|
||||
if (this.beanFactory instanceof ConfigurableBeanFactory) {
|
||||
return ((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader();
|
||||
@@ -72,6 +75,7 @@ public class SimpleBeanFactoryAwareAspectInstanceFactory implements AspectInstan
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
if (this.beanFactory.isSingleton(this.aspectBeanName) &&
|
||||
this.beanFactory.isTypeMatch(this.aspectBeanName, Ordered.class)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,6 +50,7 @@ class SpringConfiguredBeanDefinitionParser implements BeanDefinitionParser {
|
||||
"org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect";
|
||||
|
||||
|
||||
@Override
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
if (!parserContext.getRegistry().containsBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME)) {
|
||||
RootBeanDefinition def = new RootBeanDefinition();
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.2
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class AbstractAdvisingBeanPostProcessor extends ProxyConfig
|
||||
implements BeanPostProcessor, BeanClassLoaderAware, Ordered {
|
||||
|
||||
@@ -49,6 +50,7 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyConfig
|
||||
private final Map<String, Boolean> eligibleBeans = new ConcurrentHashMap<String, Boolean>(64);
|
||||
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader beanClassLoader) {
|
||||
this.beanClassLoader = beanClassLoader;
|
||||
}
|
||||
@@ -57,15 +59,18 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyConfig
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) {
|
||||
if (bean instanceof AopInfrastructureBean) {
|
||||
// Ignore AOP infrastructure such as scoped proxies.
|
||||
@@ -93,7 +98,7 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyConfig
|
||||
/**
|
||||
* Check whether the given bean is eligible for advising with this
|
||||
* post-processor's {@link Advisor}.
|
||||
* <p>Implements caching of <code>canApply</code> results per bean name.
|
||||
* <p>Implements caching of {@code canApply} results per bean name.
|
||||
* @param bean the bean instance
|
||||
* @param beanName the name of the bean
|
||||
* @see AopUtils#canApply(Advisor, Class)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -122,6 +122,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
|
||||
this.proxyClassLoader = classLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
if (this.proxyClassLoader == null) {
|
||||
this.proxyClassLoader = classLoader;
|
||||
@@ -129,6 +130,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (this.target == null) {
|
||||
throw new IllegalArgumentException("Property 'target' is required");
|
||||
@@ -190,6 +192,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getObject() {
|
||||
if (this.proxy == null) {
|
||||
throw new FactoryBeanNotInitializedException();
|
||||
@@ -197,6 +200,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
|
||||
return this.proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
if (this.proxy != null) {
|
||||
return this.proxy.getClass();
|
||||
@@ -213,6 +217,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,7 +77,7 @@ public interface Advised extends TargetClassAware {
|
||||
* Set whether the proxy should be exposed by the AOP framework as a
|
||||
* ThreadLocal for retrieval via the AopContext class. This is useful
|
||||
* if an advised object needs to call another advised method on itself.
|
||||
* (If it uses <code>this</code>, the invocation will not be advised).
|
||||
* (If it uses {@code this}, the invocation will not be advised).
|
||||
* <p>Default is "false", for optimal performance.
|
||||
*/
|
||||
void setExposeProxy(boolean exposeProxy);
|
||||
@@ -85,7 +85,7 @@ public interface Advised extends TargetClassAware {
|
||||
/**
|
||||
* Return whether the factory should expose the proxy as a ThreadLocal.
|
||||
* This can be necessary if a target object needs to invoke a method on itself
|
||||
* benefitting from advice. (If it invokes a method on <code>this</code> no advice
|
||||
* benefitting from advice. (If it invokes a method on {@code this} no advice
|
||||
* will apply.) Getting the proxy is analogous to an EJB calling getEJBObject().
|
||||
* @see AopContext
|
||||
*/
|
||||
@@ -110,7 +110,7 @@ public interface Advised extends TargetClassAware {
|
||||
|
||||
/**
|
||||
* Return the advisors applying to this proxy.
|
||||
* @return a list of Advisors applying to this proxy (never <code>null</code>)
|
||||
* @return a list of Advisors applying to this proxy (never {@code null})
|
||||
*/
|
||||
Advisor[] getAdvisors();
|
||||
|
||||
@@ -124,7 +124,7 @@ public interface Advised extends TargetClassAware {
|
||||
*/
|
||||
void addAdvisor(Advisor advisor) throws AopConfigException;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add an Advisor at the specified position in the chain.
|
||||
* @param advisor the advisor to add at the specified position in the chain
|
||||
* @param pos position in chain (0 is head). Must be valid.
|
||||
@@ -135,7 +135,7 @@ public interface Advised extends TargetClassAware {
|
||||
/**
|
||||
* Remove the given advisor.
|
||||
* @param advisor the advisor to remove
|
||||
* @return <code>true</code> if the advisor was removed; <code>false</code>
|
||||
* @return {@code true} if the advisor was removed; {@code false}
|
||||
* if the advisor was not found and hence could not be removed
|
||||
*/
|
||||
boolean removeAdvisor(Advisor advisor);
|
||||
@@ -165,7 +165,7 @@ public interface Advised extends TargetClassAware {
|
||||
* @param a the advisor to replace
|
||||
* @param b the advisor to replace it with
|
||||
* @return whether it was replaced. If the advisor wasn't found in the
|
||||
* list of advisors, this method returns <code>false</code> and does nothing.
|
||||
* list of advisors, this method returns {@code false} and does nothing.
|
||||
* @throws AopConfigException in case of invalid advice
|
||||
*/
|
||||
boolean replaceAdvisor(Advisor a, Advisor b) throws AopConfigException;
|
||||
@@ -174,9 +174,9 @@ public interface Advised extends TargetClassAware {
|
||||
/**
|
||||
* Add the given AOP Alliance advice to the tail of the advice (interceptor) chain.
|
||||
* <p>This will be wrapped in a DefaultPointcutAdvisor with a pointcut that always
|
||||
* applies, and returned from the <code>getAdvisors()</code> method in this wrapped form.
|
||||
* applies, and returned from the {@code getAdvisors()} method in this wrapped form.
|
||||
* <p>Note that the given advice will apply to all invocations on the proxy,
|
||||
* even to the <code>toString()</code> method! Use appropriate advice implementations
|
||||
* even to the {@code toString()} method! Use appropriate advice implementations
|
||||
* or specify appropriate pointcuts to apply to a narrower set of methods.
|
||||
* @param advice advice to add to the tail of the chain
|
||||
* @throws AopConfigException in case of invalid advice
|
||||
@@ -191,7 +191,7 @@ public interface Advised extends TargetClassAware {
|
||||
* with a pointcut that always applies, and returned from the {@link #getAdvisors()}
|
||||
* method in this wrapped form.
|
||||
* <p>Note: The given advice will apply to all invocations on the proxy,
|
||||
* even to the <code>toString()</code> method! Use appropriate advice implementations
|
||||
* even to the {@code toString()} method! Use appropriate advice implementations
|
||||
* or specify appropriate pointcuts to apply to a narrower set of methods.
|
||||
* @param pos index from 0 (head)
|
||||
* @param advice advice to add at the specified position in the advice chain
|
||||
@@ -202,8 +202,8 @@ public interface Advised extends TargetClassAware {
|
||||
/**
|
||||
* Remove the Advisor containing the given advice.
|
||||
* @param advice the advice to remove
|
||||
* @return <code>true</code> of the advice was found and removed;
|
||||
* <code>false</code> if there was no such advice
|
||||
* @return {@code true} of the advice was found and removed;
|
||||
* {@code false} if there was no such advice
|
||||
*/
|
||||
boolean removeAdvice(Advice advice);
|
||||
|
||||
@@ -219,7 +219,7 @@ public interface Advised extends TargetClassAware {
|
||||
|
||||
|
||||
/**
|
||||
* As <code>toString()</code> will normally be delegated to the target,
|
||||
* As {@code toString()} will normally be delegated to the target,
|
||||
* this returns the equivalent for the AOP proxy.
|
||||
* @return a string description of the proxy configuration
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -137,10 +137,12 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
setTargetSource(new SingletonTargetSource(target));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTargetSource(TargetSource targetSource) {
|
||||
this.targetSource = (targetSource != null ? targetSource : EMPTY_TARGET_SOURCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetSource getTargetSource() {
|
||||
return this.targetSource;
|
||||
}
|
||||
@@ -162,14 +164,17 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
this.targetSource = EmptyTargetSource.forClass(targetClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getTargetClass() {
|
||||
return this.targetSource.getTargetClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPreFiltered(boolean preFiltered) {
|
||||
this.preFiltered = preFiltered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreFiltered() {
|
||||
return this.preFiltered;
|
||||
}
|
||||
@@ -184,7 +189,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the advisor chain factory to use (never <code>null</code>).
|
||||
* Return the advisor chain factory to use (never {@code null}).
|
||||
*/
|
||||
public AdvisorChainFactory getAdvisorChainFactory() {
|
||||
return this.advisorChainFactory;
|
||||
@@ -221,17 +226,19 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* Remove a proxied interface.
|
||||
* <p>Does nothing if the given interface isn't proxied.
|
||||
* @param intf the interface to remove from the proxy
|
||||
* @return <code>true</code> if the interface was removed; <code>false</code>
|
||||
* @return {@code true} if the interface was removed; {@code false}
|
||||
* if the interface was not found and hence could not be removed
|
||||
*/
|
||||
public boolean removeInterface(Class intf) {
|
||||
return this.interfaces.remove(intf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getProxiedInterfaces() {
|
||||
return this.interfaces.toArray(new Class[this.interfaces.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInterfaceProxied(Class intf) {
|
||||
for (Class proxyIntf : this.interfaces) {
|
||||
if (intf.isAssignableFrom(proxyIntf)) {
|
||||
@@ -242,15 +249,18 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Advisor[] getAdvisors() {
|
||||
return this.advisorArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAdvisor(Advisor advisor) {
|
||||
int pos = this.advisors.size();
|
||||
addAdvisor(pos, advisor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAdvisor(int pos, Advisor advisor) throws AopConfigException {
|
||||
if (advisor instanceof IntroductionAdvisor) {
|
||||
validateIntroductionAdvisor((IntroductionAdvisor) advisor);
|
||||
@@ -258,6 +268,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
addAdvisorInternal(pos, advisor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAdvisor(Advisor advisor) {
|
||||
int index = indexOf(advisor);
|
||||
if (index == -1) {
|
||||
@@ -269,6 +280,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAdvisor(int index) throws AopConfigException {
|
||||
if (isFrozen()) {
|
||||
throw new AopConfigException("Cannot remove Advisor: Configuration is frozen.");
|
||||
@@ -292,11 +304,13 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
adviceChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Advisor advisor) {
|
||||
Assert.notNull(advisor, "Advisor must not be null");
|
||||
return this.advisors.indexOf(advisor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceAdvisor(Advisor a, Advisor b) throws AopConfigException {
|
||||
Assert.notNull(a, "Advisor a must not be null");
|
||||
Assert.notNull(b, "Advisor b must not be null");
|
||||
@@ -388,6 +402,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addAdvice(Advice advice) throws AopConfigException {
|
||||
int pos = this.advisors.size();
|
||||
addAdvice(pos, advice);
|
||||
@@ -396,6 +411,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
/**
|
||||
* Cannot add introductions this way unless the advice implements IntroductionInfo.
|
||||
*/
|
||||
@Override
|
||||
public void addAdvice(int pos, Advice advice) throws AopConfigException {
|
||||
Assert.notNull(advice, "Advice must not be null");
|
||||
if (advice instanceof IntroductionInfo) {
|
||||
@@ -412,6 +428,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAdvice(Advice advice) throws AopConfigException {
|
||||
int index = indexOf(advice);
|
||||
if (index == -1) {
|
||||
@@ -423,6 +440,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Advice advice) {
|
||||
Assert.notNull(advice, "Advice must not be null");
|
||||
for (int i = 0; i < this.advisors.size(); i++) {
|
||||
@@ -554,6 +572,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toProxyConfigString() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.springframework.core.NestedRuntimeException;
|
||||
* @author Rod Johnson
|
||||
* @since 13.03.2003
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class AopConfigException extends NestedRuntimeException {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,9 +21,9 @@ import org.springframework.core.NamedThreadLocal;
|
||||
/**
|
||||
* Class containing static methods used to obtain information about the current AOP invocation.
|
||||
*
|
||||
* <p>The <code>currentProxy()</code> method is usable if the AOP framework is configured to
|
||||
* <p>The {@code currentProxy()} method is usable if the AOP framework is configured to
|
||||
* expose the current proxy (not the default). It returns the AOP proxy in use. Target objects
|
||||
* or advice can use this to make advised calls, in the same way as <code>getEJBObject()</code>
|
||||
* or advice can use this to make advised calls, in the same way as {@code getEJBObject()}
|
||||
* can be used in EJBs. They can also use it to find advice configuration.
|
||||
*
|
||||
* <p>Spring's AOP framework does not expose proxies by default, as there is a performance cost
|
||||
@@ -42,7 +42,7 @@ public abstract class AopContext {
|
||||
|
||||
/**
|
||||
* ThreadLocal holder for AOP proxy associated with this thread.
|
||||
* Will contain <code>null</code> unless the "exposeProxy" property on
|
||||
* Will contain {@code null} unless the "exposeProxy" property on
|
||||
* the controlling proxy configuration has been set to "true".
|
||||
* @see ProxyConfig#setExposeProxy
|
||||
*/
|
||||
@@ -53,7 +53,7 @@ public abstract class AopContext {
|
||||
* Try to return the current AOP proxy. This method is usable only if the
|
||||
* calling method has been invoked via AOP, and the AOP framework has been set
|
||||
* to expose proxies. Otherwise, this method will throw an IllegalStateException.
|
||||
* @return Object the current AOP proxy (never returns <code>null</code>)
|
||||
* @return Object the current AOP proxy (never returns {@code null})
|
||||
* @throws IllegalStateException if the proxy cannot be found, because the
|
||||
* method was invoked outside an AOP invocation context, or because the
|
||||
* AOP framework has not been configured to expose the proxy
|
||||
@@ -68,10 +68,10 @@ public abstract class AopContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the given proxy available via the <code>currentProxy()</code> method.
|
||||
* Make the given proxy available via the {@code currentProxy()} method.
|
||||
* <p>Note that the caller should be careful to keep the old value as appropriate.
|
||||
* @param proxy the proxy to expose (or <code>null</code> to reset it)
|
||||
* @return the old proxy, which may be <code>null</code> if none was bound
|
||||
* @param proxy the proxy to expose (or {@code null} to reset it)
|
||||
* @return the old proxy, which may be {@code null} if none was bound
|
||||
* @see #currentProxy()
|
||||
*/
|
||||
static Object setCurrentProxy(Object proxy) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,20 +33,20 @@ public interface AopProxy {
|
||||
* Create a new proxy object.
|
||||
* <p>Uses the AopProxy's default class loader (if necessary for proxy creation):
|
||||
* usually, the thread context class loader.
|
||||
* @return the new proxy object (never <code>null</code>)
|
||||
* @see java.lang.Thread#getContextClassLoader()
|
||||
* @return the new proxy object (never {@code null})
|
||||
* @see Thread#getContextClassLoader()
|
||||
*/
|
||||
Object getProxy();
|
||||
|
||||
/**
|
||||
* Create a new proxy object.
|
||||
* <p>Uses the given class loader (if necessary for proxy creation).
|
||||
* <code>null</code> will simply be passed down and thus lead to the low-level
|
||||
* {@code null} will simply be passed down and thus lead to the low-level
|
||||
* proxy facility's default, which is usually different from the default chosen
|
||||
* by the AopProxy implementation's {@link #getProxy()} method.
|
||||
* @param classLoader the class loader to create the proxy with
|
||||
* (or <code>null</code> for the low-level proxy facility's default)
|
||||
* @return the new proxy object (never <code>null</code>)
|
||||
* (or {@code null} for the low-level proxy facility's default)
|
||||
* @return the new proxy object (never {@code null})
|
||||
*/
|
||||
Object getProxy(ClassLoader classLoader);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,7 +35,7 @@ package org.springframework.aop.framework;
|
||||
*
|
||||
* <p>Proxies may or may not allow advice changes to be made.
|
||||
* If they do not permit advice changes (for example, because
|
||||
* the configuration was frozen) a proxy should throw an
|
||||
* the configuration was frozen) a proxy should throw an
|
||||
* {@link AopConfigException} on an attempted advice change.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,9 +44,9 @@ public abstract class AopProxyUtils {
|
||||
* as long as possible without side effects, that is, just for singleton targets.
|
||||
* @param candidate the instance to check (might be an AOP proxy)
|
||||
* @return the target class (or the plain class of the given object as fallback;
|
||||
* never <code>null</code>)
|
||||
* never {@code null})
|
||||
* @see org.springframework.aop.TargetClassAware#getTargetClass()
|
||||
* @see org.springframework.aop.framework.Advised#getTargetSource()
|
||||
* @see Advised#getTargetSource()
|
||||
*/
|
||||
public static Class<?> ultimateTargetClass(Object candidate) {
|
||||
Assert.notNull(candidate, "Candidate object must not be null");
|
||||
@@ -112,7 +112,7 @@ public abstract class AopProxyUtils {
|
||||
* i.e. all non-Advised interfaces that the proxy implements.
|
||||
* @param proxy the proxy to analyze (usually a JDK dynamic proxy)
|
||||
* @return all user-specified interfaces that the proxy implements,
|
||||
* in the original order (never <code>null</code> or empty)
|
||||
* in the original order (never {@code null} or empty)
|
||||
* @see Advised
|
||||
*/
|
||||
public static Class[] proxiedUserInterfaces(Object proxy) {
|
||||
|
||||
@@ -146,10 +146,12 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getProxy() {
|
||||
return getProxy(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProxy(ClassLoader classLoader) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Creating CGLIB proxy: target source is " + this.advised.getTargetSource());
|
||||
@@ -234,7 +236,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see whether the supplied <code>Class</code> has already been validated and
|
||||
* Checks to see whether the supplied {@code Class} has already been validated and
|
||||
* validates it if not.
|
||||
*/
|
||||
private void validateClassIfNecessary(Class<?> proxySuperClass) {
|
||||
@@ -249,7 +251,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for final methods on the <code>Class</code> and writes warnings to the log
|
||||
* Checks for final methods on the {@code Class} and writes warnings to the log
|
||||
* for each one found.
|
||||
*/
|
||||
private void doValidateClass(Class<?> proxySuperClass) {
|
||||
@@ -376,7 +378,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
* Method interceptor used for static targets with no advice chain. The call
|
||||
* is passed directly back to the target. Used when the proxy needs to be
|
||||
* exposed and it can't be determined that the method won't return
|
||||
* <code>this</code>.
|
||||
* {@code this}.
|
||||
*/
|
||||
private static class StaticUnadvisedInterceptor implements MethodInterceptor, Serializable {
|
||||
|
||||
@@ -386,6 +388,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
Object retVal = methodProxy.invoke(this.target, args);
|
||||
return processReturnType(proxy, this.target, method, retVal);
|
||||
@@ -405,6 +408,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
Object oldProxy = null;
|
||||
try {
|
||||
@@ -432,6 +436,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
this.targetSource = targetSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
Object target = this.targetSource.getTarget();
|
||||
try {
|
||||
@@ -456,6 +461,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
this.targetSource = targetSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
Object oldProxy = null;
|
||||
Object target = this.targetSource.getTarget();
|
||||
@@ -485,6 +491,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object loadObject() {
|
||||
return this.target;
|
||||
}
|
||||
@@ -502,6 +509,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
this.advised = advised;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object loadObject() throws Exception {
|
||||
return this.advised;
|
||||
}
|
||||
@@ -509,7 +517,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* Dispatcher for the <code>equals</code> method.
|
||||
* Dispatcher for the {@code equals} method.
|
||||
* Ensures that the method call is always handled by this class.
|
||||
*/
|
||||
private static class EqualsInterceptor implements MethodInterceptor, Serializable {
|
||||
@@ -520,6 +528,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
this.advised = advised;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) {
|
||||
Object other = args[0];
|
||||
if (proxy == other) {
|
||||
@@ -541,7 +550,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* Dispatcher for the <code>hashCode</code> method.
|
||||
* Dispatcher for the {@code hashCode} method.
|
||||
* Ensures that the method call is always handled by this class.
|
||||
*/
|
||||
private static class HashCodeInterceptor implements MethodInterceptor, Serializable {
|
||||
@@ -552,6 +561,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
this.advised = advised;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) {
|
||||
return CglibAopProxy.class.hashCode() * 13 + this.advised.getTargetSource().hashCode();
|
||||
}
|
||||
@@ -575,6 +585,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
this.targetClass = targetClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
MethodInvocation invocation = new CglibMethodInvocation(proxy, this.target, method, args,
|
||||
this.targetClass, this.adviceChain, methodProxy);
|
||||
@@ -598,6 +609,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
this.advised = advised;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
Object oldProxy = null;
|
||||
boolean setProxyContext = false;
|
||||
@@ -609,7 +621,7 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
oldProxy = AopContext.setCurrentProxy(proxy);
|
||||
setProxyContext = true;
|
||||
}
|
||||
// May be <code>null</code>. Get as late as possible to minimize the time we
|
||||
// May be null Get as late as possible to minimize the time we
|
||||
// "own" the target, in case it comes from a pool.
|
||||
target = getTarget();
|
||||
if (target != null) {
|
||||
@@ -745,15 +757,16 @@ final class CglibAopProxy implements AopProxy, Serializable {
|
||||
* invoke the advice chain. Otherwise a DyanmicAdvisedInterceptor is
|
||||
* used.</dd>
|
||||
* <dt>For non-advised methods:</dt>
|
||||
* <dd>Where it can be determined that the method will not return <code>this</code>
|
||||
* or when <code>ProxyFactory.getExposeProxy()</code> returns <code>false</code>,
|
||||
* <dd>Where it can be determined that the method will not return {@code this}
|
||||
* or when {@code ProxyFactory.getExposeProxy()} returns {@code false},
|
||||
* then a Dispatcher is used. For static targets, the StaticDispatcher is used;
|
||||
* and for dynamic targets, a DynamicUnadvisedInterceptor is used.
|
||||
* If it possible for the method to return <code>this</code> then a
|
||||
* If it possible for the method to return {@code this} then a
|
||||
* StaticUnadvisedInterceptor is used for static targets - the
|
||||
* DynamicUnadvisedInterceptor already considers this.</dd>
|
||||
* </dl>
|
||||
*/
|
||||
@Override
|
||||
public int accept(Method method) {
|
||||
if (AopUtils.isFinalizeMethod(method)) {
|
||||
logger.debug("Found finalize() method - using NO_OVERRIDE");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,8 +43,10 @@ import org.springframework.aop.support.MethodMatchers;
|
||||
* @author Adrian Colyer
|
||||
* @since 2.0.3
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializable {
|
||||
|
||||
@Override
|
||||
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(
|
||||
Advised config, Method method, Class targetClass) {
|
||||
|
||||
|
||||
@@ -45,9 +45,11 @@ import org.springframework.aop.SpringProxy;
|
||||
* @see AdvisedSupport#setProxyTargetClass
|
||||
* @see AdvisedSupport#setInterfaces
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {
|
||||
|
||||
|
||||
@Override
|
||||
public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException {
|
||||
if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) {
|
||||
Class targetClass = config.getTargetClass();
|
||||
|
||||
@@ -106,10 +106,12 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getProxy() {
|
||||
return getProxy(ClassUtils.getDefaultClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProxy(ClassLoader classLoader) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Creating JDK dynamic proxy: target source is " + this.advised.getTargetSource());
|
||||
@@ -143,10 +145,11 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of <code>InvocationHandler.invoke</code>.
|
||||
* Implementation of {@code InvocationHandler.invoke}.
|
||||
* <p>Callers will see exactly the exception thrown by the target,
|
||||
* unless a hook method throws an exception.
|
||||
*/
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
MethodInvocation invocation;
|
||||
Object oldProxy = null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -112,7 +112,7 @@ public class ProxyConfig implements Serializable {
|
||||
* Set whether the proxy should be exposed by the AOP framework as a
|
||||
* ThreadLocal for retrieval via the AopContext class. This is useful
|
||||
* if an advised object needs to call another advised method on itself.
|
||||
* (If it uses <code>this</code>, the invocation will not be advised).
|
||||
* (If it uses {@code this}, the invocation will not be advised).
|
||||
* <p>Default is "false", in order to avoid unnecessary extra interception.
|
||||
* This means that no guarantees are provided that AopContext access will
|
||||
* work consistently within any method of the advised object.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import org.springframework.util.Assert;
|
||||
* @since 2.0.3
|
||||
* @see #createAopProxy()
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ProxyCreatorSupport extends AdvisedSupport {
|
||||
|
||||
private AopProxyFactory aopProxyFactory;
|
||||
@@ -95,7 +96,7 @@ public class ProxyCreatorSupport extends AdvisedSupport {
|
||||
|
||||
/**
|
||||
* Subclasses should call this to get a new AOP proxy. They should <b>not</b>
|
||||
* create an AOP proxy with <code>this</code> as an argument.
|
||||
* create an AOP proxy with {@code this} as an argument.
|
||||
*/
|
||||
protected final synchronized AopProxy createAopProxy() {
|
||||
if (!this.active) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Rob Harrop
|
||||
* @since 14.03.2003
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ProxyFactory extends ProxyCreatorSupport {
|
||||
|
||||
/**
|
||||
@@ -74,7 +75,7 @@ public class ProxyFactory extends ProxyCreatorSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ProxyFactory for the specified <code>TargetSource</code>,
|
||||
* Create a ProxyFactory for the specified {@code TargetSource},
|
||||
* making the proxy implement the specified interface.
|
||||
* @param proxyInterface the interface that the proxy should implement
|
||||
* @param targetSource the TargetSource that the proxy should invoke
|
||||
@@ -103,7 +104,7 @@ public class ProxyFactory extends ProxyCreatorSupport {
|
||||
* or removed interfaces. Can add and remove interceptors.
|
||||
* <p>Uses the given class loader (if necessary for proxy creation).
|
||||
* @param classLoader the class loader to create the proxy with
|
||||
* (or <code>null</code> for the low-level proxy facility's default)
|
||||
* (or {@code null} for the low-level proxy facility's default)
|
||||
* @return the proxy object
|
||||
*/
|
||||
public Object getProxy(ClassLoader classLoader) {
|
||||
@@ -127,7 +128,7 @@ public class ProxyFactory extends ProxyCreatorSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a proxy for the specified <code>TargetSource</code>,
|
||||
* Create a proxy for the specified {@code TargetSource},
|
||||
* implementing the specified interface.
|
||||
* @param proxyInterface the interface that the proxy should implement
|
||||
* @param targetSource the TargetSource that the proxy should invoke
|
||||
@@ -140,8 +141,8 @@ public class ProxyFactory extends ProxyCreatorSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a proxy for the specified <code>TargetSource</code> that extends
|
||||
* the target class of the <code>TargetSource</code>.
|
||||
* Create a proxy for the specified {@code TargetSource} that extends
|
||||
* the target class of the {@code TargetSource}.
|
||||
* @param targetSource the TargetSource that the proxy should invoke
|
||||
* @return the proxy object
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -88,6 +88,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @see org.springframework.aop.Advisor
|
||||
* @see Advised
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
implements FactoryBean<Object>, BeanClassLoaderAware, BeanFactoryAware {
|
||||
|
||||
@@ -100,7 +101,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private String[] interceptorNames;
|
||||
|
||||
|
||||
private String targetName;
|
||||
|
||||
private boolean autodetectInterfaces = true;
|
||||
@@ -217,12 +218,14 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
this.classLoaderConfigured = (classLoader != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
if (!this.classLoaderConfigured) {
|
||||
this.proxyClassLoader = classLoader;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
checkInterceptorNames();
|
||||
@@ -233,9 +236,10 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
* Return a proxy. Invoked when clients obtain beans from this factory bean.
|
||||
* Create an instance of the AOP proxy to be returned by this factory.
|
||||
* The instance will be cached for a singleton, and create on each call to
|
||||
* <code>getObject()</code> for a proxy.
|
||||
* {@code getObject()} for a proxy.
|
||||
* @return a fresh AOP proxy reflecting the current state of this factory
|
||||
*/
|
||||
@Override
|
||||
public Object getObject() throws BeansException {
|
||||
initializeAdvisorChain();
|
||||
if (isSingleton()) {
|
||||
@@ -256,6 +260,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
* a single one), the target bean type, or the TargetSource's target class.
|
||||
* @see org.springframework.aop.TargetSource#getTargetClass
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
synchronized (this) {
|
||||
if (this.singletonInstance != null) {
|
||||
@@ -277,6 +282,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return this.singleton;
|
||||
}
|
||||
@@ -351,7 +357,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
|
||||
/**
|
||||
* Return the proxy object to expose.
|
||||
* <p>The default implementation uses a <code>getProxy</code> call with
|
||||
* <p>The default implementation uses a {@code getProxy} call with
|
||||
* the factory's bean class loader. Can be overridden to specify a
|
||||
* custom class loader.
|
||||
* @param aopProxy the prepared AopProxy instance to get the proxy from
|
||||
@@ -392,7 +398,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
* which concludes the interceptorNames list, is an Advisor or Advice,
|
||||
* or may be a target.
|
||||
* @param beanName bean name to check
|
||||
* @return <code>true</code> if it's an Advisor or Advice
|
||||
* @return {@code true} if it's an Advisor or Advice
|
||||
*/
|
||||
private boolean isNamedBeanAnAdvisorOrAdvice(String beanName) {
|
||||
Class namedBeanClass = this.beanFactory.getType(beanName);
|
||||
@@ -543,10 +549,10 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
Advisor advisor = namedBeanToAdvisor(next);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Adding advisor with name '" + name + "'");
|
||||
}
|
||||
}
|
||||
addAdvisor(advisor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a TargetSource to use when creating a proxy. If the target was not
|
||||
* specified at the end of the interceptorNames list, the TargetSource will be
|
||||
@@ -627,24 +633,26 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
private final String beanName;
|
||||
|
||||
private final String message;
|
||||
|
||||
|
||||
public PrototypePlaceholderAdvisor(String beanName) {
|
||||
this.beanName = beanName;
|
||||
this.message = "Placeholder for prototype Advisor/Advice with bean name '" + beanName + "'";
|
||||
}
|
||||
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Advice getAdvice() {
|
||||
throw new UnsupportedOperationException("Cannot invoke methods: " + this.message);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isPerInstance() {
|
||||
throw new UnsupportedOperationException("Cannot invoke methods: " + this.message);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.message;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -114,14 +114,17 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Object getProxy() {
|
||||
return this.proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object getThis() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AccessibleObject getStaticPart() {
|
||||
return this.method;
|
||||
}
|
||||
@@ -131,19 +134,23 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||
* May or may not correspond with a method invoked on an underlying
|
||||
* implementation of that interface.
|
||||
*/
|
||||
@Override
|
||||
public final Method getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object[] getArguments() {
|
||||
return (this.arguments != null ? this.arguments : new Object[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArguments(Object[] arguments) {
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object proceed() throws Throwable {
|
||||
// We start with an index of -1 and increment early.
|
||||
if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) {
|
||||
@@ -151,12 +158,12 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||
}
|
||||
|
||||
Object interceptorOrInterceptionAdvice =
|
||||
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex);
|
||||
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex);
|
||||
if (interceptorOrInterceptionAdvice instanceof InterceptorAndDynamicMethodMatcher) {
|
||||
// Evaluate dynamic method matcher here: static part will already have
|
||||
// been evaluated and found to match.
|
||||
InterceptorAndDynamicMethodMatcher dm =
|
||||
(InterceptorAndDynamicMethodMatcher) interceptorOrInterceptionAdvice;
|
||||
(InterceptorAndDynamicMethodMatcher) interceptorOrInterceptionAdvice;
|
||||
if (dm.methodMatcher.matches(this.method, this.targetClass, this.arguments)) {
|
||||
return dm.interceptor.invoke(this);
|
||||
}
|
||||
@@ -192,6 +199,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||
* current interceptor index.
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
public MethodInvocation invocableClone() {
|
||||
Object[] cloneArguments = null;
|
||||
if (this.arguments != null) {
|
||||
@@ -210,6 +218,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||
* current interceptor index.
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
public MethodInvocation invocableClone(Object[] arguments) {
|
||||
// Force initialization of the user attributes Map,
|
||||
// for having a shared Map reference in the clone.
|
||||
@@ -230,6 +239,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setUserAttribute(String key, Object value) {
|
||||
if (value != null) {
|
||||
if (this.userAttributes == null) {
|
||||
@@ -244,6 +254,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getUserAttribute(String key) {
|
||||
return (this.userAttributes != null ? this.userAttributes.get(key) : null);
|
||||
}
|
||||
@@ -253,7 +264,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||
* This method provides an invocation-bound alternative to a ThreadLocal.
|
||||
* <p>This map is initialized lazily and is not used in the AOP framework itself.
|
||||
* @return any user attributes associated with this invocation
|
||||
* (never <code>null</code>)
|
||||
* (never {@code null})
|
||||
*/
|
||||
public Map<String, Object> getUserAttributes() {
|
||||
if (this.userAttributes == null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,7 +38,7 @@ public interface AdvisorAdapter {
|
||||
|
||||
/**
|
||||
* Does this adapter understand this advice object? Is it valid to
|
||||
* invoke the <code>getInterceptors</code> method with an Advisor that
|
||||
* invoke the {@code getInterceptors} method with an Advisor that
|
||||
* contains this advice as an argument?
|
||||
* @param advice an Advice such as a BeforeAdvice
|
||||
* @return whether this adapter understands the given advice object
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,10 +48,12 @@ public class AdvisorAdapterRegistrationManager implements BeanPostProcessor {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof AdvisorAdapter){
|
||||
this.advisorAdapterRegistry.registerAdvisorAdapter((AdvisorAdapter) bean);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,7 +38,7 @@ public interface AdvisorAdapterRegistry {
|
||||
* {@link org.springframework.aop.AfterReturningAdvice},
|
||||
* {@link org.springframework.aop.ThrowsAdvice}.
|
||||
* @param advice object that should be an advice
|
||||
* @return an Advisor wrapping the given advice. Never returns <code>null</code>.
|
||||
* @return an Advisor wrapping the given advice. Never returns {@code null}.
|
||||
* If the advice parameter is an Advisor, return it.
|
||||
* @throws UnknownAdviceTypeException if no registered advisor adapter
|
||||
* can wrap the supposed advice
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,12 +31,15 @@ import org.springframework.aop.AfterReturningAdvice;
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class AfterReturningAdviceAdapter implements AdvisorAdapter, Serializable {
|
||||
|
||||
@Override
|
||||
public boolean supportsAdvice(Advice advice) {
|
||||
return (advice instanceof AfterReturningAdvice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodInterceptor getInterceptor(Advisor advisor) {
|
||||
AfterReturningAdvice advice = (AfterReturningAdvice) advisor.getAdvice();
|
||||
return new AfterReturningAdviceInterceptor(advice);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class AfterReturningAdviceInterceptor implements MethodInterceptor, AfterAdvice, Serializable {
|
||||
|
||||
private final AfterReturningAdvice advice;
|
||||
@@ -46,6 +47,7 @@ public class AfterReturningAdviceInterceptor implements MethodInterceptor, After
|
||||
this.advice = advice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
Object retVal = mi.proceed();
|
||||
this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,6 +37,7 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Serializable {
|
||||
|
||||
private final List<AdvisorAdapter> adapters = new ArrayList<AdvisorAdapter>(3);
|
||||
@@ -52,6 +53,7 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Advisor wrap(Object adviceObject) throws UnknownAdviceTypeException {
|
||||
if (adviceObject instanceof Advisor) {
|
||||
return (Advisor) adviceObject;
|
||||
@@ -73,6 +75,7 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se
|
||||
throw new UnknownAdviceTypeException(advice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException {
|
||||
List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>(3);
|
||||
Advice advice = advisor.getAdvice();
|
||||
@@ -90,6 +93,7 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se
|
||||
return interceptors.toArray(new MethodInterceptor[interceptors.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerAdvisorAdapter(AdvisorAdapter adapter) {
|
||||
this.adapters.add(adapter);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,12 +31,15 @@ import org.springframework.aop.MethodBeforeAdvice;
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
class MethodBeforeAdviceAdapter implements AdvisorAdapter, Serializable {
|
||||
|
||||
@Override
|
||||
public boolean supportsAdvice(Advice advice) {
|
||||
return (advice instanceof MethodBeforeAdvice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodInterceptor getInterceptor(Advisor advisor) {
|
||||
MethodBeforeAdvice advice = (MethodBeforeAdvice) advisor.getAdvice();
|
||||
return new MethodBeforeAdviceInterceptor(advice);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class MethodBeforeAdviceInterceptor implements MethodInterceptor, Serializable {
|
||||
|
||||
private MethodBeforeAdvice advice;
|
||||
@@ -45,6 +46,7 @@ public class MethodBeforeAdviceInterceptor implements MethodInterceptor, Seriali
|
||||
this.advice = advice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis() );
|
||||
return mi.proceed();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user