15 changed files with 756 additions and 0 deletions
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project name="org.springframework.aspects"> |
||||
<property file="${basedir}/../build.properties"/> |
||||
<import file="${basedir}/../build-spring-framework/package-bundle.xml"/> |
||||
<import file="${basedir}/../spring-build/aspect/default.xml"/> |
||||
</project> |
||||
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?> |
||||
<ivy-module |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:noNamespaceSchemaLocation="http://incubator.apache.org/ivy/schemas/ivy.xsd" |
||||
version="1.3"> |
||||
|
||||
<info organisation="org.springframework" module="${ant.project.name}"> |
||||
<license name="Apache 2.0" url="http://www.apache.org/licenses/LICENSE-2.0"/> |
||||
</info> |
||||
|
||||
<configurations> |
||||
<include file="${spring.build.dir}/common/default-ivy-configurations.xml"/> |
||||
<conf name="aspectj" extends="runtime" description="JARs needed to run with AspectJ"/> |
||||
<conf name="tx" extends="runtime" description="JARs needed to run transactional aspects"/> |
||||
</configurations> |
||||
|
||||
<publications> |
||||
<artifact name="${ant.project.name}"/> |
||||
<artifact name="${ant.project.name}-sources" type="src" ext="jar"/> |
||||
</publications> |
||||
|
||||
<dependencies> |
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.logging" rev="1.1.1" conf="compile->compile"/> |
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.5.4" conf="optional, aspectj->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.beans" rev="latest.integration" conf="compile->compile"/> |
||||
<dependency org="org.springframework" name="org.springframework.transaction" rev="latest.integration" conf="optional, tx->compile"/> |
||||
</dependencies> |
||||
|
||||
</ivy-module> |
||||
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<groupId>org.springframework</groupId> |
||||
<artifactId>org.springframework.core</artifactId> |
||||
<packaging>jar</packaging> |
||||
<name>Spring Core Abstractions and Utilities</name> |
||||
<version>3.0.0.M1</version> |
||||
<repositories> |
||||
<repository> |
||||
<id>com.springsource.repository.bundles.external</id> |
||||
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name> |
||||
<url>http://repository.springsource.com/maven/bundles/external</url> |
||||
</repository> |
||||
</repositories> |
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<configuration> |
||||
<source>1.5</source> |
||||
<target>1.5</target> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>com.springsource.org.apache.commons.logging</artifactId> |
||||
<version>1.1.1</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.log4j</groupId> |
||||
<artifactId>com.springsource.org.apache.log4j</artifactId> |
||||
<version>1.2.15</version> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>com.springsource.org.apache.commons.collections</artifactId> |
||||
<version>3.2.0</version> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.aspectj</groupId> |
||||
<artifactId>com.springsource.org.aspectj.weaver</artifactId> |
||||
<version>1.6.2.RELEASE</version> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.objectweb.asm</groupId> |
||||
<artifactId>com.springsource.org.objectweb.asm.commons</artifactId> |
||||
<version>2.2.3</version> |
||||
<optional>true</optional> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
||||
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
/* |
||||
* Copyright 2002-2008 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. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans.factory.aspectj; |
||||
|
||||
import org.aspectj.lang.annotation.SuppressAjWarnings; |
||||
import org.springframework.beans.factory.wiring.BeanConfigurerSupport; |
||||
|
||||
/** |
||||
* Abstract superaspect for AspectJ aspects that can perform Dependency |
||||
* Injection on objects, however they may be created. Define the beanCreation() |
||||
* pointcut in subaspects. |
||||
* |
||||
* <p>Subaspects may also need a metadata resolution strategy, in the |
||||
* <code>BeanWiringInfoResolver</code> interface. The default implementation |
||||
* looks for a bean with the same name as the FQN. This is the default name |
||||
* of a bean in a Spring container if the id value is not supplied explicitly. |
||||
* |
||||
* @author Rob Harrop |
||||
* @author Rod Johnson |
||||
* @author Adrian Colyer |
||||
* @author Ramnivas Laddad |
||||
* @since 2.0 |
||||
* @deprecated as of Spring 2.5.2. |
||||
* Use AbstractDependencyInjectionAspect or its subaspects instead. |
||||
*/ |
||||
public abstract aspect AbstractBeanConfigurerAspect extends BeanConfigurerSupport { |
||||
|
||||
/** |
||||
* Configured bean before initialization. |
||||
*/ |
||||
@SuppressAjWarnings("adviceDidNotMatch") |
||||
before(Object beanInstance) : beanInitialization(beanInstance) { |
||||
if (preConstructionConfiguration(beanInstance)) { |
||||
configureBean(beanInstance); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Configured bean after construction. |
||||
*/ |
||||
@SuppressAjWarnings("adviceDidNotMatch") |
||||
after(Object beanInstance) returning : beanCreation(beanInstance) { |
||||
if (!preConstructionConfiguration(beanInstance)) { |
||||
configureBean(beanInstance); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* The initialization of a new object. |
||||
* |
||||
* <p>WARNING: Although this pointcut is non-abstract for backwards |
||||
* compatibility reasons, it is meant to be overridden to select |
||||
* initialization of any configurable bean. |
||||
*/ |
||||
protected pointcut beanInitialization(Object beanInstance); |
||||
|
||||
/** |
||||
* The creation of a new object. |
||||
*/ |
||||
protected abstract pointcut beanCreation(Object beanInstance); |
||||
|
||||
|
||||
/** |
||||
* Are dependencies to be injected prior to the construction of an object? |
||||
*/ |
||||
protected boolean preConstructionConfiguration(Object beanInstance) { |
||||
return false; // matches the default in the @Configurable annotation |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,101 @@
@@ -0,0 +1,101 @@
|
||||
/* |
||||
* Copyright 2002-2008 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. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans.factory.aspectj; |
||||
|
||||
import org.aspectj.lang.annotation.SuppressAjWarnings; |
||||
|
||||
/** |
||||
* Abstract base aspect that can perform Dependency |
||||
* Injection on objects, however they may be created. |
||||
* |
||||
* @author Ramnivas Laddad |
||||
* @since 2.5.2 |
||||
*/ |
||||
public abstract aspect AbstractDependencyInjectionAspect { |
||||
/** |
||||
* Select construction join points for objects to inject dependencies |
||||
*/ |
||||
public abstract pointcut beanConstruction(Object bean); |
||||
|
||||
/** |
||||
* Select deserialization join points for objects to inject dependencies |
||||
*/ |
||||
public abstract pointcut beanDeserialization(Object bean); |
||||
|
||||
/** |
||||
* Select join points in a configurable bean |
||||
*/ |
||||
public abstract pointcut inConfigurableBean(); |
||||
|
||||
/** |
||||
* Select join points in beans to be configured prior to construction? |
||||
* By default, use post-construction injection matching the default in the Configurable annotation. |
||||
*/ |
||||
public pointcut preConstructionConfiguration() : if(false); |
||||
|
||||
/** |
||||
* Select the most-specific initialization join point |
||||
* (most concrete class) for the initialization of an instance. |
||||
*/ |
||||
public pointcut mostSpecificSubTypeConstruction() : |
||||
if(thisJoinPoint.getSignature().getDeclaringType() == thisJoinPoint.getThis().getClass()); |
||||
|
||||
/** |
||||
* Select least specific super type that is marked for DI (so that injection occurs only once with pre-construction inejection |
||||
*/ |
||||
public abstract pointcut leastSpecificSuperTypeConstruction(); |
||||
|
||||
/** |
||||
* Configure the bean |
||||
*/ |
||||
public abstract void configureBean(Object bean); |
||||
|
||||
|
||||
private pointcut preConstructionCondition() : |
||||
leastSpecificSuperTypeConstruction() && preConstructionConfiguration(); |
||||
|
||||
private pointcut postConstructionCondition() : |
||||
mostSpecificSubTypeConstruction() && !preConstructionConfiguration(); |
||||
|
||||
/** |
||||
* Pre-construction configuration. |
||||
*/ |
||||
@SuppressAjWarnings("adviceDidNotMatch") |
||||
before(Object bean) : |
||||
beanConstruction(bean) && preConstructionCondition() && inConfigurableBean() { |
||||
configureBean(bean); |
||||
} |
||||
|
||||
/** |
||||
* Post-construction configuration. |
||||
*/ |
||||
@SuppressAjWarnings("adviceDidNotMatch") |
||||
after(Object bean) returning : |
||||
beanConstruction(bean) && postConstructionCondition() && inConfigurableBean() { |
||||
configureBean(bean); |
||||
} |
||||
|
||||
/** |
||||
* Post-deserialization configuration. |
||||
*/ |
||||
@SuppressAjWarnings("adviceDidNotMatch") |
||||
after(Object bean) returning : |
||||
beanDeserialization(bean) && inConfigurableBean() { |
||||
configureBean(bean); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,124 @@
@@ -0,0 +1,124 @@
|
||||
/* |
||||
* Copyright 2002-2008 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. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans.factory.aspectj; |
||||
|
||||
import java.io.ObjectStreamException; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* An aspect that injects dependency into any object whose type implements the {@link ConfigurableObject} interface. |
||||
* <p> |
||||
* This aspect supports injecting into domain objects when they are created for the first time as well as |
||||
* upon deserialization. Subaspects need to simply provide definition for the configureBean() method. This |
||||
* method may be implemented without relying on Spring container if so desired. |
||||
* </p> |
||||
* <p> |
||||
* There are two cases that needs to be handled: |
||||
* <ol> |
||||
* <li>Normal object creation via the '<code>new</code>' operator: this is |
||||
* taken care of by advising <code>initialization()</code> join points.</li> |
||||
* <li>Object creation through deserialization: since no constructor is |
||||
* invoked during deserialization, the aspect needs to advise a method that a |
||||
* deserialization mechanism is going to invoke. Ideally, we should not |
||||
* require user classes to implement any specific method. This implies that |
||||
* we need to <i>introduce</i> the chosen method. We should also handle the cases |
||||
* where the chosen method is already implemented in classes (in which case, |
||||
* the user's implementation for that method should take precedence over the |
||||
* introduced implementation). There are a few choices for the chosen method: |
||||
* <ul> |
||||
* <li>readObject(ObjectOutputStream): Java requires that the method must be |
||||
* <code>private</p>. Since aspects cannot introduce a private member, |
||||
* while preserving its name, this option is ruled out.</li> |
||||
* <li>readResolve(): Java doesn't pose any restriction on an access specifier. |
||||
* Problem solved! There is one (minor) limitation of this approach in |
||||
* that if a user class already has this method, that method must be |
||||
* <code>public</code>. However, this shouldn't be a big burden, since |
||||
* use cases that need classes to implement readResolve() (custom enums, |
||||
* for example) are unlikely to be marked as @Configurable, and |
||||
* in any case asking to make that method <code>public</code> should not |
||||
* pose any undue burden.</li> |
||||
* </ul> |
||||
* The minor collaboration needed by user classes (i.e., that the |
||||
* implementation of <code>readResolve()</code>, if any, must be |
||||
* <code>public</code>) can be lifted as well if we were to use an |
||||
* experimental feature in AspectJ - the <code>hasmethod()</code> PCD.</li> |
||||
* </ol> |
||||
|
||||
* <p> |
||||
* While having type implement the {@link ConfigurableObject} interface is certainly a valid choice, an alternative |
||||
* is to use a 'declare parents' statement another aspect (a subaspect of this aspect would be a logical choice) |
||||
* that declares the classes that need to be configured by supplying the {@link ConfigurableObject} interface. |
||||
* </p> |
||||
* |
||||
* @author Ramnivas Laddad |
||||
* @since 2.5.2 |
||||
*/ |
||||
public abstract aspect AbstractInterfaceDrivenDependencyInjectionAspect extends AbstractDependencyInjectionAspect { |
||||
/** |
||||
* Select initialization join point as object construction |
||||
*/ |
||||
public pointcut beanConstruction(Object bean) : |
||||
initialization(ConfigurableObject+.new(..)) && this(bean); |
||||
|
||||
/** |
||||
* Select deserialization join point made available through ITDs for ConfigurableDeserializationSupport |
||||
*/ |
||||
public pointcut beanDeserialization(Object bean) : |
||||
execution(Object ConfigurableDeserializationSupport+.readResolve()) && |
||||
this(bean); |
||||
|
||||
public pointcut leastSpecificSuperTypeConstruction() : initialization(ConfigurableObject.new(..)); |
||||
|
||||
|
||||
|
||||
// Implementation to support re-injecting dependencies once an object is deserialized |
||||
/** |
||||
* Declare any class implementing Serializable and ConfigurableObject as also implementing |
||||
* ConfigurableDeserializationSupport. This allows us to introduce the readResolve() |
||||
* method and select it with the beanDeserialization() pointcut. |
||||
* |
||||
* <p>Here is an improved version that uses the hasmethod() pointcut and lifts |
||||
* even the minor requirement on user classes: |
||||
* |
||||
* <pre class="code">declare parents: ConfigurableObject+ Serializable+ |
||||
* && !hasmethod(Object readResolve() throws ObjectStreamException) |
||||
* implements ConfigurableDeserializationSupport; |
||||
* </pre> |
||||
*/ |
||||
declare parents: |
||||
ConfigurableObject+ && Serializable+ implements ConfigurableDeserializationSupport; |
||||
|
||||
/** |
||||
* A marker interface to which the <code>readResolve()</code> is introduced. |
||||
*/ |
||||
static interface ConfigurableDeserializationSupport extends Serializable { |
||||
} |
||||
|
||||
/** |
||||
* Introduce the <code>readResolve()</code> method so that we can advise its |
||||
* execution to configure the object. |
||||
* |
||||
* <p>Note if a method with the same signature already exists in a |
||||
* <code>Serializable</code> class of ConfigurableObject type, |
||||
* that implementation will take precedence (a good thing, since we are |
||||
* merely interested in an opportunity to detect deserialization.) |
||||
*/ |
||||
public Object ConfigurableDeserializationSupport.readResolve() throws ObjectStreamException { |
||||
return this; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
/* |
||||
* Copyright 2002-2008 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. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.beans.factory.aspectj; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import org.springframework.beans.BeansException; |
||||
import org.springframework.beans.factory.BeanFactory; |
||||
import org.springframework.beans.factory.BeanFactoryAware; |
||||
import org.springframework.beans.factory.DisposableBean; |
||||
import org.springframework.beans.factory.InitializingBean; |
||||
import org.springframework.beans.factory.annotation.AnnotationBeanWiringInfoResolver; |
||||
import org.springframework.beans.factory.annotation.Configurable; |
||||
import org.springframework.beans.factory.wiring.BeanConfigurerSupport; |
||||
|
||||
/** |
||||
* Concrete aspect that uses the {@link Configurable} |
||||
* annotation to identify which classes need autowiring. |
||||
* |
||||
* <p>The bean name to look up will be taken from the |
||||
* <code>@Configurable</code> annotation if specified, otherwise the |
||||
* default bean name to look up will be the FQN of the class being configured. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Ramnivas Laddad |
||||
* @author Juergen Hoeller |
||||
* @author Adrian Colyer |
||||
* @since 2.0 |
||||
* @see org.springframework.beans.factory.annotation.Configurable |
||||
* @see org.springframework.beans.factory.annotation.AnnotationBeanWiringInfoResolver |
||||
*/ |
||||
public aspect AnnotationBeanConfigurerAspect |
||||
extends AbstractInterfaceDrivenDependencyInjectionAspect |
||||
implements BeanFactoryAware, InitializingBean, DisposableBean { |
||||
|
||||
private BeanConfigurerSupport beanConfigurerSupport = new BeanConfigurerSupport(); |
||||
|
||||
public pointcut inConfigurableBean() : @this(Configurable); |
||||
|
||||
public pointcut preConstructionConfiguration() : preConstructionConfigurationSupport(*); |
||||
|
||||
declare parents: @Configurable * implements ConfigurableObject; |
||||
|
||||
public void configureBean(Object bean) { |
||||
beanConfigurerSupport.configureBean(bean); |
||||
} |
||||
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { |
||||
beanConfigurerSupport.setBeanFactory(beanFactory); |
||||
beanConfigurerSupport.setBeanWiringInfoResolver(new AnnotationBeanWiringInfoResolver()); |
||||
} |
||||
|
||||
public void afterPropertiesSet() throws Exception { |
||||
beanConfigurerSupport.afterPropertiesSet(); |
||||
} |
||||
|
||||
public void destroy() throws Exception { |
||||
beanConfigurerSupport.destroy(); |
||||
} |
||||
|
||||
|
||||
/* |
||||
* An intermediary to match preConstructionConfiguration signature (that doesn't expose the annotation object) |
||||
*/ |
||||
private pointcut preConstructionConfigurationSupport(Configurable c) : @this(c) && if(c.preConstruction()); |
||||
|
||||
/* |
||||
* This declaration shouldn't be needed, |
||||
* except for an AspectJ bug (https://bugs.eclipse.org/bugs/show_bug.cgi?id=214559) |
||||
*/ |
||||
declare parents: @Configurable Serializable+ |
||||
implements ConfigurableDeserializationSupport; |
||||
|
||||
} |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
/* |
||||
* Copyright 2002-2008 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. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.beans.factory.aspectj; |
||||
|
||||
/** |
||||
* Marker interface for domain object that need DI through aspects. |
||||
* |
||||
* @author Ramnivas Laddad |
||||
* @since 2.5 |
||||
*/ |
||||
public interface ConfigurableObject { |
||||
|
||||
} |
||||
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
/* |
||||
* Copyright 2002-2007 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. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.transaction.aspectj; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
import org.aspectj.lang.annotation.SuppressAjWarnings; |
||||
import org.aspectj.lang.reflect.MethodSignature; |
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
||||
import org.springframework.transaction.interceptor.TransactionAttributeSource; |
||||
|
||||
/** |
||||
* Abstract superaspect for AspectJ transaction aspects. Concrete |
||||
* subaspects will implement the <code>transactionalMethodExecution()</code> |
||||
* pointcut using a strategy such as Java 5 annotations. |
||||
* |
||||
* <p>Suitable for use inside or outside the Spring IoC container. |
||||
* Set the "transactionManager" property appropriately, allowing |
||||
* use of any transaction implementation supported by Spring. |
||||
* |
||||
* <p><b>NB:</b> If a method implements an interface that is itself |
||||
* transactionally annotated, the relevant Spring transaction attribute |
||||
* will <i>not</i> be resolved. This behavior will vary from that of Spring AOP |
||||
* if proxying an interface (but not when proxying a class). We recommend that |
||||
* transaction annotations should be added to classes, rather than business |
||||
* interfaces, as they are an implementation detail rather than a contract |
||||
* specification validation. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Ramnivas Laddad |
||||
* @since 2.0 |
||||
*/ |
||||
public abstract aspect AbstractTransactionAspect extends TransactionAspectSupport { |
||||
|
||||
/** |
||||
* Construct object using the given transaction metadata retrieval strategy. |
||||
* @param tas TransactionAttributeSource implementation, retrieving Spring |
||||
* transaction metadata for each joinpoint. Write the subclass to pass in null |
||||
* if it's intended to be configured by Setter Injection. |
||||
*/ |
||||
protected AbstractTransactionAspect(TransactionAttributeSource tas) { |
||||
setTransactionAttributeSource(tas); |
||||
} |
||||
|
||||
@SuppressAjWarnings("adviceDidNotMatch") |
||||
before(Object txObject) : transactionalMethodExecution(txObject) { |
||||
MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getSignature(); |
||||
Method method = methodSignature.getMethod(); |
||||
TransactionInfo txInfo = createTransactionIfNecessary(method, txObject.getClass()); |
||||
} |
||||
|
||||
@SuppressAjWarnings("adviceDidNotMatch") |
||||
after(Object txObject) throwing(Throwable t) : transactionalMethodExecution(txObject) { |
||||
try { |
||||
completeTransactionAfterThrowing(TransactionAspectSupport.currentTransactionInfo(), t); |
||||
} |
||||
catch (Throwable t2) { |
||||
logger.error("Failed to close transaction after throwing in a transactional method", t2); |
||||
} |
||||
} |
||||
|
||||
@SuppressAjWarnings("adviceDidNotMatch") |
||||
after(Object txObject) returning() : transactionalMethodExecution(txObject) { |
||||
commitTransactionAfterReturning(TransactionAspectSupport.currentTransactionInfo()); |
||||
} |
||||
|
||||
@SuppressAjWarnings("adviceDidNotMatch") |
||||
after(Object txObject) : transactionalMethodExecution(txObject) { |
||||
cleanupTransactionInfo(TransactionAspectSupport.currentTransactionInfo()); |
||||
} |
||||
|
||||
/** |
||||
* Concrete subaspects must implement this pointcut, to identify |
||||
* transactional methods. For each selected joinpoint, TransactionMetadata |
||||
* will be retrieved using Spring's TransactionAttributeSource interface. |
||||
*/ |
||||
protected abstract pointcut transactionalMethodExecution(Object txObject); |
||||
|
||||
} |
||||
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
/* |
||||
* Copyright 2002-2008 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. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.transaction.aspectj; |
||||
|
||||
import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
/** |
||||
* Concrete AspectJ transaction aspect using Spring Transactional annotation |
||||
* for JDK 1.5+. |
||||
* |
||||
* <p>When using this aspect, you <i>must</i> annotate the implementation class |
||||
* (and/or methods within that class), <i>not</i> the interface (if any) that |
||||
* the class implements. AspectJ follows Java's rule that annotations on |
||||
* interfaces are <i>not</i> inherited. |
||||
* |
||||
* <p>A @Transactional annotation on a class specifies the default transaction |
||||
* semantics for the execution of any <b>public</b> operation in the class. |
||||
* |
||||
* <p>A @Transactional annotation on a method within the class overrides the |
||||
* default transaction semantics given by the class annotation (if present). |
||||
* Any method may be annotated (regardless of visibility). |
||||
* Annotating non-public methods directly is the only way |
||||
* to get transaction demarcation for the execution of such operations. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Ramnivas Laddad |
||||
* @author Adrian Colyer |
||||
* @since 2.0 |
||||
* @see org.springframework.transaction.annotation.Transactional |
||||
*/ |
||||
public aspect AnnotationTransactionAspect extends AbstractTransactionAspect { |
||||
|
||||
public AnnotationTransactionAspect() { |
||||
super(new AnnotationTransactionAttributeSource(false)); |
||||
} |
||||
|
||||
/** |
||||
* Matches the execution of any public method in a type with the |
||||
* Transactional annotation, or any subtype of a type with the |
||||
* Transactional annotation. |
||||
*/ |
||||
private pointcut executionOfAnyPublicMethodInAtTransactionalType() : |
||||
execution(public * ((@Transactional *)+).*(..)) && @this(Transactional); |
||||
|
||||
/** |
||||
* Matches the execution of any method with the |
||||
* Transactional annotation. |
||||
*/ |
||||
private pointcut executionOfTransactionalMethod() : |
||||
execution(* *(..)) && @annotation(Transactional); |
||||
|
||||
/** |
||||
* Definition of pointcut from super aspect - matched join points |
||||
* will have Spring transaction management applied. |
||||
*/ |
||||
protected pointcut transactionalMethodExecution(Object txObject) : |
||||
(executionOfAnyPublicMethodInAtTransactionalType() |
||||
|| executionOfTransactionalMethod() ) |
||||
&& this(txObject); |
||||
|
||||
} |
||||
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
<html> |
||||
<body> |
||||
<p> |
||||
The Spring Data Binding framework, an internal library used by Spring Web Flow. |
||||
</p> |
||||
</body> |
||||
</html> |
||||
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?> |
||||
|
||||
<!-- |
||||
AspectJ load-time weaving config file to install common Spring aspects. |
||||
--> |
||||
<aspectj> |
||||
|
||||
<!-- |
||||
<weaver options="-showWeaveInfo"/> |
||||
--> |
||||
|
||||
<aspects> |
||||
<aspect name="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/> |
||||
<aspect name="org.springframework.transaction.aspectj.AnnotationTransactionAspect"/> |
||||
</aspects> |
||||
|
||||
</aspectj> |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
||||
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
||||
|
||||
<!-- Appenders --> |
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender"> |
||||
<param name="Target" value="System.out" /> |
||||
<layout class="org.apache.log4j.PatternLayout"> |
||||
<param name="ConversionPattern" value="%-5p: %c - %m%n" /> |
||||
</layout> |
||||
</appender> |
||||
|
||||
<logger name="org.springframework.beans"> |
||||
<level value="warn" /> |
||||
</logger> |
||||
|
||||
<logger name="org.springframework.binding"> |
||||
<level value="debug" /> |
||||
</logger> |
||||
|
||||
<!-- Root Logger --> |
||||
<root> |
||||
<priority value="warn" /> |
||||
<appender-ref ref="console" /> |
||||
</root> |
||||
|
||||
</log4j:configuration> |
||||
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
Bundle-SymbolicName: org.springframework.aspects |
||||
Bundle-Name: Spring Aspects |
||||
Bundle-Vendor: SpringSource |
||||
Bundle-ManifestVersion: 2 |
||||
Import-Template: |
||||
org.apache.commons.logging.*;version="[1.1.1, 2.0.0)", |
||||
org.aspectj.*;version="[1.5.4, 2.0.0)";resolution:=optional, |
||||
org.springframework.beans.*;version="[3.0.0, 3.0.1)", |
||||
org.springframework.transaction.*;version="[3.0.0, 3.0.1)";resolution:=optional |
||||
Ignored-Existing-Headers: |
||||
Bnd-LastModified, |
||||
Import-Package, |
||||
Export-Package, |
||||
Tool |
||||
Loading…
Reference in new issue